@Test @FixFor("DBZ-1021") public void shouldIgnoreEventsForDeletedTable() throws Exception { TestHelper.execute(SETUP_TABLES_STMT); Configuration.Builder configBuilder = TestHelper.defaultConfig() .with(PostgresConnectorConfig.SNAPSHOT_MODE, INITIAL.getValue()) .with(PostgresConnectorConfig.DROP_SLOT_ON_STOP, Boolean.FALSE); start(PostgresConnector.class, configBuilder.build()); assertConnectorIsRunning(); //check the records from the snapshot assertRecordsFromSnapshot(2, 1, 1); // insert 2 new records TestHelper.execute(INSERT_STMT); assertRecordsAfterInsert(2, 2, 2); //now stop the connector stopConnector(); assertNoRecordsToConsume(); //insert some more records and deleted the table TestHelper.execute(INSERT_STMT); TestHelper.execute("DROP TABLE s1.a"); start(PostgresConnector.class, configBuilder.with(PostgresConnectorConfig.DROP_SLOT_ON_STOP, Boolean.TRUE).build()); assertConnectorIsRunning(); SourceRecords actualRecords = consumeRecordsByTopic(1); assertThat(actualRecords.topics()).hasSize(1); assertThat(actualRecords.recordsForTopic(topicName("s2.a"))).hasSize(1); }
@Test public void testExecute() throws MojoExecutionException, MojoFailureException, ClassNotFoundException, IOException { mojo.execute(); File outputSer = new File(project.getBuild().getDirectory() + "/querytranslator/output.ser"); assertThat(outputSer).isNotNull().exists(); Serializer s = new Serializer(project); ResultVO r = s.deserialize(); assertThat(r).isNotNull(); Collection<PackageVO> packages = r.getPackages(); assertThat(packages).isNotNull().isNotEmpty().hasSize(3); Collection<EntityVO> entities = r.getPackages().iterator().next().getEntities(); assertThat(entities).isNotNull().isNotEmpty().hasSize(TestInfo.numberOfEntities - TestInfo.numberOfEntitiesInGenericPackage - TestInfo.numberOfEntitiesInSubPackage); Collection<QueryVO> queries = entities.iterator().next().getQueries(); assertThat(queries).isNotNull().isNotEmpty().hasSize(4); QueryVO query = queries.iterator().next(); assertThat(query).isNotNull(); assertThat(query.getSQLQuery()).isNotNull().isNotEmpty(); }
@Test public void collectionsUtilityMethods() { assertThat(setA).isNotEmpty().hasSize(2).doesNotHaveDuplicates(); assertThat(setA).containsOnly(s1, s2); }
@Test public void shouldRegisterPayback() { when(accountRepository.findByCreditCard(creditCardNumber)).thenReturn(account); when(merchantRepository.findByNumber(merchantNumber)).thenReturn(merchant); doAnswer(new Answer<PaybackConfirmation>() { @Override public PaybackConfirmation answer(InvocationOnMock invocation) throws Throwable { return new PaybackConfirmation("1111", (AccountIncome) invocation.getArguments()[0]); } }).when(paybackRepository).save(any(AccountIncome.class), same(purchase)); PaybackConfirmation confirmation = null; // replace with actual call to bookKeeper.registerPaybackFor(..) assertThat(confirmation.getNumber()).isEqualTo("1111"); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); }
@Test public void shouldRegisterPayback() { when(accountRepository.findByCreditCard(creditCardNumber)).thenReturn(account); when(merchantRepository.findByNumber(merchantNumber)).thenReturn(merchant); doAnswer(new Answer<PaybackConfirmation>() { @Override public PaybackConfirmation answer(InvocationOnMock invocation) throws Throwable { return new PaybackConfirmation("1111", (AccountIncome) invocation.getArguments()[0]); } }).when(paybackRepository).save(any(AccountIncome.class), same(purchase)); PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isEqualTo("1111"); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void testWithParamHSQL() throws Exception { setupHSQL(); final QueryVO q = new QueryVO("name", "select ent from TableA ent where ent.id = :id"); JPATransformer.transform(q); assertThat(q.getError()).isNull(); assertThat(q.getSQLQuery()).isNotNull().isNotEmpty().hasSize(1); assertThat(CoreFactory.getQueries()).isNotEmpty().hasSize(1); assertThat(q.getSQLQuery().iterator().next()).isEqualToIgnoringCase("SELECT t0.ID, t0.AGE, t0.COMMENT, t0.FAV, t0.NAME, t0.SURNAME FROM TABLE_A t0 where (t0.ID = ?)"); }
@Test public void testSimpleSelectDerby() throws Exception { setupDerby(); final QueryVO q = new QueryVO("name", "select ent from TableA ent"); JPATransformer.transform(q); assertThat(q.getError()).isNull(); assertThat(q.getSQLQuery()).isNotNull().isNotEmpty().hasSize(1); assertThat(CoreFactory.getQueries()).isNotEmpty().hasSize(1); assertThat(q.getSQLQuery().iterator().next()).isEqualToIgnoringCase("SELECT t0.ID, t0.AGE, t0.COMMENT, t0.FAV, t0.NAME, t0.SURNAME FROM TABLE_A t0"); }
@Test public void testWithParamDerby() throws Exception { setupDerby(); final QueryVO q = new QueryVO("name", "select ent from TableA ent where ent.id = :id"); JPATransformer.transform(q); assertThat(q.getError()).isNull(); assertThat(q.getSQLQuery()).isNotNull().isNotEmpty().hasSize(1); assertThat(CoreFactory.getQueries()).isNotEmpty().hasSize(1); assertThat(q.getSQLQuery().iterator().next()).isEqualToIgnoringCase("SELECT t0.ID, t0.AGE, t0.COMMENT, t0.FAV, t0.NAME, t0.SURNAME FROM TABLE_A t0 where (t0.ID = ?)"); }
@Test public void testSimpleSelectHSQL() throws Exception { setupHSQL(); final QueryVO q = new QueryVO("name", "select ent from TableA ent"); JPATransformer.transform(q); assertThat(q.getError()).isNull(); assertThat(q.getSQLQuery()).isNotNull().isNotEmpty().hasSize(1); assertThat(CoreFactory.getQueries()).isNotEmpty().hasSize(1); assertThat(q.getSQLQuery().iterator().next()).isEqualToIgnoringCase("SELECT t0.ID, t0.AGE, t0.COMMENT, t0.FAV, t0.NAME, t0.SURNAME FROM TABLE_A t0"); }
@Test public void testSimpleSelectH2() throws Exception { setupH2(); if (VersionSupport.isNotSupported(CoreFactory.getProperties())) { return; } final QueryVO q = new QueryVO("name", "select ent from TableA ent"); JPATransformer.transform(q); assertThat(q.getError()).isNull(); assertThat(q.getSQLQuery()).isNotNull().isNotEmpty().hasSize(1); assertThat(CoreFactory.getQueries()).isNotEmpty().hasSize(1); assertThat(q.getSQLQuery().iterator().next()).isEqualToIgnoringCase("SELECT t0.ID, t0.AGE, t0.COMMENT, t0.FAV, t0.NAME, t0.SURNAME FROM TABLE_A t0"); }
@Test public void testWithParamH2() throws Exception { setupH2(); if (VersionSupport.isNotSupported(CoreFactory.getProperties())) { return; } final QueryVO q = new QueryVO("name", "select ent from TableA ent where ent.id = :id"); JPATransformer.transform(q); assertThat(q.getError()).isNull(); assertThat(q.getSQLQuery()).isNotNull().isNotEmpty().hasSize(1); assertThat(CoreFactory.getQueries()).isNotEmpty().hasSize(1); assertThat(q.getSQLQuery().iterator().next()).isEqualToIgnoringCase("SELECT t0.ID, t0.AGE, t0.COMMENT, t0.FAV, t0.NAME, t0.SURNAME FROM TABLE_A t0 where (t0.ID = ?)"); }
@Test public void getStorageEmpty() throws Exception { db.dropDatabase(); // TODO: create a new DB here instead of dropping the old one assertThat(db.getCollectionNames()).hasSize(0); ResourceState result = client.read(new RequestContext.Builder().build(), "/testApp/" + BASEPATH); // verify response assertThat(result).isNotNull(); assertThat(result.id()).isEqualTo(BASEPATH); assertThat(result.getPropertyNames().size()).isEqualTo(2); assertThat(result.getProperty("type")).isEqualTo("database"); assertThat(result.getProperty("count")).isEqualTo(0); assertThat(result.members()).isEmpty(); }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void createEmptyCollection() throws Exception { // DB db = mongoClient.getDB("testGetStorageEmpty"); db.dropDatabase(); // TODO: create a new DB here instead of dropping the old one ? assertThat(db.getCollectionNames()).hasSize(0); ResourceState state = new DefaultResourceState("testCollection"); ResourceState response = client.create(new RequestContext.Builder().build(), "/testApp/" + BASEPATH, state); // verify response assertThat(response).isNotNull(); assertThat(response.id()).isEqualTo("testCollection"); assertThat(response.getProperty("type")).isEqualTo("collection"); assertThat(response.members()).isEmpty(); // verify whats in mongodb assertThat(db.collectionExists("testCollection")).isTrue(); assertThat(db.getCollection("testCollection").count()).isEqualTo(0); }
@Test public void createCollectionNoId() throws Exception { // DB db = mongoClient.getDB("testGetStorageEmpty"); db.dropDatabase(); // TODO: create a new DB here instead of dropping the old one ? assertThat(db.getCollectionNames()).hasSize(0); ResourceState response = client.create(new RequestContext.Builder().build(), "/testApp/" + BASEPATH, new DefaultResourceState()); // verfiy response assertThat(response).isNotNull(); assertThat(response.id()).isNotNull(); assertThat(response.getProperty("type")).isEqualTo("collection"); assertThat(response.members()).isEmpty(); String id = response.id(); // verify whats in mongodb assertThat(db.collectionExists(id)).isTrue(); assertThat(db.getCollection(id).count()).isEqualTo(0); }