@Test public void testWithHeader() throws Exception { ComplexTypeDescriptor countryDescriptor = createCountryDescriptor(); ComplexTypeDescriptor personDescriptor = createPersonDescriptor(countryDescriptor); CSVEntityIterator iterator = new CSVEntityIterator( PLAIN_URI, personDescriptor, new NoOpConverter<String>(), ',', Encodings.UTF_8); assertEquals(new Entity(personDescriptor, "name", "Alice", "age", 23), nextOf(iterator)); assertEquals(new Entity(personDescriptor, "name", "Bob", "age", 34), nextOf(iterator)); assertEquals(new Entity(personDescriptor, "name", "Charly", "age", 45), nextOf(iterator)); assertUnavailable(iterator); }
@Test public void testWithoutHeader() throws Exception { ComplexTypeDescriptor countryDescriptor = createCountryDescriptor(); ComplexTypeDescriptor personDescriptor = createPersonDescriptor(countryDescriptor); CSVEntityIterator iterator = new CSVEntityIterator( PLAIN_URI, personDescriptor, new NoOpConverter<String>(), ',', Encodings.UTF_8); iterator.setColumns(new String[] {"c1", "c2"}); assertEquals(new Entity(personDescriptor, "c1", "name", "c2", "age"), nextOf(iterator)); assertEquals(new Entity(personDescriptor, "c1", "Alice", "c2", "23"), nextOf(iterator)); assertEquals(new Entity(personDescriptor, "c1", "Bob", "c2", "34"), nextOf(iterator)); assertEquals(new Entity(personDescriptor, "c1", "Charly", "c2", "45"), nextOf(iterator)); assertUnavailable(iterator); }
@Test public void testGraph() throws Exception { ComplexTypeDescriptor countryDescriptor = createCountryDescriptor(); ComplexTypeDescriptor personDescriptor = createPersonDescriptor(countryDescriptor); // Define expected countries Entity germany = new Entity(countryDescriptor, "isoCode", "DE", "name", "Germany"); Entity usa = new Entity(countryDescriptor, "isoCode", "US", "name", "USA"); // Define expected persons Entity alice = new Entity(personDescriptor, "name", "Alice", "age", 23, "country", germany); Entity bob = new Entity(personDescriptor, "name", "Bob", "age", 34, "country", usa); // iterate CSV file and check iterator output CSVEntityIterator iterator = new CSVEntityIterator(GRAPH_URI, personDescriptor, null, ',', Encodings.UTF_8); assertEquals(alice, nextOf(iterator)); assertEquals(bob, nextOf(iterator)); assertUnavailable(iterator); }