Package org.openengsb.core.edbi.api

Examples of org.openengsb.core.edbi.api.IndexCommit


    @Test
    public void execute_insert_createsRecordsCorrectly() throws Exception {
        engine.create(testIndex);

        IndexCommit commit = mock(IndexCommit.class);
        when(commit.getTimestamp()).thenReturn(new Date(42));
        // TODO: mock entire commit

        List models = new ArrayList<>();

        models.add(new TestModel("A", 42));
View Full Code Here


    @Test
    public void execute_update_updatesRecordsCorrectly() throws Exception {
        engine.create(testIndex);

        IndexCommit commit = mock(IndexCommit.class);
        when(commit.getTimestamp()).thenReturn(new Date(42));

        TestModel testModelA = new TestModel("A", 42);
        TestModel testModelB = new TestModel("B", -42);

        List<OpenEngSBModel> list = new ArrayList<>();

        list.add((OpenEngSBModel) testModelA);
        list.add((OpenEngSBModel) testModelB);

        engine.execute(new InsertOperation(commit, testIndex, list));

        testModelB.setTestInteger(43);

        IndexCommit updateCommit = mock(IndexCommit.class);
        when(updateCommit.getTimestamp()).thenReturn(new Date(84));
        engine.execute(new UpdateOperation(updateCommit, testIndex, new ArrayList(Arrays.asList(testModelB))));

        try (ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM HISTORY_TABLE")) {
            assertTrue(rs.next());
            assertEquals("A", rs.getString("TESTID"));
View Full Code Here

    @Test
    public void execute_delete_deletesRecordsCorrectly() throws Exception {
        engine.create(testIndex);

        IndexCommit commit = mock(IndexCommit.class);
        when(commit.getTimestamp()).thenReturn(new Date(42));

        TestModel testModelA = new TestModel("A", 42);
        TestModel testModelB = new TestModel("B", -42);

        engine.execute(new InsertOperation(commit, testIndex, new ArrayList(Arrays.asList(testModelA, testModelB))));

        IndexCommit deleteCommit = mock(IndexCommit.class);
        when(deleteCommit.getTimestamp()).thenReturn(new Date(84));

        engine.execute(new DeleteOperation(deleteCommit, testIndex, new ArrayList(Arrays.asList(testModelB))));

        try (ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM HISTORY_TABLE")) {
            assertTrue(rs.next());
View Full Code Here

        commit.addInsert(insert1).addInsert(insert2).addInsert(insert3);
        commit.addUpdate(update1).addUpdate(update2);
        commit.addDelete(delete1).addDelete(delete2);

        // test
        IndexCommit convertedCommit = converter.convert(commit);

        // assert
        assertEquals("testConnector", convertedCommit.getConnectorId());
        assertEquals("testDomain", convertedCommit.getDomainId());
        assertEquals("testInstance", convertedCommit.getInstanceId());
        assertEquals("550e8400-e29b-41d4-a716-446655440000", convertedCommit.getCommitId().toString());
        assertNotNull(convertedCommit.getTimestamp());

        assertEquals("testContext", convertedCommit.getContextId());
        assertEquals("testUser", convertedCommit.getUser());

        Map<Class<?>, List<OpenEngSBModel>> inserts = convertedCommit.getInserts();
        assertEquals(2, inserts.size());
        assertEquals(2, inserts.get(TestModelA.class).size());
        assertEquals(1, inserts.get(TestModelB.class).size());

        assertSame(insert1, inserts.get(TestModelA.class).get(0));
        assertSame(insert2, inserts.get(TestModelA.class).get(1));
        assertSame(insert3, inserts.get(TestModelB.class).get(0));

        Map<Class<?>, List<OpenEngSBModel>> updates = convertedCommit.getUpdates();
        assertEquals(1, updates.size());
        assertEquals(2, updates.get(TestModelA.class).size());

        assertSame(update1, updates.get(TestModelA.class).get(0));
        assertSame(update2, updates.get(TestModelA.class).get(1));

        Map<Class<?>, List<OpenEngSBModel>> deletes = convertedCommit.getDeletes();
        assertEquals(2, deletes.size());
        assertEquals(1, deletes.get(TestModelA.class).size());
        assertEquals(1, deletes.get(TestModelB.class).size());

        assertSame(delete1, deletes.get(TestModelA.class).get(0));
        assertSame(delete2, deletes.get(TestModelB.class).get(0));

        Set<Class<?>> modelClasses = convertedCommit.getModelClasses();
        assertEquals(2, modelClasses.size());

        assertTrue("Model classes do not contain TestModel_A", modelClasses.contains(TestModelA.class));
        assertTrue("Model classes do not contain TestModel_B", modelClasses.contains(TestModelB.class));
    }
View Full Code Here

    @Test
    public void execute_insert_createsRecordsCorrectly() throws Exception {
        engine.create(testIndex);

        IndexCommit commit = mock(IndexCommit.class);
        when(commit.getTimestamp()).thenReturn(new Date(42));
        // TODO: mock entire commit

        List models = new ArrayList<>();

        models.add(new TestModel("A", 42));
View Full Code Here

    @Test
    public void execute_update_updatesRecordsCorrectly() throws Exception {
        engine.create(testIndex);

        IndexCommit commit = mock(IndexCommit.class);
        when(commit.getTimestamp()).thenReturn(new Date(42));

        TestModel testModelA = new TestModel("A", 42);
        TestModel testModelB = new TestModel("B", -42);

        engine.execute(new InsertOperation(commit, testIndex, new ArrayList(Arrays.asList(testModelA, testModelB))));

        testModelB.setTestInteger(43);

        IndexCommit updateCommit = mock(IndexCommit.class);
        when(updateCommit.getTimestamp()).thenReturn(new Date(84));
        engine.execute(new UpdateOperation(updateCommit, testIndex,
            new ArrayList(Arrays.asList(testModelA, testModelB))));

        try (ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM HEAD_TABLE")) {
            assertTrue(rs.next());
View Full Code Here

    @Test
    public void execute_delete_deletesRecordsCorrectly() throws Exception {
        engine.create(testIndex);

        IndexCommit commit = mock(IndexCommit.class);
        when(commit.getTimestamp()).thenReturn(new Date(42));

        TestModel testModelA = new TestModel("A", 42);
        TestModel testModelB = new TestModel("B", -42);

        engine.execute(new InsertOperation(commit, testIndex, new ArrayList(Arrays.asList(testModelA, testModelB))));

        IndexCommit deleteCommit = mock(IndexCommit.class);
        when(deleteCommit.getTimestamp()).thenReturn(new Date(84));

        engine.execute(new DeleteOperation(deleteCommit, testIndex, new ArrayList(Arrays.asList(testModelB))));

        try (ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM HEAD_TABLE")) {
            assertTrue(rs.next());
View Full Code Here

    @Test
    public void commit_createsIndexInherently() throws Exception {
        assertFalse(engine.indexExists(TestModel.class));
        assertEquals(0, jdbc().queryForInt("SELECT COUNT(*) FROM INDEX_INFORMATION"));

        IndexCommit commit = newTestCommit()
            .insert(new TestModel("foo", 1))
            .get();

        engine.commit(commit);

View Full Code Here

    @Test
    public void commit_insertWithSubmodel_shouldProperlyInsertRecords() throws Exception {
        SubTestModel submodel = new SubTestModel(11);

        IndexCommit commit = newTestCommit()
            .insert(submodel)
            .insert(new TestModel("foo", 1, submodel))
            .insert(new TestModel("bar", 2))
            .get();

        engine.commit(commit);

        assertEquals(2,
            jdbc().queryForInt("SELECT COUNT(*) FROM " + engine.getIndex(TestModel.class).getHeadTableName()));
        assertEquals(2,
            jdbc().queryForInt("SELECT COUNT(*) FROM " + engine.getIndex(TestModel.class).getHistoryTableName()));

        Map<String, Object> record;

        // testmodel
        String sql = "SELECT * FROM " + engine.getIndex(TestModel.class).getHeadTableName() + " WHERE TESTID = 'foo'";
        record = jdbc().queryForMap(sql);
        assertEquals(11, record.get("SUBMODEL")); // foreign key should be the id of the model

        // extensive asserts for sub model tables
        JdbcIndex<SubTestModel> index = engine.getIndex(SubTestModel.class);

        assertEquals(1, jdbc().queryForInt("SELECT COUNT(*) FROM " + index.getHeadTableName()));
        assertEquals(1, jdbc().queryForInt("SELECT COUNT(*) FROM " + index.getHistoryTableName()));

        // submodel
        String column = index.getFields().get(0).getMappedName(); // SubTestModel only has one field

        record = jdbc().queryForMap("SELECT * FROM " + index.getHeadTableName());
        assertEquals(commit.getTimestamp(), record.get("REV_CREATED"));
        assertEquals(null, record.get("REV_MODIFIED"));
        assertEquals(11, record.get(column));

        record = jdbc().queryForMap("SELECT * FROM " + index.getHistoryTableName());
        assertEquals(11, record.get(column));
        // assert meta data
        assertEquals(commit.getTimestamp(), record.get("REV_TIMESTAMP"));
        assertEquals("INSERT", record.get("REV_OPERATION"));
        assertEquals("testUser", record.get("REV_USER"));
        assertEquals("testContext", record.get("REV_CONTEXTID"));
        assertEquals("testDomain", record.get("REV_DOMAINID"));
        assertEquals("testConnector", record.get("REV_CONNECTORID"));
View Full Code Here

    @Test
    public void commit_update_updatesTablesCorrectly() throws Exception {
        TestModel entity = new TestModel("foo", 1);

        // initial insert
        IndexCommit insertCommit = newTestCommit().insert(entity).get();
        engine.commit(insertCommit);

        // update
        entity.setTestInteger(42);
        IndexCommit updateCommit = newTestCommit().update(entity).get();
        engine.commit(updateCommit);

        // assert

        Index<TestModel> index = engine.getIndex(TestModel.class);
View Full Code Here

TOP

Related Classes of org.openengsb.core.edbi.api.IndexCommit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.