use of io.lumeer.engine.api.data.DataDocument 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();
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorageTest method getTestDocument.
private DataDocument getTestDocument(final String... values) {
final DataDocument d = new DataDocument();
for (int i = 0; i < values.length; i++) {
try {
int x = Integer.parseInt(values[i]);
d.put("param" + (i + 1), x);
} catch (NumberFormatException nfe) {
d.put("param" + (i + 1), values[i]);
}
}
return d;
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorageTest method testRun.
@Test
public void testRun() throws Exception {
mongoDbStorage.createCollection(COLLECTION_RUN);
for (int i = 0; i < 200; i++) {
DataDocument insertedDocument = createDummyDocument();
mongoDbStorage.createDocument(COLLECTION_RUN, insertedDocument);
}
// query form: https://docs.mongodb.com/v3.2/reference/command/find/#definition
String query = "{find: \"" + COLLECTION_RUN + "\"}";
List<DataDocument> searchDocuments = mongoDbStorage.run(query);
// run() method returns 101 entries due to it is a default value of "batchSize" query key
assertThat(searchDocuments).hasSize(101);
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorageTest method testSearchAttrs.
@Test
public void testSearchAttrs() throws Exception {
mongoDbStorage.createCollection(COLLECTION_SEARCH_ATTRS);
for (int i = 0; i < 200; i++) {
DataDocument insertedDocument = new DataDocument("a", i).append("b", i * 2).append("c", i * 3).append("d", i + 4).append("e", i + 5).append("f", new DataDocument("a", i).append("b", i - 2).append("c", i * i));
mongoDbStorage.createDocument(COLLECTION_SEARCH_ATTRS, insertedDocument);
}
// test whether we get all documents
List<DataDocument> docs = mongoDbStorage.search(COLLECTION_SEARCH_ATTRS, null, null);
assertThat(docs).hasSize(200);
final DataFilter filter = new MongoDbDataFilter(Filters.gte("a", 100));
docs = mongoDbStorage.search(COLLECTION_SEARCH_ATTRS, filter, Arrays.asList("a", "c", "f.b"));
assertThat(docs).hasSize(100);
DataDocument anyDoc = docs.get(0);
assertThat(anyDoc).containsKeys("_id", "a", "c", "f");
assertThat(anyDoc).doesNotContainKeys("b", "d", "e");
DataDocument nestedDoc = anyDoc.getDataDocument("f");
assertThat(nestedDoc).containsKey("b");
assertThat(nestedDoc).doesNotContainKeys("a", "c");
// test if it's necceserry to include attribute which is used in filter
docs = mongoDbStorage.search(COLLECTION_SEARCH_ATTRS, filter, Arrays.asList("b", "c", "d"));
assertThat(docs).hasSize(100);
anyDoc = docs.get(0);
assertThat(anyDoc).containsKeys("_id", "b", "c", "d");
assertThat(anyDoc).doesNotContainKeys("a", "e", "f");
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorageTest method testSearchWithProjection.
@Test
public void testSearchWithProjection() {
mongoDbStorage.createCollection(COLLECTION_SEARCH_PROJECTION);
for (int i = 0; i < 10; i++) {
DataDocument insertedDocument = createDummyDocument();
mongoDbStorage.createDocument(COLLECTION_SEARCH_PROJECTION, insertedDocument);
}
List<DataDocument> searchDocuments = mongoDbStorage.search(COLLECTION_SEARCH_PROJECTION, null, null, Collections.singletonList(DUMMY_KEY1), 0, 5);
assertThat(searchDocuments).hasSize(5);
assertThat(searchDocuments).extracting(d -> d.getString(DUMMY_KEY2)).containsOnly((String) null);
}
Aggregations