@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 @FixFor("DBZ-759") public void equalsAndHashCode() { Value binaryValue1 = Value.create(new byte[] { 1, 2, 3 }); Value binaryValue2 = Value.create(new byte[] { 1, 2, 3 }); Set<Value> set = Collections.singleton(binaryValue1); assertThat(set).contains(binaryValue2); } }
protected void assertRegexSet(String patterns, String... matches) { Set<Pattern> regexSet = Strings.setOfRegex(patterns); assertThat(regexSet.stream() .map(Pattern::pattern) .collect(Collectors.toSet())).containsOnly((Object[])matches); }
@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); }
Assertions.assertThat( components ).isNotNull().isNotEmpty().hasSize( 2 ); Assertions.assertThat( parameters ).isNotNull().isNotEmpty().hasSize( 2 ).contains( new ParameterAnnotationContent( "bar", null, "thebar", "coolbar", true, false, String.class.getName() ), new ParameterAnnotationContent( "beer", null, "thebeer", "coolbeer", false, false,
assertThat( user.getNicknames() ).as( "Should have 2 nick1" ).hasSize( 2 ); assertThat( user.getNicknames() ).as( "Should contain nicks" ).contains( "idrA", "day[9]" ); user.getNicknames().remove( "idrA" ); tx.commit(); assertThat( user.getAddresses().get( "home" ).getCity() ).as( "home address should be under home" ).isEqualTo( home.getCity() ); assertThat( user.getNicknames() ).as( "Should have 1 nick1" ).hasSize( 1 ); assertThat( user.getNicknames() ).as( "Should contain nick" ).contains( "day[9]" ); session.delete( user ); session.delete( session.load( Address.class, home.getId() ) ); assertThat( user2.getNicknames() ).as( "Should have 2 nicks" ).hasSize( 2 ); assertThat( user2.getNicknames() ).as( "Should contain nick" ).contains( "idrA", "day[9]" ); session.delete( user2 );
assertThat( soge.getOwners() ).hasSize( 1 ); assertThat( soge.getOwners() ).onProperty( "id" ).contains( owner.getId() ); tx.commit(); assertThat( owner.getBankAccounts() ).hasSize( 1 ); assertThat( owner.getBankAccounts() ).onProperty( "id" ).contains( soge.getId() ); BankAccount barclays = new BankAccount( "account_2" ); barclays.setAccountNumber( "ZZZ-009" ); assertThat( owner.getBankAccounts() ).hasSize( 1 ); assertThat( owner.getBankAccounts() ).onProperty( "id" ).contains( barclays.getId() ); barclays = owner.getBankAccounts().iterator().next(); barclays.getOwners().clear();
@Test public void testManyToManyCompositeId() throws Exception { Session session = openSession(); Transaction transaction = session.beginTransaction(); Car car = new Car(); car.setCarId( new Car.CarId( "Citroen", "AX" ) ); car.setHp( 20 ); session.persist( car ); Tire tire = new Tire(); tire.setTireId( new Tire.TireId( "Michelin", "B1" ) ); tire.setSize( 17d ); car.getTires().add( tire ); tire.getCars().add( car ); session.persist( tire ); transaction.commit(); session.clear(); transaction = session.beginTransaction(); car = (Car) session.get( Car.class, car.getCarId() ); assertThat( car.getTires() ).hasSize( 1 ); assertThat( car.getTires().iterator().next().getCars() ).contains( car ); session.delete( car ); session.delete( car.getTires().iterator().next() ); transaction.commit(); session.close(); }
assertThat( hoegaarden.getBrewery() ).isNotNull(); assertThat( hoegaarden.getBrewery().getBeers() ) .hasSize( 1 ) .containsOnly( hoegaarden ); Beer citron = new Beer(); hoeBrewery = hoegaarden.getBrewery(); citron = get( session, Beer.class, citron.getId() ); assertThat( citron.getBrewery().getBeers() ) .hasSize( 1 ) .containsOnly( citron ); hoeBrewery = citron.getBrewery(); citron.setBrewery( null );
@Test public void lookingIntoProperties() { Collection<Book> books = new HashSet<Book>(); books.add(new Book("Homer", "Odyssey")); books.add(new Book("J.R.R. Tolkien", "Hobbit")); assertThat(books).onProperty("title").contains("Hobbit"); assertThat(books).onProperty("author").contains("J.R.R. Tolkien"); assertThat(books).onProperty("author").contains("J.K. Rownling"); } }
@Test public void testLegacyIdCorrectlyAnnotated() { ThriftStructMetadataBuilder builder = new ThriftStructMetadataBuilder(new ThriftCatalog(), LegacyIdCorrect.class); ThriftStructMetadata metadata = builder.build(); Set<Integer> seen = new HashSet<>(); for (ThriftFieldMetadata field : metadata.getFields()) { seen.add((int) field.getId()); } assertThat(seen) .as("fields found in LegacyIdCorrect") .isEqualTo(LegacyIdCorrect.IDS); }
assertThat( loadedEmployer.getEmployees() ).onProperty( "name" ).containsOnly( "DNadar" );
@Test public void testCase() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException { setupH2(); if (VersionSupport.isNotSupported(CoreFactory.getProperties())) { return; } JPATransformer.transformAllQueries(packages); assertThat(packages.iterator().next().getEntities().get(0).getQueries().iterator().next().getSQLQuery()).isNotNull().isNotEmpty(); }
protected void assertHistoryRecorded() { MySqlSchema duplicate = build.storeDatabaseHistoryInFile(TEST_FILE_PATH).createSchemas(); duplicate.loadHistory(source); // Make sure table is defined in each ... assertThat(duplicate.tableIds()).isEqualTo(mysql.tableIds()); for (int i = 0; i != 2; ++i) { duplicate.tableIds().forEach(tableId -> { TableSchema dupSchema = duplicate.schemaFor(tableId); TableSchema schema = mysql.schemaFor(tableId); assertThat(schema).isEqualTo(dupSchema); Table dupTable = duplicate.tableFor(tableId); Table table = mysql.tableFor(tableId); assertThat(table).isEqualTo(dupTable); }); mysql.tableIds().forEach(tableId -> { TableSchema dupSchema = duplicate.schemaFor(tableId); TableSchema schema = mysql.schemaFor(tableId); assertThat(schema).isEqualTo(dupSchema); Table dupTable = duplicate.tableFor(tableId); Table table = mysql.tableFor(tableId); assertThat(table).isEqualTo(dupTable); }); duplicate.refreshSchemas(); } }
assertThat( blog.getEntries() ).isNotNull(); if ( blog.getEntries().size() < ( nbrOfBlogEntries / nbrOfAuthors ) / 10 ) { System.out.printf( "Small number of entries in this collection %s\n", blog.getEntries().size() );
@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 testLegacyIdOnUnion() { ThriftUnionMetadataBuilder builder = new ThriftUnionMetadataBuilder(new ThriftCatalog(), LegacyIdUnionCorrect.class); ThriftStructMetadata metadata = builder.build(); Set<Integer> seen = new HashSet<>(); for (ThriftFieldMetadata field : metadata.getFields()) { seen.add((int) field.getId()); } assertThat(seen) .as("fields found in LegacyIdUnionCorrect") .isEqualTo(LegacyIdUnionCorrect.IDS); }
@Test public void testGetStorageCollectionsQuery() throws Exception { DBCollection collection = db.getCollection("testQueryCollection"); if (collection != null) { collection.drop(); } collection = db.createCollection("testQueryCollection", new BasicDBObject("count", 0)); // insert data records for the test setupPeopleData(collection); assertThat(collection.count()).isEqualTo(6); // This should return 3 items // SimpleResourceParams resourceParams = new SimpleResourceParams(); resourceParams.put("q", "[{$group:{_id:{country:'$country'},numPeople:{$sum:1}}}]"); RequestContext requestContext = new RequestContext.Builder() .returnFields(new DefaultReturnFields("*(*)")) .resourceParams(resourceParams) .build(); ResourceState result = client.read(requestContext, "/testApp/" + BASEPATH + "/testQueryCollection/_aggregate"); // verify response assertThat(result).isNotNull(); assertThat(result.id()).isEqualTo("_aggregate"); assertThat(result.getProperty("result")).isNotNull(); assertThat(result.getProperty("result")).isInstanceOf(List.class); List results = (List) result.getProperty("result"); assertThat(results.size()).isEqualTo(3); Set countries = checkAggregateItems(results); Set expected = new HashSet(Arrays.asList(new String[] { "DE", "FR", "US" })); assertThat(countries).isEqualTo(expected); }
@Test public void renameCollectionAlreadyExists() throws Exception { db.dropDatabase(); // TODO: create a new DB here instead of dropping the old one assertThat(db.getCollectionNames()).hasSize(0); // create a couple of collections db.createCollection("foo", new BasicDBObject()); db.createCollection("bar", new BasicDBObject()); // check that the collections are there (Note: there is an internal index collection, so one more than expected) assertThat(db.getCollectionNames()).hasSize(3); assertThat(db.collectionExists("foo")); assertThat(db.collectionExists("bar")); // set the update resource state to include a new id value // Note that this matches an already existing collection ResourceState updateResourceState = new DefaultResourceState("bar"); try { client.update(new RequestContext.Builder().build(), "/testApp/" + BASEPATH + "/foo", updateResourceState); Fail.fail(); } catch (ResourceAlreadyExistsException e) { //expected } }