Search in sources :

Example 1 with CellProcessor

use of org.molgenis.data.file.processor.CellProcessor in project molgenis by molgenis.

the class ExcelRepositoryTest method addCellProcessor_data.

@Test
public void addCellProcessor_data() {
    CellProcessor processor = when(mock(CellProcessor.class).processData()).thenReturn(true).getMock();
    excelSheetReader.addCellProcessor(processor);
    for (Entity entity : excelSheetReader) entity.get("col2");
    verify(processor).process("val2");
    verify(processor).process("val4");
    verify(processor).process("val6");
}
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 2 with CellProcessor

use of org.molgenis.data.file.processor.CellProcessor in project molgenis by molgenis.

the class ExcelSheetWriterTest method addCellProcessor.

@Test
public void addCellProcessor() throws IOException {
    CellProcessor processor = when(mock(CellProcessor.class).processData()).thenReturn(true).getMock();
    Entity entity = new DynamicEntity(mock(EntityType.class)) {

        @Override
        protected void validateValueType(String attrName, Object value) {
        // noop
        }
    };
    entity.set("col1", "val1");
    entity.set("col2", "val2");
    excelSheetWriter.addCellProcessor(processor);
    excelSheetWriter.add(entity);
    verify(processor).process("val1");
    verify(processor).process("val2");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) CellProcessor(org.molgenis.data.file.processor.CellProcessor) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 3 with CellProcessor

use of org.molgenis.data.file.processor.CellProcessor in project molgenis by molgenis.

the class CsvWriterTest method addCellProcessor_data.

@Test
public void addCellProcessor_data() throws IOException {
    CellProcessor processor = when(mock(CellProcessor.class).processData()).thenReturn(true).getMock();
    Entity entity = new DynamicEntity(entityType);
    entity.set("col1", "val1");
    entity.set("col2", "val2");
    try (CsvWriter csvWriter = new CsvWriter(new StringWriter())) {
        csvWriter.addCellProcessor(processor);
        csvWriter.writeAttributeNames(Arrays.asList("col1", "col2"));
        csvWriter.add(entity);
    }
    verify(processor).process("val1");
    verify(processor).process("val2");
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) StringWriter(java.io.StringWriter) DynamicEntity(org.molgenis.data.support.DynamicEntity) CellProcessor(org.molgenis.data.file.processor.CellProcessor) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 4 with CellProcessor

use of org.molgenis.data.file.processor.CellProcessor in project molgenis by molgenis.

the class CsvWriterTest method addCellProcessor.

@Test
public void addCellProcessor() throws IOException {
    CellProcessor processor = when(mock(CellProcessor.class).processHeader()).thenReturn(true).getMock();
    try (CsvWriter csvWriter = new CsvWriter(new StringWriter())) {
        csvWriter.addCellProcessor(processor);
        csvWriter.writeAttributeNames(Arrays.asList("col1", "col2"));
    }
    verify(processor).process("col1");
    verify(processor).process("col2");
}
Also used : StringWriter(java.io.StringWriter) CellProcessor(org.molgenis.data.file.processor.CellProcessor) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 5 with CellProcessor

use of org.molgenis.data.file.processor.CellProcessor 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)

Aggregations

AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)9 CellProcessor (org.molgenis.data.file.processor.CellProcessor)9 Test (org.testng.annotations.Test)9 Entity (org.molgenis.data.Entity)7 DynamicEntity (org.molgenis.data.support.DynamicEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 StringWriter (java.io.StringWriter)2 EntityType (org.molgenis.data.meta.model.EntityType)2 Writable (org.molgenis.data.Writable)1