package ru.cjdb.sql;

import dagger.Module;
import dagger.ObjectGraph;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import ru.cjdb.CjDbModule;
import ru.cjdb.scheme.types.Types;
import ru.cjdb.sql.queries.ddl.CreateTableQuery;
import ru.cjdb.sql.queries.dml.InsertQuery;
import ru.cjdb.sql.queries.dml.SelectQuery;
import ru.cjdb.sql.result.QueryResult;
import ru.cjdb.testutils.TestUtils;

import javax.inject.Inject;

import static java.util.Arrays.asList;
import static ru.cjdb.sql.queries.ddl.CreateTableQuery.RowDefinition;

public class QueryExecutorImplTest {

    @Inject
    QueryExecutor queryExecutor;

    @Before
    public void setup() {
        ObjectGraph.create(new QueryExecutorImplTestModule ()).inject(this);
    }

    @Test
    public void testCreateThenInsertThenSelect() {
        CreateTableQuery createTableQuery = new CreateTableQuery(TestUtils.createRandomName(),
                asList(new RowDefinition("test", Types.INT)));
        queryExecutor.execute(createTableQuery);

        InsertQuery insertQuery = new InsertQuery("Test", 2);
        queryExecutor.execute(insertQuery);

        SelectQuery selectQuery = new SelectQuery("Test", asList("test"));
        QueryResult queryResult = queryExecutor.execute(selectQuery);

        Assert.assertTrue(queryResult.isSuccessful());
        Assert.assertTrue(queryResult.hasResult());

        Assert.assertEquals(queryResult.getResult().getRow(0).getAt(0), 2);
    }

    @Module(injects = QueryExecutorImplTest.class, includes = CjDbModule.class)
    public static final class QueryExecutorImplTestModule {
    }
}
@@ -814,24 +814,81 @@
 nSelect() %7B%0A
+        String tableName = TestUtils.createRandomName();%0A
         Crea
@@ -944,36 +944,17 @@
 ery(
-TestUtils.createRandom
+table
 Name
-()
 ,%0A  
@@ -1114,22 +1114,25 @@
 rtQuery(
-%22Test%22
+tableName
 , 2);%0A  
@@ -1228,14 +1228,17 @@
 ery(
-%22Test%22
+tableName
 , as

Fix test