use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDaoTest method testCreateDocumentMultiple.
@Test
public void testCreateDocumentMultiple() {
Document document = prepareDocument();
String id = documentDao.createDocument(document).getId();
assertThat(id).isNotNull().isNotEmpty();
assertThat(ObjectId.isValid(id)).isTrue();
Document document2 = new MorphiaDocument();
String id2 = documentDao.createDocument(document2).getId();
assertThat(id2).isNotNull().isNotEmpty();
assertThat(ObjectId.isValid(id2)).isTrue();
assertThat(id).isNotEqualTo(id2);
}
use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDaoTest method createDocument.
private MorphiaDocument createDocument() {
MorphiaDocument document = prepareDocument();
datastore.save(documentDao.databaseCollection(), document);
return document;
}
use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDaoTest method testUpdateDocumentNotExisting.
@Test
@Ignore("Stored anyway with the current implementation")
public void testUpdateDocumentNotExisting() {
MorphiaDocument document = prepareDocument();
assertThatThrownBy(() -> documentDao.updateDocument(DOCUMENT_ID, document)).isInstanceOf(WriteFailedException.class);
}
use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDao method createDocuments.
@Override
public List<Document> createDocuments(final List<Document> documents) {
List<org.bson.Document> bsonDocuments = documents.stream().map(doc -> new MorphiaDocument(doc).toBsonDocument()).collect(Collectors.toList());
database.getCollection(databaseCollection()).insertMany(bsonDocuments);
for (int i = 0; i < documents.size(); i++) {
documents.get(i).setId(bsonDocuments.get(i).getObjectId(ID).toHexString());
}
return documents;
}
use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDao method updateDocument.
@Override
public Document updateDocument(final String id, final Document document) {
MorphiaDocument morphiaDocument = new MorphiaDocument(document);
morphiaDocument.setId(id);
datastore.save(databaseCollection(), morphiaDocument);
return morphiaDocument;
}
Aggregations