Search in sources :

Example 56 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MongoDbStorageTest method testDropDocument.

@Test
public void testDropDocument() throws Exception {
    mongoDbStorage.createCollection(COLLECTION_DROP_DOCUMENT);
    DataDocument insertedDocument = createDummyDocument();
    String documentId = mongoDbStorage.createDocument(COLLECTION_DROP_DOCUMENT, insertedDocument);
    final DataFilter documentIdFilter = mongoDbStorageDialect.documentIdFilter(documentId);
    DataDocument readedDocument = mongoDbStorage.readDocument(COLLECTION_DROP_DOCUMENT, documentIdFilter);
    assertThat(readedDocument).isNotNull();
    mongoDbStorage.dropDocument(COLLECTION_DROP_DOCUMENT, documentIdFilter);
    readedDocument = mongoDbStorage.readDocument(COLLECTION_DROP_DOCUMENT, documentIdFilter);
    assertThat(readedDocument).isNull();
}
Also used : DataFilter(io.lumeer.engine.api.data.DataFilter) DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 57 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MongoDbStorageTest method getTestDocument.

private DataDocument getTestDocument(final String... values) {
    final DataDocument d = new DataDocument();
    for (int i = 0; i < values.length; i++) {
        try {
            int x = Integer.parseInt(values[i]);
            d.put("param" + (i + 1), x);
        } catch (NumberFormatException nfe) {
            d.put("param" + (i + 1), values[i]);
        }
    }
    return d;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument)

Example 58 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MongoDbStorageTest method testRun.

@Test
public void testRun() throws Exception {
    mongoDbStorage.createCollection(COLLECTION_RUN);
    for (int i = 0; i < 200; i++) {
        DataDocument insertedDocument = createDummyDocument();
        mongoDbStorage.createDocument(COLLECTION_RUN, insertedDocument);
    }
    // query form: https://docs.mongodb.com/v3.2/reference/command/find/#definition
    String query = "{find: \"" + COLLECTION_RUN + "\"}";
    List<DataDocument> searchDocuments = mongoDbStorage.run(query);
    // run() method returns 101 entries due to it is a default value of "batchSize" query key
    assertThat(searchDocuments).hasSize(101);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 59 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MongoDbStorageTest method testSearchAttrs.

@Test
public void testSearchAttrs() throws Exception {
    mongoDbStorage.createCollection(COLLECTION_SEARCH_ATTRS);
    for (int i = 0; i < 200; i++) {
        DataDocument insertedDocument = new DataDocument("a", i).append("b", i * 2).append("c", i * 3).append("d", i + 4).append("e", i + 5).append("f", new DataDocument("a", i).append("b", i - 2).append("c", i * i));
        mongoDbStorage.createDocument(COLLECTION_SEARCH_ATTRS, insertedDocument);
    }
    // test whether we get all documents
    List<DataDocument> docs = mongoDbStorage.search(COLLECTION_SEARCH_ATTRS, null, null);
    assertThat(docs).hasSize(200);
    final DataFilter filter = new MongoDbDataFilter(Filters.gte("a", 100));
    docs = mongoDbStorage.search(COLLECTION_SEARCH_ATTRS, filter, Arrays.asList("a", "c", "f.b"));
    assertThat(docs).hasSize(100);
    DataDocument anyDoc = docs.get(0);
    assertThat(anyDoc).containsKeys("_id", "a", "c", "f");
    assertThat(anyDoc).doesNotContainKeys("b", "d", "e");
    DataDocument nestedDoc = anyDoc.getDataDocument("f");
    assertThat(nestedDoc).containsKey("b");
    assertThat(nestedDoc).doesNotContainKeys("a", "c");
    // test if it's necceserry to include attribute which is used in filter
    docs = mongoDbStorage.search(COLLECTION_SEARCH_ATTRS, filter, Arrays.asList("b", "c", "d"));
    assertThat(docs).hasSize(100);
    anyDoc = docs.get(0);
    assertThat(anyDoc).containsKeys("_id", "b", "c", "d");
    assertThat(anyDoc).doesNotContainKeys("a", "e", "f");
}
Also used : DataFilter(io.lumeer.engine.api.data.DataFilter) DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 60 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MongoDbStorageTest method testSearchWithProjection.

@Test
public void testSearchWithProjection() {
    mongoDbStorage.createCollection(COLLECTION_SEARCH_PROJECTION);
    for (int i = 0; i < 10; i++) {
        DataDocument insertedDocument = createDummyDocument();
        mongoDbStorage.createDocument(COLLECTION_SEARCH_PROJECTION, insertedDocument);
    }
    List<DataDocument> searchDocuments = mongoDbStorage.search(COLLECTION_SEARCH_PROJECTION, null, null, Collections.singletonList(DUMMY_KEY1), 0, 5);
    assertThat(searchDocuments).hasSize(5);
    assertThat(searchDocuments).extracting(d -> d.getString(DUMMY_KEY2)).containsOnly((String) null);
}
Also used : DataFilter(io.lumeer.engine.api.data.DataFilter) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) DataDocument(io.lumeer.engine.api.data.DataDocument) DataStorageStats(io.lumeer.engine.api.data.DataStorageStats) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) MongoBulkWriteException(com.mongodb.MongoBulkWriteException) Filters(com.mongodb.client.model.Filters) Query(io.lumeer.engine.api.data.Query) List(java.util.List) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Before(org.junit.Before) DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Aggregations

DataDocument (io.lumeer.engine.api.data.DataDocument)75 Test (org.junit.Test)42 Collection (io.lumeer.api.model.Collection)16 Document (io.lumeer.api.model.Document)16 JsonDocument (io.lumeer.api.dto.JsonDocument)14 Document (org.bson.Document)13 SoftAssertions (org.assertj.core.api.SoftAssertions)10 ReturnDocument (com.mongodb.client.model.ReturnDocument)9 JsonCollection (io.lumeer.api.dto.JsonCollection)9 DataFilter (io.lumeer.engine.api.data.DataFilter)9 ImportedCollection (io.lumeer.api.model.ImportedCollection)6 SearchQuery (io.lumeer.storage.api.query.SearchQuery)6 LocalDateTime (java.time.LocalDateTime)6 BsonDocument (org.bson.BsonDocument)6 LinkedList (java.util.LinkedList)5 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Response (javax.ws.rs.core.Response)4 DataStorageStats (io.lumeer.engine.api.data.DataStorageStats)3