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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations