@Test public void testFormatShakespeareOutputFn() { DoFnTester<KV<String, String>, TableRow> formatShakespeareOutputFn = DoFnTester.of(new FormatShakespeareOutputFn()); List<TableRow> results = formatShakespeareOutputFn.processBatch(COMBINED_TUPLES_ARRAY); Assert.assertThat(results, CoreMatchers.hasItem(resultRow1)); Assert.assertThat(results, CoreMatchers.hasItem(resultRow2)); }
/** * This test verifies whether the transparent caching works for the three resources provided by * our dummy provider. * * @throws Exception */ @Test public void testCachedResources() throws Exception { String uri1 = "http://localhost/resource1"; String uri2 = "http://localhost/resource2"; String uri3 = "http://localhost/resource3"; RepositoryConnection con = repository.getConnection(); try { con.begin(); List<Statement> list1 = Iterations.asList( con.getStatements(con.getValueFactory().createURI(uri1), null, null, true)); Assert.assertEquals(3, list1.size()); Assert.assertThat( list1, allOf( CoreMatchers.<Statement>hasItem(hasProperty("object", hasToString("\"Value 1\""))), CoreMatchers.<Statement>hasItem(hasProperty("object", hasToString("\"Value X\""))))); con.commit(); con.begin(); List<Statement> list2 = Iterations.asList( con.getStatements(con.getValueFactory().createURI(uri2), null, null, true)); Assert.assertEquals(2, list2.size()); Assert.assertThat( list2, allOf( CoreMatchers.<Statement>hasItem(hasProperty("object", hasToString("\"Value 2\""))))); con.commit(); con.begin(); List<Statement> list3 = Iterations.asList( con.getStatements(con.getValueFactory().createURI(uri3), null, null, true)); Assert.assertEquals(2, list3.size()); Assert.assertThat( list3, allOf( CoreMatchers.<Statement>hasItem(hasProperty("object", hasToString("\"Value 3\""))), CoreMatchers.<Statement>hasItem(hasProperty("object", hasToString("\"Value 4\""))))); con.commit(); } catch (RepositoryException ex) { con.rollback(); } finally { con.close(); } }
@Test public void testExtractLargeWordsFn() { DoFnTester<TableRow, KV<String, String>> extractLargeWordsFn = DoFnTester.of(new ExtractLargeWordsFn()); List<KV<String, String>> results = extractLargeWordsFn.processBatch(ROWS_ARRAY); Assert.assertThat(results, CoreMatchers.hasItem(tuple1)); Assert.assertThat(results, CoreMatchers.hasItem(tuple2)); Assert.assertThat(results, CoreMatchers.hasItem(tuple3)); }
@Test public void testJavaLoggerProxyAndAssertions() { ITest<Person> testClient = Person::new; ITest clientProxy = LoggerProxyFactory.newProxyFactory(testClient).buildProxy(); testClient.demoAPI("name", "address", Arrays.asList("12345")); Person person = (Person) clientProxy.demoAPI("name proxy", "address proxy", Arrays.asList("54321")); new JsonAssertion(person.toString()) .pathMatch("$.name", "name proxy") .pathMatch("$.phone", CoreMatchers.hasItem("54321")); }