package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.orient.core.db.ODatabaseType;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import org.junit.*;
import org.junit.rules.TestName;

/**
 * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com)
 */
public class OMoveVertexStatementExecutionTest {
  @Rule
  public TestName name = new TestName();

  private ODatabaseDocument db;

  private String   className;
  private OrientDB orientDB;

  @Before
  public void before() {
    orientDB = new OrientDB("embedded:./target/databases", OrientDBConfig.defaultConfig());
    orientDB.create(name.getMethodName(), ODatabaseType.MEMORY);
    db = orientDB.open(name.getMethodName(), "admin", "admin");
  }

  @After
  public void after() {
    db.close();
    orientDB.close();
  }

  @Test
  public void testMoveVertex() {
    String vertexClassName1 = "testMoveVertexV1";
    String vertexClassName2 = "testMoveVertexV2";
    String edgeClassName = "testMoveVertexE";
    db.createVertexClass(vertexClassName1);
    db.createVertexClass(vertexClassName2);
    db.createEdgeClass(edgeClassName);

    db.command("create vertex " + vertexClassName1 + " set name = 'a'");
    db.command("create vertex " + vertexClassName1 + " set name = 'b'");
    db.command("create edge " + edgeClassName + " from (select from " + vertexClassName1 + " where name = 'a' ) to (select from "
        + vertexClassName1 + " where name = 'b' )");

    db.command("MOVE VERTEX (select from " + vertexClassName1 + " where name = 'a') to class:" + vertexClassName2);
    OResultSet rs = db.query("select from " + vertexClassName1);
    Assert.assertTrue(rs.hasNext());
    rs.next();
    Assert.assertFalse(rs.hasNext());
    rs.close();

    rs = db.query("select from " + vertexClassName2);
    Assert.assertTrue(rs.hasNext());
    rs.next();
    Assert.assertFalse(rs.hasNext());
    rs.close();


    rs = db.query("select expand(out()) from " + vertexClassName2);
    Assert.assertTrue(rs.hasNext());
    rs.next();
    Assert.assertFalse(rs.hasNext());
    rs.close();

    rs = db.query("select expand(in()) from " + vertexClassName1);
    Assert.assertTrue(rs.hasNext());
    rs.next();
    Assert.assertFalse(rs.hasNext());
    rs.close();

  }

}

@@ -2397,10 +2397,1496 @@
 ;%0A%0A  %7D%0A%0A
+  @Test%0A  public void testMoveVertexBatch() %7B%0A    String vertexClassName1 = %22testMoveVertexBatchV1%22;%0A    String vertexClassName2 = %22testMoveVertexBatchV2%22;%0A    String edgeClassName = %22testMoveVertexBatchE%22;%0A    db.createVertexClass(vertexClassName1);%0A    db.createVertexClass(vertexClassName2);%0A    db.createEdgeClass(edgeClassName);%0A%0A    db.command(%22create vertex %22 + vertexClassName1 + %22 set name = 'a'%22);%0A    db.command(%22create vertex %22 + vertexClassName1 + %22 set name = 'b'%22);%0A    db.command(%22create edge %22 + edgeClassName + %22 from (select from %22 + vertexClassName1 + %22 where name = 'a' ) to (select from %22%0A            + vertexClassName1 + %22 where name = 'b' )%22);%0A%0A    db.command(%22MOVE VERTEX (select from %22 + vertexClassName1 + %22 where name = 'a') to class:%22 + vertexClassName2 + %22 BATCH 2%22);%0A    OResultSet rs = db.query(%22select from %22 + vertexClassName1);%0A    Assert.assertTrue(rs.hasNext());%0A    rs.next();%0A    Assert.assertFalse(rs.hasNext());%0A    rs.close();%0A%0A    rs = db.query(%22select from %22 + vertexClassName2);%0A    Assert.assertTrue(rs.hasNext());%0A    rs.next();%0A    Assert.assertFalse(rs.hasNext());%0A    rs.close();%0A%0A%0A    rs = db.query(%22select expand(out()) from %22 + vertexClassName2);%0A    Assert.assertTrue(rs.hasNext());%0A    rs.next();%0A    Assert.assertFalse(rs.hasNext());%0A    rs.close();%0A%0A    rs = db.query(%22select expand(in()) from %22 + vertexClassName1);%0A    Assert.assertTrue(rs.hasNext());%0A    rs.next();%0A    Assert.assertFalse(rs.hasNext());%0A    rs.close();%0A%0A  %7D%0A%0A
 %7D%0A

Add test case for MOVE VERTEX BATCH