Search in sources :

Example 51 with Entity

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");
}
Also used : Entity(org.molgenis.data.Entity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 52 with Entity

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");
}
Also used : Entity(org.molgenis.data.Entity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 53 with Entity

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");
    }
}
Also used : Entity(org.molgenis.data.Entity) CellProcessor(org.molgenis.data.file.processor.CellProcessor) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 54 with Entity

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());
    }
}
Also used : Entity(org.molgenis.data.Entity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 55 with Entity

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;
        }
    };
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Aggregations

Entity (org.molgenis.data.Entity)448 Test (org.testng.annotations.Test)295 DynamicEntity (org.molgenis.data.support.DynamicEntity)192 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)120 Attribute (org.molgenis.data.meta.model.Attribute)111 EntityType (org.molgenis.data.meta.model.EntityType)110 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)37 MolgenisDataException (org.molgenis.data.MolgenisDataException)20 QueryImpl (org.molgenis.data.support.QueryImpl)20 AttributeType (org.molgenis.data.meta.AttributeType)18 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)18 Stream (java.util.stream.Stream)17 QueryRule (org.molgenis.data.QueryRule)16 MultiAllelicResultFilter (org.molgenis.data.annotation.core.filter.MultiAllelicResultFilter)16 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)16 Objects.requireNonNull (java.util.Objects.requireNonNull)15 DataService (org.molgenis.data.DataService)15 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 Instant (java.time.Instant)13