Search in sources :

Example 61 with DataDocument

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

the class MongoDbStorageTest method collectionStatsTest.

@Test
public void collectionStatsTest() {
    mongoDbStorage.createCollection(COLLECTION_CSTATS);
    mongoDbStorage.createDocument(COLLECTION_CSTATS, new DataDocument("stats", 4));
    mongoDbStorage.createIndex(COLLECTION_CSTATS, new DataDocument("stats", 1), false);
    final DataStorageStats dss = mongoDbStorage.getCollectionStats(COLLECTION_CSTATS);
    assertThat(dss.getDatabaseName()).isEqualTo(EmbeddedMongoDb.NAME);
    assertThat(dss.getCollectionName()).isEqualTo(COLLECTION_CSTATS);
    assertThat(dss.getDocuments()).isEqualTo(1);
    assertThat(dss.getIndexes()).isEqualTo(2);
    assertThat(dss.getDataSize()).isGreaterThan(0);
    assertThat(dss.getStorageSize()).isGreaterThan(0);
    assertThat(dss.getIndexSize()).isGreaterThan(0);
    mongoDbStorage.dropCollection(COLLECTION_CSTATS);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) DataStorageStats(io.lumeer.engine.api.data.DataStorageStats) Test(org.junit.Test)

Example 62 with DataDocument

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

the class MongoDbStorageTest method testComplexArrayManipulation.

@Test
public void testComplexArrayManipulation() throws Exception {
    mongoDbStorage.createCollection(COLLECTION_COMPLEX_ARRAY_MANIPULATION);
    DataDocument d = createDummyDocument();
    DataDocument n = createDummyDocument();
    DataDocument d1 = new DataDocument();
    d1.put("gt", 10);
    DataDocument d2 = new DataDocument();
    d2.put("lt", 20);
    n.put("a", Arrays.asList(d1, d2));
    d.put("n", n);
    String id = mongoDbStorage.createDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, d);
    final DataFilter documentIdFilter = mongoDbStorageDialect.documentIdFilter(id);
    DataDocument fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(2);
    DataDocument d3 = new DataDocument();
    d3.put("equals", "true");
    mongoDbStorage.addItemToArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", d3);
    fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(3);
    DataDocument d4 = new DataDocument();
    d4.put("i", true);
    DataDocument d5 = new DataDocument();
    d4.put("p", 12.3);
    mongoDbStorage.addItemsToArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", Arrays.asList(d4, d5));
    fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(5);
    mongoDbStorage.removeItemsFromArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", Arrays.asList(d2, d3));
    fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(3);
    mongoDbStorage.removeItemFromArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", d2);
    fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(3);
    mongoDbStorage.removeItemFromArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", d4);
    fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
    assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(2);
}
Also used : DataFilter(io.lumeer.engine.api.data.DataFilter) DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 63 with DataDocument

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

the class MongoDbStorageTest method testAggregate.

public void testAggregate() {
    mongoDbStorage.createCollection(COLLECTION_AGGREGATE);
    mongoDbStorage.createDocument(COLLECTION_AGGREGATE, getTestDocument("a", "1", "val1"));
    mongoDbStorage.createDocument(COLLECTION_AGGREGATE, getTestDocument("a", "2", "val2"));
    mongoDbStorage.createDocument(COLLECTION_AGGREGATE, getTestDocument("a", "3", "val3"));
    mongoDbStorage.createDocument(COLLECTION_AGGREGATE, getTestDocument("a", "4", "val6"));
    mongoDbStorage.createDocument(COLLECTION_AGGREGATE, getTestDocument("b", "1", "val4"));
    mongoDbStorage.createDocument(COLLECTION_AGGREGATE, getTestDocument("c", "1", "val5"));
    final DataDocument filters = new DataDocument();
    final DataDocument condition = new DataDocument();
    condition.put("$gt", 2);
    filters.put("param2", condition);
    final DataDocument grouping = new DataDocument();
    final DataDocument groupId = new DataDocument();
    final DataDocument aggregate = new DataDocument();
    groupId.put("param1", "$param1");
    aggregate.put("$sum", "$param2");
    grouping.put("_id", groupId);
    grouping.put("added", aggregate);
    final Query q = new Query(filters);
    q.setGrouping(grouping);
    q.setCollections(Collections.singleton(COLLECTION_AGGREGATE));
    List<DataDocument> result = mongoDbStorage.query(q);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getDataDocument("_id")).containsOnlyKeys("param1");
    assertThat(result.get(0).getString("_id.param1")).isEqualTo("a");
    assertThat(result.get(0).get("added")).isEqualTo(7);
    final DataDocument project = new DataDocument();
    final DataDocument multiply = new DataDocument();
    multiply.put("$multiply", Arrays.asList("$param2", 5));
    project.put("param4", multiply);
    final DataDocument sort = new DataDocument();
    sort.put("param4", -1);
    q.setGrouping(new DataDocument());
    q.setProjections(project);
    q.setSorting(sort);
    result = mongoDbStorage.query(q);
    assertThat(result).hasSize(2);
    assertThat(result.get(0).get("param4")).isEqualTo(20);
    assertThat(result.get(1).get("param4")).isEqualTo(15);
    q.setSkip(1);
    result = mongoDbStorage.query(q);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).get("param4")).isEqualTo(15);
    q.setSkip(0);
    q.setLimit(1);
    result = mongoDbStorage.query(q);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).get("param4")).isEqualTo(20);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Query(io.lumeer.engine.api.data.Query)

Example 64 with DataDocument

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

the class MongoDbStorageTest method dataStatsTest.

@Test
public void dataStatsTest() {
    mongoDbStorage.createCollection(COLLECTION_STATS);
    mongoDbStorage.createDocument(COLLECTION_STATS, new DataDocument("stats", 4));
    mongoDbStorage.createIndex(COLLECTION_STATS, new DataDocument("stats", 1), false);
    final DataStorageStats dss = mongoDbStorage.getDbStats();
    assertThat(dss.getDatabaseName()).isEqualTo(EmbeddedMongoDb.NAME);
    assertThat(dss.getCollections()).isGreaterThan(0);
    assertThat(dss.getDocuments()).isGreaterThan(0);
    assertThat(dss.getIndexes()).isGreaterThan(0);
    assertThat(dss.getDataSize()).isGreaterThan(0);
    assertThat(dss.getStorageSize()).isGreaterThan(0);
    assertThat(dss.getIndexSize()).isGreaterThan(0);
    mongoDbStorage.dropCollection(COLLECTION_STATS);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) DataStorageStats(io.lumeer.engine.api.data.DataStorageStats) Test(org.junit.Test)

Example 65 with DataDocument

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

the class MongoDbStorageTest method createDummyDocument.

private DataDocument createDummyDocument() {
    DataDocument dataDocument = new DataDocument();
    dataDocument.put(DUMMY_KEY1, DUMMY_VALUE1);
    dataDocument.put(DUMMY_KEY2, DUMMY_VALUE2);
    return dataDocument;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument)

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