Search in sources :

Example 26 with Collection

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");
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) ImportedCollection(io.lumeer.api.model.ImportedCollection) JsonCollection(io.lumeer.api.dto.JsonCollection) ImportedCollection(io.lumeer.api.model.ImportedCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Example 27 with Collection

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) ImportedCollection(io.lumeer.api.model.ImportedCollection) JsonCollection(io.lumeer.api.dto.JsonCollection) ImportedCollection(io.lumeer.api.model.ImportedCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Example 28 with Collection

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) ImportedCollection(io.lumeer.api.model.ImportedCollection) JsonCollection(io.lumeer.api.dto.JsonCollection) ImportedCollection(io.lumeer.api.model.ImportedCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Example 29 with Collection

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();
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) ImportedCollection(io.lumeer.api.model.ImportedCollection) JsonCollection(io.lumeer.api.dto.JsonCollection) ImportedCollection(io.lumeer.api.model.ImportedCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Example 30 with Collection

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) ImportedCollection(io.lumeer.api.model.ImportedCollection) JsonCollection(io.lumeer.api.dto.JsonCollection) ImportedCollection(io.lumeer.api.model.ImportedCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Aggregations

Collection (io.lumeer.api.model.Collection)77 Test (org.junit.Test)47 JsonCollection (io.lumeer.api.dto.JsonCollection)34 DataDocument (io.lumeer.engine.api.data.DataDocument)17 MorphiaCollection (io.lumeer.storage.mongodb.model.MorphiaCollection)17 SearchQuery (io.lumeer.storage.api.query.SearchQuery)14 SoftAssertions (org.assertj.core.api.SoftAssertions)12 Document (io.lumeer.api.model.Document)8 ImportedCollection (io.lumeer.api.model.ImportedCollection)8 SuggestionQuery (io.lumeer.storage.api.query.SuggestionQuery)8 Response (javax.ws.rs.core.Response)8 JsonAttribute (io.lumeer.api.dto.JsonAttribute)7 Attribute (io.lumeer.api.model.Attribute)7 HashSet (java.util.HashSet)6 JsonQuery (io.lumeer.api.dto.JsonQuery)5 LocalDateTime (java.time.LocalDateTime)4 List (java.util.List)4 JsonDocument (io.lumeer.api.dto.JsonDocument)3 LinkType (io.lumeer.api.model.LinkType)3 CollectionDao (io.lumeer.storage.api.dao.CollectionDao)3