use of org.molgenis.data.Entity in project molgenis by molgenis.
the class CsvIteratorTest method testIteratorFromCsvFile.
@Test
public void testIteratorFromCsvFile() throws IOException {
File csvFile = createTmpFileForResource("testdata.csv");
CsvIterator it = new CsvIterator(csvFile, "testdata", null, null, entityType);
assertEquals(it.getColNamesMap().keySet(), Sets.newLinkedHashSet(Arrays.asList("col1", "col2")));
assertEquals(Iterators.size(it), 5);
it = new CsvIterator(csvFile, "testdata", null, null, entityType);
Entity entity = it.next();
assertEquals(entity.get("col1"), "val1");
assertEquals(entity.get("col2"), "val2");
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class CsvIteratorTest method testIteratorFromCsvFileWithBom.
@Test
public void testIteratorFromCsvFileWithBom() throws IOException {
File csvFile = createTmpFileForResource("testDataWithBom.csv");
CsvIterator it = new CsvIterator(csvFile, "testdata", null, null, entityType);
assertEquals(it.getColNamesMap().keySet(), Sets.newLinkedHashSet(Arrays.asList("col1", "col2")));
assertEquals(Iterators.size(it), 5);
it = new CsvIterator(csvFile, "testdata", null, null, entityType);
Entity entity = it.next();
assertEquals(entity.get("col1"), "val1");
assertEquals(entity.get("col2"), "val2");
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class CsvRepositoryTest method addCellProcessor_header.
@Test
public void addCellProcessor_header() throws IOException {
CellProcessor processor = when(mock(CellProcessor.class).processHeader()).thenReturn(true).getMock();
when(processor.process("col1")).thenReturn("col1");
when(processor.process("col2")).thenReturn("col2");
try (CsvRepository csvRepository = new CsvRepository(test, entityTypeFactory, attrMetaFactory, null)) {
csvRepository.addCellProcessor(processor);
for (@SuppressWarnings("unused") Entity entity : csvRepository) {
}
verify(processor).process("col1");
verify(processor).process("col2");
}
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class CsvRepositoryTest method iterator_emptylines.
@Test
public void iterator_emptylines() throws IOException {
try (CsvRepository csvRepository = new CsvRepository(emptylines, entityTypeFactory, attrMetaFactory, null)) {
Iterator<Entity> it = csvRepository.iterator();
Entity entity = it.next();
assertEquals(entity.get("col1"), "val1");
assertEquals(entity.get("col2"), "val2");
assertFalse(it.hasNext());
}
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class SortaCsvRepository method iterator.
@Override
public Iterator<Entity> iterator() {
final AtomicInteger count = new AtomicInteger(0);
final Iterator<Entity> iterator = csvRepository.iterator();
return new Iterator<Entity>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public Entity next() {
Entity entity = iterator.next();
if (isEmpty(entity.getString(ALLOWED_IDENTIFIER))) {
DynamicEntity dynamicEntity = new DynamicEntity(getEntityType());
dynamicEntity.set(entity);
entity = dynamicEntity;
entity.set(ALLOWED_IDENTIFIER, String.valueOf(count.incrementAndGet()));
}
return entity;
}
};
}
Aggregations