use of io.lumeer.engine.api.data.DataFilter in project engine by Lumeer.
the class MongoDbStorageTest method testNestedDocuments.
@Test
public void testNestedDocuments() throws Exception {
mongoDbStorage.createCollection(COLLECTION_NESTED_DOCUMENTS);
DataDocument d = createDummyDocument();
d.put("a", createDummyDocument());
d.put("b", createDummyDocument());
d.put("l", Arrays.asList(1, 2, 3, 4));
d.put("ld", Arrays.asList(createDummyDocument(), createDummyDocument(), createDummyDocument()));
DataDocument doubleNested = createDummyDocument();
doubleNested.put("dn", createDummyDocument());
d.put("c", doubleNested);
DataDocument trippleNested = createDummyDocument();
DataDocument tn = createDummyDocument();
tn.put("tnn", createDummyDocument());
trippleNested.put("tn", tn);
trippleNested.put("ld", Arrays.asList(createDummyDocument(), createDummyDocument(), createDummyDocument()));
d.put("d_d", trippleNested);
String id = mongoDbStorage.createDocument(COLLECTION_NESTED_DOCUMENTS, d);
final DataFilter documentIdFilter = mongoDbStorageDialect.documentIdFilter(id);
mongoDbStorage.dropAttribute(COLLECTION_NESTED_DOCUMENTS, documentIdFilter, "d_d.tn.tnn." + DUMMY_KEY1);
// use debug to see nested hierarchy works
DataDocument nested = mongoDbStorage.readDocument(COLLECTION_NESTED_DOCUMENTS, documentIdFilter);
assertThat(nested).isNotNull();
}
use of io.lumeer.engine.api.data.DataFilter 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();
}
use of io.lumeer.engine.api.data.DataFilter 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);
}
use of io.lumeer.engine.api.data.DataFilter 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);
}
use of io.lumeer.engine.api.data.DataFilter 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();
}
Aggregations