package io.bootique.jdbc.test;

import io.bootique.BQRuntime;
import io.bootique.test.junit.BQTestFactory;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TestDataManagerIT {

    @ClassRule
    public static BQTestFactory TEST_FACTORY = new BQTestFactory();
    private static Table T1;
    private static Table T2;

    @Rule
    public TestDataManager dataManager = new TestDataManager(true, T1, T2);

    @BeforeClass
    public static void setupDB() {
        BQRuntime testRuntime = TEST_FACTORY
                .app("--config=classpath:io/bootique/jdbc/test/TestDataManagerIT.yml")
                .autoLoadModules()
                .createRuntime();

        DatabaseChannel channel = DatabaseChannel.get(testRuntime);

        channel.execStatement().exec("CREATE TABLE \"t1\" (\"id\" INT NOT NULL PRIMARY KEY, \"name\" VARCHAR(10))");
        channel.execStatement().exec("CREATE TABLE \"t2\" (\"id\" INT NOT NULL PRIMARY KEY, \"name\" VARCHAR(10), \"t1_id\" INT)");

        T1 = channel.newTable("t1").columnNames("id", "name").build();
        T2 = channel.newTable("t2").columnNames("id", "name", "t1_id").build();
    }

    @Test
    public void test1() {

        assertEquals(0, T1.getRowCount());
        assertEquals(0, T2.getRowCount());

        T1.insert(1, "x");
        T2.insert(1, "x1", 1);

        assertEquals(1, T1.getRowCount());
        assertEquals(1, T2.getRowCount());
    }

    @Test
    public void test2() {

        assertEquals(0, T1.getRowCount());
        assertEquals(0, T2.getRowCount());

        T1.insert(2, "x");
        T2.insert(2, "x2", 2);

        assertEquals(1, T1.getRowCount());
        assertEquals(1, T2.getRowCount());
    }

}

@@ -1294,84 +1294,78 @@
     
-assertEquals(0, T1.getRowCount());%0A        assertEquals(0, T2.getRowCount
+T1.matcher().assertNoMatches();%0A        T2.matcher().assertNoMatches
 ()
-)
 ;%0A%0A 
@@ -1434,214 +1434,200 @@
     
-assertEquals(1, T1.getRowCount());%0A        assertEquals(1, T2.getRowCount());%0A    %7D%0A%0A    @Test%0A    public void test2() %7B%0A%0A        assertEquals(0, T1.getRowCount());%0A        assertEquals(0, T2.getRowCount
+T1.matcher().assertOneMatch();%0A        T2.matcher().assertOneMatch();%0A    %7D%0A%0A    @Test%0A    public void test2() %7B%0A%0A        T1.matcher().assertNoMatches();%0A        T2.matcher().assertNoMatches
 ()
-)
 ;%0A%0A 
@@ -1696,83 +1696,75 @@
     
-assertEquals(1, T1.getRowCount());%0A        assertEquals(1, T2.getRowCount()
+T1.matcher().assertOneMatch();%0A        T2.matcher().assertOneMatch(
 );%0A 

Test API: matcher API, support for key/value matching #46