Search in sources :

Example 1 with Writable

use of org.molgenis.data.Writable in project molgenis by molgenis.

the class ExcelWriterTest method addCellProcessor_data.

@Test
public void addCellProcessor_data() throws IOException {
    CellProcessor processor = when(mock(CellProcessor.class).processData()).thenReturn(true).getMock();
    OutputStream os = mock(OutputStream.class);
    ExcelWriter excelWriter = new ExcelWriter(os, attrMetaFactory);
    excelWriter.addCellProcessor(processor);
    try {
        Entity entity = new DynamicEntity(mock(EntityType.class)) {

            @Override
            protected void validateValueType(String attrName, Object value) {
            // noop
            }
        };
        entity.set("col1", "val1");
        entity.set("col2", "val2");
        Writable writable = excelWriter.createWritable("test", Arrays.asList("col1", "col2"));
        writable.add(entity);
    } finally {
        excelWriter.close();
    }
    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) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CellProcessor(org.molgenis.data.file.processor.CellProcessor) Writable(org.molgenis.data.Writable) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

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