Search in sources :

Example 1 with TransformationExample

use of eu.esdihumboldt.cst.test.TransformationExample in project hale by halestudio.

the class XLSInstanceWriterTest method testWriteNotNestedProperties.

/**
 * Test - write data of complex schema and analyze result The
 * implementation, this test based on, does not work correctly at the
 * moment.
 *
 * @throws Exception , if an error occurs
 */
@Test
public void testWriteNotNestedProperties() throws Exception {
    TransformationExample example = TransformationExamples.getExample(TransformationExamples.SIMPLE_COMPLEX);
    // alternative the data could be generated by iterating through the
    // exempleproject's sourcedata
    List<String> header = Arrays.asList("id", "name");
    List<String> firstDataRow = Arrays.asList("id0", "name0");
    // set instances to xls instance writer
    XLSInstanceWriter writer = new XLSInstanceWriter();
    IContentType contentType = HalePlatform.getContentTypeManager().getContentType("eu.esdihumboldt.hale.io.xls.xls");
    writer.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES, Value.of(false));
    File tmpFile = tmpFolder.newFile("excelNotNestedProperties.xls");
    writer.setInstances(example.getSourceInstances());
    // write instances to a temporary XLS file
    writer.setTarget(new FileIOSupplier(tmpFile));
    writer.setContentType(contentType);
    IOReport report = writer.execute(null);
    assertTrue(report.isSuccess());
    Workbook wb = WorkbookFactory.create(tmpFile);
    Sheet sheet = wb.getSheetAt(0);
    checkHeader(sheet, header);
    checkSheetName(sheet, "person");
    checkFirstDataRow(sheet, firstDataRow);
}
Also used : XLSInstanceWriter(eu.esdihumboldt.hale.io.xls.writer.XLSInstanceWriter) TransformationExample(eu.esdihumboldt.cst.test.TransformationExample) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) IContentType(org.eclipse.core.runtime.content.IContentType) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) File(java.io.File) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 2 with TransformationExample

use of eu.esdihumboldt.cst.test.TransformationExample in project hale by halestudio.

the class XLSInstanceWriterTest method testWriteComplexSchema.

/**
 * Test - write data of complex schema and analyze result
 *
 * @throws Exception , if an error occurs
 */
@Test
public void testWriteComplexSchema() throws Exception {
    TransformationExample example = TransformationExamples.getExample(TransformationExamples.SIMPLE_COMPLEX);
    // alternative the data could be generated by iterating through the
    // exempleproject's sourcedata
    List<String> header = Arrays.asList("id", "name", "details.age", "details.income", "details.address.street", "details.address.city");
    List<String> firstDataRow = Arrays.asList("id0", "name0", "age0", "income0", "street0", "city0");
    // set instances to xls instance writer
    XLSInstanceWriter writer = new XLSInstanceWriter();
    IContentType contentType = HalePlatform.getContentTypeManager().getContentType("eu.esdihumboldt.hale.io.xls.xls");
    writer.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES, Value.of(true));
    File tmpFile = tmpFolder.newFile("excelTestWriteComplexSchema.xls");
    writer.setInstances(example.getSourceInstances());
    // write instances to a temporary XLS file
    writer.setTarget(new FileIOSupplier(tmpFile));
    writer.setContentType(contentType);
    IOReport report = writer.execute(null);
    assertTrue(report.isSuccess());
    Workbook wb = WorkbookFactory.create(tmpFile);
    Sheet sheet = wb.getSheetAt(0);
    checkHeader(sheet, header);
    checkSheetName(sheet, "person");
    checkFirstDataRow(sheet, firstDataRow);
}
Also used : XLSInstanceWriter(eu.esdihumboldt.hale.io.xls.writer.XLSInstanceWriter) TransformationExample(eu.esdihumboldt.cst.test.TransformationExample) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) IContentType(org.eclipse.core.runtime.content.IContentType) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) File(java.io.File) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 3 with TransformationExample

use of eu.esdihumboldt.cst.test.TransformationExample in project hale by halestudio.

the class CSVInstanceWriterTest method testWriteSimpleSchema.

/**
 * Test - write simple data, without nested properties
 *
 * @throws Exception , if an error occurs
 */
@Test
public void testWriteSimpleSchema() throws Exception {
    TransformationExample example = TransformationExamples.getExample(TransformationExamples.SIMPLE_ASSIGN);
    // alternative the data could be generated by iterating through the
    // exempleproject's source data
    String propertyNames = "id,a1,b1,c1";
    String firstDataRow = "id0,a10,b10,c10";
    // header size
    int numberOfEntries = 4;
    int numberOfRows = 3;
    char sep = ',';
    File tmpFile = tmpFolder.newFile("csvTestWriteSimpleSchema.csv");
    assertTrue("Csv Export was not successful.", writeCsvToFile(tmpFile, true, Value.of(sep), null, null, example.getSourceInstances()));
    CSVReader reader = new CSVReader(new FileReader(tmpFile), sep);
    List<String[]> rows = reader.readAll();
    // 
    reader.close();
    assertEquals("Not enough rows.", numberOfRows, rows.size());
    // Check header ###
    Iterator<String[]> row = rows.iterator();
    String[] header = row.next();
    assertEquals("There are not enough entries.", numberOfEntries, header.length);
    for (int i = 0; i < header.length; i++) {
        assertTrue("The header of the csv file do not contain all properties.", propertyNames.contains(header[i]));
    }
    String[] dataRow = row.next();
    for (int i = 0; i < dataRow.length; i++) {
        assertTrue("The first data row of the csv file do not contain all properties.", firstDataRow.contains(dataRow[i]));
    }
}
Also used : CSVReader(au.com.bytecode.opencsv.CSVReader) TransformationExample(eu.esdihumboldt.cst.test.TransformationExample) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Example 4 with TransformationExample

