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