Search in sources :

Example 16 with DataDocument

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

the class MongoDbStorageTest method testReplaceDocument.

@Test
public void testReplaceDocument() throws Exception {
    mongoDbStorage.createCollection(COLLECTION_REPLACE_DOCUMENT);
    DataDocument insertedDocument = new DataDocument("a", 1).append("b", 2).append("c", 3);
    String documentId = mongoDbStorage.createDocument(COLLECTION_REPLACE_DOCUMENT, insertedDocument);
    final DataFilter documentIdFilter = mongoDbStorageDialect.documentIdFilter(documentId);
    DataDocument replaceDocument = new DataDocument("d", 4).append("e", 5).append("f", 6);
    mongoDbStorage.replaceDocument(COLLECTION_REPLACE_DOCUMENT, replaceDocument, documentIdFilter);
    DataDocument readedDocument = mongoDbStorage.readDocument(COLLECTION_REPLACE_DOCUMENT, documentIdFilter);
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(readedDocument.containsKey("a")).as("a").isFalse();
    assertions.assertThat(readedDocument.containsKey("b")).as("b").isFalse();
    assertions.assertThat(readedDocument.containsKey("c")).as("c").isFalse();
    assertions.assertThat(readedDocument.containsKey("d")).as("d").isTrue();
    assertions.assertThat(readedDocument.containsKey("e")).as("e").isTrue();
    assertions.assertThat(readedDocument.containsKey("f")).as("f").isTrue();
    assertions.assertAll();
}
Also used : DataFilter(io.lumeer.engine.api.data.DataFilter) DataDocument(io.lumeer.engine.api.data.DataDocument) SoftAssertions(org.assertj.core.api.SoftAssertions) Test(org.junit.Test)

Example 17 with DataDocument

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

the class MongoDbStorageTest method testDropAttribute.

@Test
public void testDropAttribute() throws Exception {
    mongoDbStorage.createCollection(COLLECTION_DROP_ATTRIBUTE);
    DataDocument insertedDocument = createDummyDocument();
    String documentId = mongoDbStorage.createDocument(COLLECTION_DROP_ATTRIBUTE, insertedDocument);
    DataDocument readedDocument = mongoDbStorage.readDocument(COLLECTION_DROP_ATTRIBUTE, mongoDbStorageDialect.documentIdFilter(documentId));
    assertThat(readedDocument).hasSize(3);
    final DataFilter documentIdFilter = mongoDbStorageDialect.documentIdFilter(documentId);
    mongoDbStorage.dropAttribute(COLLECTION_DROP_ATTRIBUTE, documentIdFilter, DUMMY_KEY1);
    readedDocument = mongoDbStorage.readDocument(COLLECTION_DROP_ATTRIBUTE, documentIdFilter);
    assertThat(readedDocument).hasSize(2);
}
Also used : DataFilter(io.lumeer.engine.api.data.DataFilter) DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 18 with DataDocument

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

the class MongoDbStorageTest method testBasicArrayManipulation.

@Test
public void testBasicArrayManipulation() throws Exception {
    mongoDbStorage.createCollection(COLLECTION_BASIC_ARRAY_MANIPULATION);
    DataDocument doc = createDummyDocument();
    doc.put("a", Arrays.asList(1, 2, 3, 4));
    String id = mongoDbStorage.createDocument(COLLECTION_BASIC_ARRAY_MANIPULATION, doc);
    final DataFilter documentIdFilter = mongoDbStorageDialect.documentIdFilter(id);
    DataDocument fromDb = mongoDbStorage.readDocument(COLLECTION_BASIC_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("a", Integer.class)).hasSize(4);
    mongoDbStorage.addItemToArray(COLLECTION_BASIC_ARRAY_MANIPULATION, documentIdFilter, "a", 10);
    fromDb = mongoDbStorage.readDocument(COLLECTION_BASIC_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("a", Integer.class)).hasSize(5);
    mongoDbStorage.addItemsToArray(COLLECTION_BASIC_ARRAY_MANIPULATION, documentIdFilter, "a", Arrays.asList(5, 6, 7));
    fromDb = mongoDbStorage.readDocument(COLLECTION_BASIC_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("a", Integer.class)).hasSize(8);
    mongoDbStorage.removeItemFromArray(COLLECTION_BASIC_ARRAY_MANIPULATION, documentIdFilter, "a", 10);
    fromDb = mongoDbStorage.readDocument(COLLECTION_BASIC_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("a", Integer.class)).hasSize(7);
    mongoDbStorage.removeItemsFromArray(COLLECTION_BASIC_ARRAY_MANIPULATION, documentIdFilter, "a", Arrays.asList(5, 6, 7));
    fromDb = mongoDbStorage.readDocument(COLLECTION_BASIC_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("a", Integer.class)).hasSize(4);
}
Also used : DataFilter(io.lumeer.engine.api.data.DataFilter) DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 19 with DataDocument

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

the class MongoDbStorageTest method testSearch.

@Test
public void testSearch() throws Exception {
    mongoDbStorage.createCollection(COLLECTION_SEARCH);
    for (int i = 0; i < 100; i++) {
        DataDocument insertedDocument = createDummyDocument();
        mongoDbStorage.createDocument(COLLECTION_SEARCH, insertedDocument);
    }
    List<DataDocument> searchDocuments = mongoDbStorage.search(COLLECTION_SEARCH, null, null, 10, 10);
    assertThat(searchDocuments).hasSize(10);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 20 with DataDocument

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

the class MongoDbStorageTest method testGetAttributeValues.

@Test
public void testGetAttributeValues() throws Exception {
    mongoDbStorage.createCollection(COLLECTION_GET_ATTRIBUTE_VALUES);
    // simple case
    int numDummyKey1 = 150;
    int numDummyKey2 = 10;
    for (int i = 0; i < numDummyKey1; i++) {
        DataDocument dataDocument = new DataDocument();
        dataDocument.put(DUMMY_KEY1, i);
        dataDocument.put(DUMMY_KEY2, i % numDummyKey2);
        mongoDbStorage.createDocument(COLLECTION_GET_ATTRIBUTE_VALUES, dataDocument);
    }
    Set<String> attributeValues1 = mongoDbStorage.getAttributeValues(COLLECTION_GET_ATTRIBUTE_VALUES, DUMMY_KEY1);
    assertThat(attributeValues1).hasSize(Math.min(numDummyKey1, 100));
    Set<String> attributeValues2 = mongoDbStorage.getAttributeValues(COLLECTION_GET_ATTRIBUTE_VALUES, DUMMY_KEY2);
    assertThat(attributeValues2).hasSize(Math.min(numDummyKey2, 100));
    // case when some attribute value is null
    String k1 = "k1";
    String k2 = "k2";
    String v1 = "v1";
    String v2 = "v2";
    String v3 = "v3";
    DataDocument d1 = new DataDocument();
    d1.put(k1, v1);
    d1.put(k2, v2);
    DataDocument d2 = new DataDocument();
    d2.put(k1, v3);
    mongoDbStorage.createDocument(COLLECTION_GET_ATTRIBUTE_VALUES, d1);
    mongoDbStorage.createDocument(COLLECTION_GET_ATTRIBUTE_VALUES, d2);
    Set<String> a1 = mongoDbStorage.getAttributeValues(COLLECTION_GET_ATTRIBUTE_VALUES, k1);
    assertThat(a1).containsExactlyInAnyOrder(v1, v3);
}
Also used : 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