use of eu.esdihumboldt.cst.test.TransformationExample in project hale by halestudio.

the class CSVInstanceWriterTest method testWriteSimpleSchemaDelimiter.

/**
 * Test - write simple data, without nested properties
 *
 * @throws Exception , if an error occurs
 */
@Test
public void testWriteSimpleSchemaDelimiter() throws Exception {
    TransformationExample example = TransformationExamples.getExample(TransformationExamples.SIMPLE_ASSIGN);
    // alternative the data could be generated by iterating through the
    // exempleproject's source data
    String propertyNames = "id,a1,b1,c1";
    String firstDataRow = "id0,a10,b10,c10";
    // header size
    int numberOfEntries = 4;
    int numberOfRows = 3;
    char sep = '\t';
    char quo = '\'';
    char esc = '"';
    File tmpFile = tmpFolder.newFile("csvTestWriteSimpleSchemaDelimiter.csv");
    assertTrue("Csv Export was not successful.", writeCsvToFile(tmpFile, true, Value.of(sep), Value.of(quo), Value.of(esc), example.getSourceInstances()));
    CSVReader reader = new CSVReader(new FileReader(tmpFile), sep, quo, esc);
    List<String[]> rows = reader.readAll();
    // 
    reader.close();
    assertEquals("Not enough rows.", numberOfRows, rows.size());
    // Check header ###
    Iterator<String[]> row = rows.iterator();
    String[] header = row.next();
    assertEquals("There are not enough entries.", numberOfEntries, header.length);
    for (int i = 0; i < header.length; i++) {
        assertTrue("The header of the csv file do not contain all properties.", propertyNames.contains(header[i]));
    }
    String[] dataRow = row.next();
    for (int i = 0; i < dataRow.length; i++) {
        assertTrue("The first data row of the csv file do not contain all properties. Miss on : " + dataRow[i], firstDataRow.contains(dataRow[i]));
    }
}
Also used : CSVReader(au.com.bytecode.opencsv.CSVReader) TransformationExample(eu.esdihumboldt.cst.test.TransformationExample) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Example 5 with TransformationExample

use of eu.esdihumboldt.cst.test.TransformationExample in project hale by halestudio.

the class CSVInstanceWriterTest method testWriteComplexSchema.

/**
 * Test - write data of complex schema and analyze result
 *
 * @throws Exception , if an error occurs
 */
@Test
public void testWriteComplexSchema() throws Exception {
    TransformationExample example = TransformationExamples.getExample(TransformationExamples.SIMPLE_COMPLEX);
    // alternative the data could be generated by iterating through the
    // exempleproject's source data
    String propertyNames = "id,name,details.age,details.income,details.address.street,details.address.city";
    String firstDataRow = "id0,name0,age0,income0,street0,city0,street1,city1";
    // String secondDataRow =
    // "id1,name1,age1,income1,street2,city2,street3,city3";
    int numberOfEntries = 6;
    int numberOfRows = 3;
    char sep = ',';
    File tmpFile = tmpFolder.newFile("csvTestWriteComplexSchema.csv");
    assertTrue("Csv Export was not successful.", writeCsvToFile(tmpFile, true, Value.of(sep), null, null, example.getSourceInstances()));
    CSVReader reader = new CSVReader(new FileReader(tmpFile), sep);
    List<String[]> rows = reader.readAll();
    // 
    reader.close();
    assertEquals("Not enough rows.", numberOfRows, rows.size());
    // Check header ###
    Iterator<String[]> row = rows.iterator();
    String[] header = row.next();
    assertEquals("There are not enough entries.", numberOfEntries, header.length);
    for (int i = 0; i < header.length; i++) {
        assertTrue("The header of the csv file do not contain all properties.", propertyNames.contains(header[i]));
    // This is for debug purposes to check which properties are missing
    // propertyNames = propertyNames.replaceFirst(header[i], "");
    }
    String[] dataRow = row.next();
    for (int i = 0; i < dataRow.length; i++) {
        assertTrue("The first data row of the csv file do not contain all properties.", firstDataRow.contains(dataRow[i]));
    // This is for debug purposes ...
    // firstDataRow = firstDataRow.replaceFirst(dataRow[i], "");
    }
}
Also used : CSVReader(au.com.bytecode.opencsv.CSVReader) TransformationExample(eu.esdihumboldt.cst.test.TransformationExample) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Aggregations

TransformationExample (eu.esdihumboldt.cst.test.TransformationExample)5 File (java.io.File)5 Test (org.junit.Test)5 CSVReader (au.com.bytecode.opencsv.CSVReader)3 FileReader (java.io.FileReader)3 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)2 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)2 XLSInstanceWriter (eu.esdihumboldt.hale.io.xls.writer.XLSInstanceWriter)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 IContentType (org.eclipse.core.runtime.content.IContentType)2