/** * This method test when there is a deletion change. * * @throws SQLException */ @Test @NeedReload public void test_when_there_is_deletion_change() throws SQLException { Changes changes = new Changes(new Request(dataSource, "select * from test2")); changes.setStartPointNow(); update("delete from test2 where VAR1 is null"); changes.setEndPointNow(); assertThat(changes.getChangesList()).hasSize(1); Change change = changes.getChangesList().get(0); assertThat(change.getDataName()).isEqualTo("select * from test2"); assertThat(change.getChangeType()).isEqualTo(ChangeType.DELETION); assertThat(change.getColumnsNameList()) .containsExactly( "VAR1", "VAR2", "VAR3", "VAR4", "VAR5", "VAR6", "VAR7", "VAR8", "VAR9", "VAR10", "VAR11", "VAR12", "VAR13", "VAR14", "VAR15", "VAR16"); assertThat(change.getRowAtStartPoint().getValuesList().get(0).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(1).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(2).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(3).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(4).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(5).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(6).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(7).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(8).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(9).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(10).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(11).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(12).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(13).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(14).getValue()).isNull(); assertThat(change.getRowAtStartPoint().getValuesList().get(15).getValue()).isNull(); assertThat(change.getRowAtEndPoint()).isNull(); }
/** This method test when there is not change. */ @Test public void test_when_there_is_no_change() { Changes changes = new Changes(new Request(dataSource, "select * from test")); changes.setStartPointNow(); changes.setEndPointNow(); assertThat(changes.getChangesList()).hasSize(0); }
/** * This method test when there is a deletion change with primary key. * * @throws SQLException */ @Test @NeedReload public void test_when_there_is_deletion_change_with_primary_key() throws SQLException { Changes changes = new Changes(new Request(dataSource, "select * from interpretation").setPksName("id")); changes.setStartPointNow(); update("delete interpretation where id = 3"); changes.setEndPointNow(); assertThat(changes.getChangesList()).hasSize(1); Change change = changes.getChangesList().get(0); assertThat(change.getDataName()).isEqualTo("select * from interpretation"); assertThat(change.getChangeType()).isEqualTo(ChangeType.DELETION); assertThat(change.getColumnsNameList()) .containsExactly("ID", "ID_MOVIE", "ID_ACTOR", "CHARACTER"); assertThat(change.getRowAtStartPoint().getValuesList().get(0).getValue()) .isEqualTo(new BigDecimal(3)); assertThat(change.getRowAtStartPoint().getValuesList().get(1).getValue()) .isEqualTo(new BigDecimal(3)); assertThat(change.getRowAtStartPoint().getValuesList().get(2).getValue()) .isEqualTo(new BigDecimal(1)); assertThat(change.getRowAtStartPoint().getValuesList().get(3).getValue()) .isEqualTo("Dr Grace Augustine"); assertThat(change.getRowAtEndPoint()).isNull(); }
/** * This method test when there is a creation change with primary key. * * @throws SQLException */ @Test @NeedReload public void test_when_there_is_creation_change_with_primary_key() throws SQLException { Changes changes = new Changes(new Request(dataSource, "select * from movie").setPksName("id")); changes.setStartPointNow(); update( "insert into movie values(4, 'Ghostbusters', 1984, '16319617-AE95-4087-9264-D3D21BF611B6')"); changes.setEndPointNow(); assertThat(changes.getChangesList()).hasSize(1); Change change = changes.getChangesList().get(0); assertThat(change.getDataName()).isEqualTo("select * from movie"); assertThat(change.getChangeType()).isEqualTo(ChangeType.CREATION); assertThat(change.getColumnsNameList()).containsExactly("ID", "TITLE", "YEAR", "MOVIE_IMDB"); assertThat(change.getRowAtStartPoint()).isNull(); assertThat(change.getRowAtEndPoint().getValuesList().get(0).getValue()) .isEqualTo(new BigDecimal(4)); assertThat(change.getRowAtEndPoint().getValuesList().get(1).getValue()) .isEqualTo("Ghostbusters"); assertThat(change.getRowAtEndPoint().getValuesList().get(2).getValue()) .isEqualTo(new BigDecimal(1984)); assertThat(change.getRowAtEndPoint().getValuesList().get(3).getValue()) .isEqualTo(UUID.fromString("16319617-AE95-4087-9264-D3D21BF611B6")); }
/** * This method test when there is no change found because it is another table. * * @throws SQLException */ @Test @NeedReload public void test_when_there_is_no_change_found() throws SQLException { Changes changes = new Changes(new Request(dataSource, "select * from test")); changes.setStartPointNow(); update("delete from test2 where VAR1 is null"); changes.setEndPointNow(); assertThat(changes.getChangesList()).hasSize(0); }
/** This method should fail because the value is no close to. */ @Test @NeedReload public void should_fail_because_value_is_not_close_to() { Table table = new Table(source, "test"); Changes changes = new Changes(table).setStartPointNow(); update("update test set var14 = 1 where var1 = 1"); changes.setEndPointNow(); try { assertThat(changes) .change() .column("var10") .valueAtEndPoint() .isCloseTo( DateTimeValue.of(DateValue.of(2014, 5, 24), TimeValue.of(9, 46, 31)), TimeValue.of(0, 0, 0, 1)); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()) .isEqualTo( String.format( "[Value at end point of Column at index 9 (column name : VAR10) of Change at index 0 (with primary key : [1]) of Changes on TEST table of 'sa/jdbc:h2:mem:test' source] %n" + "Expecting:%n" + " <2014-05-24T09:46:30.000000000>%n" + "to be close to: %n" + " <2014-05-24T09:46:31.000000000> %n" + " with tolerance <00:00:00.000000001>")); } try { assertThat(table) .column("var10") .value() .isCloseTo( DateTimeValue.of(DateValue.of(2014, 5, 24), TimeValue.of(9, 46, 31)), TimeValue.of(0, 0, 0, 100)); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()) .isEqualTo( String.format( "[Value at index 0 of Column at index 9 (column name : VAR10) of TEST table] %n" + "Expecting:%n" + " <2014-05-24T09:46:30.000000000>%n" + "to be close to: %n" + " <2014-05-24T09:46:31.000000000> %n" + " with tolerance <00:00:00.000000100>")); } }
/** This method tests the {@code isCloseTo} assertion method. */ @Test @NeedReload public void test_is_close_to() { Table table = new Table(source, "test"); Changes changes = new Changes(table).setStartPointNow(); update("update test set var14 = 1 where var1 = 1"); changes.setEndPointNow(); ChangeColumnValueAssert changeColumnValueAssert = assertThat(changes).change().column("var10").valueAtEndPoint(); ChangeColumnValueAssert changeColumnValueAssert2 = changeColumnValueAssert.isCloseTo( DateTimeValue.of(DateValue.of(2014, 5, 24), TimeValue.of(9, 46, 30)), TimeValue.of(0, 0, 0)); Assertions.assertThat(changeColumnValueAssert).isSameAs(changeColumnValueAssert2); TableColumnValueAssert tableColumnValueAssert = assertThat(table).column("var10").value(); TableColumnValueAssert tableColumnValueAssert2 = tableColumnValueAssert.isCloseTo( DateTimeValue.of(DateValue.of(2014, 5, 24), TimeValue.of(9, 46, 30)), TimeValue.of(0, 0, 0)); Assertions.assertThat(tableColumnValueAssert).isSameAs(tableColumnValueAssert2); }
/** * This method test when there is a modification change without primary key. * * @throws SQLException */ @Test @NeedReload public void test_when_there_is_modification_change_without_primary_key() throws SQLException { Changes changes = new Changes(new Request(dataSource, "select * from test2")); changes.setStartPointNow(); update("update test2 set VAR12 = 'modification' where VAR1 = 1"); changes.setEndPointNow(); assertThat(changes.getChangesList()).hasSize(2); Change change = changes.getChangesList().get(0); assertThat(change.getDataName()).isEqualTo("select * from test2"); assertThat(change.getChangeType()).isEqualTo(ChangeType.CREATION); assertThat(change.getColumnsNameList()) .containsExactly( "VAR1", "VAR2", "VAR3", "VAR4", "VAR5", "VAR6", "VAR7", "VAR8", "VAR9", "VAR10", "VAR11", "VAR12", "VAR13", "VAR14", "VAR15", "VAR16"); assertThat(change.getRowAtStartPoint()).isNull(); assertThat(change.getRowAtEndPoint().getValuesList().get(0).getValue()).isEqualTo(1); assertThat(change.getRowAtEndPoint().getValuesList().get(1).getValue()).isEqualTo(true); assertThat(change.getRowAtEndPoint().getValuesList().get(2).getValue()).isEqualTo((byte) 2); assertThat(change.getRowAtEndPoint().getValuesList().get(3).getValue()).isEqualTo((short) 3); assertThat(change.getRowAtEndPoint().getValuesList().get(4).getValue()).isEqualTo(4L); assertThat(change.getRowAtEndPoint().getValuesList().get(5).getValue()) .isEqualTo(new BigDecimal("5.60")); assertThat(change.getRowAtEndPoint().getValuesList().get(6).getValue()).isEqualTo(7.8f); assertThat(change.getRowAtEndPoint().getValuesList().get(7).getValue()) .isEqualTo(Time.valueOf("09:46:30")); assertThat(change.getRowAtEndPoint().getValuesList().get(8).getValue()) .isEqualTo(Date.valueOf("2014-05-24")); assertThat(change.getRowAtEndPoint().getValuesList().get(9).getValue()) .isEqualTo(Timestamp.valueOf("2014-05-24 09:46:30")); assertThat(change.getRowAtEndPoint().getValuesList().get(10).getValue()) .isEqualTo(Assertions.bytesContentFromClassPathOf("h2-logo-2.png")); assertThat(change.getRowAtEndPoint().getValuesList().get(11).getValue()) .isEqualTo("modification"); assertThat(change.getRowAtEndPoint().getValuesList().get(12).getValue()) .isEqualTo(new BigDecimal("5.00")); assertThat(change.getRowAtEndPoint().getValuesList().get(13).getValue()).isEqualTo(7f); assertThat(change.getRowAtEndPoint().getValuesList().get(14).getValue()).isEqualTo(null); assertThat(change.getRowAtEndPoint().getValuesList().get(15).getValue()) .isEqualTo(UUID.fromString("30b443ae-c0c9-4790-9bec-ce1380808435")); Change change1 = changes.getChangesList().get(1); assertThat(change1.getDataName()).isEqualTo("select * from test2"); assertThat(change1.getChangeType()).isEqualTo(ChangeType.DELETION); assertThat(change1.getColumnsNameList()) .containsExactly( "VAR1", "VAR2", "VAR3", "VAR4", "VAR5", "VAR6", "VAR7", "VAR8", "VAR9", "VAR10", "VAR11", "VAR12", "VAR13", "VAR14", "VAR15", "VAR16"); assertThat(change1.getRowAtStartPoint().getValuesList().get(0).getValue()).isEqualTo(1); assertThat(change1.getRowAtStartPoint().getValuesList().get(1).getValue()).isEqualTo(true); assertThat(change1.getRowAtStartPoint().getValuesList().get(2).getValue()).isEqualTo((byte) 2); assertThat(change1.getRowAtStartPoint().getValuesList().get(3).getValue()).isEqualTo((short) 3); assertThat(change1.getRowAtStartPoint().getValuesList().get(4).getValue()).isEqualTo(4L); assertThat(change1.getRowAtStartPoint().getValuesList().get(5).getValue()) .isEqualTo(new BigDecimal("5.60")); assertThat(change1.getRowAtStartPoint().getValuesList().get(6).getValue()).isEqualTo(7.8f); assertThat(change1.getRowAtStartPoint().getValuesList().get(7).getValue()) .isEqualTo(Time.valueOf("09:46:30")); assertThat(change1.getRowAtStartPoint().getValuesList().get(8).getValue()) .isEqualTo(Date.valueOf("2014-05-24")); assertThat(change1.getRowAtStartPoint().getValuesList().get(9).getValue()) .isEqualTo(Timestamp.valueOf("2014-05-24 09:46:30")); assertThat(change1.getRowAtStartPoint().getValuesList().get(10).getValue()) .isEqualTo(Assertions.bytesContentFromClassPathOf("h2-logo-2.png")); assertThat(change1.getRowAtStartPoint().getValuesList().get(11).getValue()).isEqualTo("text"); assertThat(change1.getRowAtStartPoint().getValuesList().get(12).getValue()) .isEqualTo(new BigDecimal("5.00")); assertThat(change1.getRowAtStartPoint().getValuesList().get(13).getValue()).isEqualTo(7f); assertThat(change1.getRowAtStartPoint().getValuesList().get(14).getValue()).isEqualTo(null); assertThat(change1.getRowAtStartPoint().getValuesList().get(15).getValue()) .isEqualTo(UUID.fromString("30b443ae-c0c9-4790-9bec-ce1380808435")); assertThat(change1.getRowAtEndPoint()).isNull(); }