use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class ImportFacadeIT method testImportEmptyHeaderCSV.
@Test
public void testImportEmptyHeaderCSV() {
final String noHeaderCsv = "\n" + "a;b;c;d\n" + "a;b;c;d\n";
ImportedCollection importedCollection = createImportObject(noHeaderCsv);
Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
assertThat(collection).isNotNull();
List<DataDocument> data = dataDao.getData(collection.getId(), query());
// it's because library ignores any leading empty lines
assertThat(data).hasSize(1);
assertThat(data.get(0).keySet()).containsOnly("_id", "a", "b", "c", "d");
assertThat(data.get(0).getString("a")).isEqualTo("a");
assertThat(data.get(0).getString("b")).isEqualTo("b");
assertThat(data.get(0).getString("c")).isEqualTo("c");
assertThat(data.get(0).getString("d")).isEqualTo("d");
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class ImportFacadeIT method testImportCommaSeparatedCSV.
@Test
public void testImportCommaSeparatedCSV() {
final String commaSeparatedCsv = "h1,h2,h3\n" + "a,,c,d\n" + ",,,\n" + "a,b,c,d\n";
ImportedCollection importedCollection = createImportObject(commaSeparatedCsv);
Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
assertThat(collection).isNotNull();
List<DataDocument> data = dataDao.getData(collection.getId(), query());
assertThat(data).hasSize(3);
int h1Num = 0;
int h2Num = 0;
int h3Num = 0;
for (DataDocument dataDocument : data) {
String h1 = dataDocument.getString("h1");
String h2 = dataDocument.getString("h2");
String h3 = dataDocument.getString("h3");
h1Num += h1 != null && h1.equals("a") ? 1 : 0;
h2Num += h2 != null && h2.equals("b") ? 1 : 0;
h3Num += h3 != null && h3.equals("c") ? 1 : 0;
}
assertThat(h1Num).isEqualTo(2);
assertThat(h2Num).isEqualTo(1);
assertThat(h3Num).isEqualTo(2);
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class ImportFacadeIT method testImportCorrectCSV.
@Test
public void testImportCorrectCSV() {
final String correctCsv = "h1;h2;h3;h4\n" + ";b;c;d\n" + ";;c;d\n" + "a;b;;d\n" + "a;b;;\n";
ImportedCollection importedCollection = createImportObject(correctCsv);
Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
assertThat(collection).isNotNull();
List<DataDocument> data = dataDao.getData(collection.getId(), query());
assertThat(data).hasSize(4);
int h1Num = 0;
int h2Num = 0;
int h3Num = 0;
int h4Num = 0;
for (DataDocument dataDocument : data) {
String h1 = dataDocument.getString("h1");
String h2 = dataDocument.getString("h2");
String h3 = dataDocument.getString("h3");
String h4 = dataDocument.getString("h4");
h1Num += h1 != null && h1.equals("a") ? 1 : 0;
h2Num += h2 != null && h2.equals("b") ? 1 : 0;
h3Num += h3 != null && h3.equals("c") ? 1 : 0;
h4Num += h4 != null && h4.equals("d") ? 1 : 0;
}
assertThat(h1Num).isEqualTo(2);
assertThat(h2Num).isEqualTo(3);
assertThat(h3Num).isEqualTo(2);
assertThat(h4Num).isEqualTo(3);
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class ImportFacadeIT method testImportNoLinesCSV.
@Test
public void testImportNoLinesCSV() {
final String noLinesCsv = "h1;h2;h3;h4\n";
ImportedCollection importedCollection = createImportObject(noLinesCsv);
Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
assertThat(collection).isNotNull();
List<DataDocument> data = dataDao.getData(collection.getId(), query());
assertThat(data).isEmpty();
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class ImportFacadeIT method testImportDiffRowsLengthCSV.
@Test
public void testImportDiffRowsLengthCSV() {
final String diffRowsLengthCsv = "h1;h2;h3\n" + "a;b;c;d\n" + "a;b;c;d;e;f;g;h\n" + "\n\n\n\n\n" + "a;b;c\n";
ImportedCollection importedCollection = createImportObject(diffRowsLengthCsv);
Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
assertThat(collection).isNotNull();
List<DataDocument> data = dataDao.getData(collection.getId(), query());
assertThat(data).hasSize(3);
int h1Num = 0;
int h2Num = 0;
int h3Num = 0;
for (DataDocument dataDocument : data) {
String h1 = dataDocument.getString("h1");
String h2 = dataDocument.getString("h2");
String h3 = dataDocument.getString("h3");
h1Num += h1 != null && h1.equals("a") ? 1 : 0;
h2Num += h2 != null && h2.equals("b") ? 1 : 0;
h3Num += h3 != null && h3.equals("c") ? 1 : 0;
}
assertThat(h1Num).isEqualTo(3);
assertThat(h2Num).isEqualTo(3);
assertThat(h3Num).isEqualTo(3);
}
Aggregations