use of org.molgenis.emx2.io.tablestore.TableStoreForXlsxFile in project molgenis-emx2 by molgenis.
the class TestExcelStore method testSimple.
@Test
public void testSimple() throws IOException {
List<Row> rows = new ArrayList<Row>();
for (int i = 0; i < 10; i++) {
Row r = new Row();
r.set("name", "test" + i);
r.set("id", i);
rows.add(r);
}
Path tmp = Files.createTempDirectory("TestExcelStore");
tmp.toFile().deleteOnExit();
Path excelFile = tmp.resolve("test.xlsx");
TableStoreForXlsxFile store = new TableStoreForXlsxFile(excelFile);
store.writeTable("test", List.of(), rows);
// and read
store = new TableStoreForXlsxFile(excelFile);
List<Row> rows2 = store.readTable("test");
assertEquals(10, rows2.size());
// empty rows
excelFile = tmp.resolve("test.xlsx");
store = new TableStoreForXlsxFile(excelFile);
store.writeTable("test2", List.of("blaat"), new ArrayList<>());
}
use of org.molgenis.emx2.io.tablestore.TableStoreForXlsxFile in project molgenis-emx2 by molgenis.
the class TestReadWriteStores method testExcelStore.
@Test
public void testExcelStore() throws IOException {
Path tmp = Files.createTempDirectory(null);
try {
Path excelFile = tmp.resolve("test.xlsx");
System.out.println("defined excel file " + excelFile);
TableStoreForXlsxFile store = new TableStoreForXlsxFile(excelFile);
executeTest(store);
} catch (MolgenisException e) {
e.printStackTrace();
} finally {
Files.walk(tmp).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
if (Files.exists(tmp))
throw new RuntimeException("TMP directory " + tmp + " not deleted. This should never happen.");
}
use of org.molgenis.emx2.io.tablestore.TableStoreForXlsxFile in project molgenis-emx2 by molgenis.
the class TestColumnTypeIsFile method testExcelShouldNotIncludeFileColumns.
@Test
public void testExcelShouldNotIncludeFileColumns() throws IOException {
Path tmp = Files.createTempDirectory(null);
Path excelFile = tmp.resolve("test.xlsx");
MolgenisIO.toExcelFile(excelFile, schema);
TableStore store = new TableStoreForXlsxFile(excelFile);
assertFalse(store.readTable("User").iterator().next().getColumnNames().contains("picture"));
}
use of org.molgenis.emx2.io.tablestore.TableStoreForXlsxFile in project molgenis-emx2 by molgenis.
the class TestTypesImport method testExcelTypesCast.
@Test
public void testExcelTypesCast() {
ClassLoader classLoader = getClass().getClassLoader();
Path path = new File(classLoader.getResource("TypeTest.xlsx").getFile()).toPath();
TableStore store = new TableStoreForXlsxFile(path);
for (Row r : store.readTable("Sheet1")) {
assertEquals("1.0", r.getString("decimal"));
assertEquals(Double.valueOf(1.0), r.getDecimal("decimal"));
assertEquals("1", r.getString("int"));
assertEquals(Integer.valueOf(1), r.getInteger("int"));
}
}
Aggregations