Search in sources :

Example 6 with CellProcessor

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

the class ExcelWriterTest method addCellProcessor_header.

@Test
public void addCellProcessor_header() throws IOException {
    CellProcessor processor = when(mock(CellProcessor.class).processHeader()).thenReturn(true).getMock();
    OutputStream os = mock(OutputStream.class);
    ExcelWriter excelWriter = new ExcelWriter(os, attrMetaFactory);
    excelWriter.addCellProcessor(processor);
    try {
        excelWriter.createWritable("sheet", Arrays.asList("col1", "col2"));
    } finally {
        excelWriter.close();
    }
    verify(processor).process("col1");
    verify(processor).process("col2");
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CellProcessor(org.molgenis.data.file.processor.CellProcessor) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 7 with CellProcessor

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

Example 8 with CellProcessor

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

the class ExcelRepositoryTest method addCellProcessor_header.

@Test
public void addCellProcessor_header() {
    CellProcessor processor = mock(CellProcessor.class);
    when(processor.processHeader()).thenReturn(true);
    when(processor.process("col1")).thenReturn("col1");
    when(processor.process("col2")).thenReturn("col2");
    excelSheetReader.addCellProcessor(processor);
    for (@SuppressWarnings("unused") Entity entity : excelSheetReader) {
    }
    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 9 with CellProcessor

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

the class CsvRepositoryTest method addCellProcessor_data.

@Test
public void addCellProcessor_data() throws IOException {
    CellProcessor processor = when(mock(CellProcessor.class).processData()).thenReturn(true).getMock();
    try (CsvRepository csvRepository = new CsvRepository(test, entityTypeFactory, attrMetaFactory, null)) {
        csvRepository.addCellProcessor(processor);
        for (@SuppressWarnings("unused") Entity entity : csvRepository) {
        }
        verify(processor).process("val1");
        verify(processor).process("val2");
    }
}
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