use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDaoTest method testCreateDocumentExisting.
@Test
public void testCreateDocumentExisting() {
MorphiaDocument document = createDocument();
assertThatThrownBy(() -> documentDao.createDocument(document)).isInstanceOf(// TODO change this to our own exception
DuplicateKeyException.class);
}
use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDaoTest method testCreateDocument.
@Test
public void testCreateDocument() {
MorphiaDocument document = prepareDocument();
String id = documentDao.createDocument(document).getId();
assertThat(id).isNotNull().isNotEmpty();
assertThat(ObjectId.isValid(id)).isTrue();
Document storedDocument = datastore.get(documentDao.databaseCollection(), MorphiaDocument.class, new ObjectId(id));
assertThat(storedDocument).isNotNull();
SoftAssertions assertions = new SoftAssertions();
assertions.assertThat(storedDocument.getId()).isEqualTo(id);
assertions.assertThat(storedDocument.getCollectionId()).isEqualTo(COLLECTION_ID);
assertions.assertThat(storedDocument.getCreatedBy()).isEqualTo(CREATED_BY);
assertions.assertThat(storedDocument.getCreationDate()).isEqualTo(CREATION_DATE);
assertions.assertThat(storedDocument.getUpdatedBy()).isNull();
assertions.assertThat(storedDocument.getUpdateDate()).isNull();
assertions.assertThat(storedDocument.getDataVersion()).isEqualTo(DATA_VERSION);
assertions.assertThat(storedDocument.getData()).isNull();
assertions.assertAll();
}
use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDaoTest method prepareDocument.
private MorphiaDocument prepareDocument() {
MorphiaDocument document = new MorphiaDocument();
document.setCollectionId(COLLECTION_ID);
document.setCreationDate(CREATION_DATE);
document.setCreatedBy(CREATED_BY);
document.setDataVersion(DATA_VERSION);
document.setData(new DataDocument("something", "that should not be stored"));
return document;
}
use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDaoTest method testUpdateDocument.
@Test
public void testUpdateDocument() {
MorphiaDocument document = createDocument();
String id = document.getId();
LocalDateTime updateDate = LocalDateTime.now().withNano(0);
document.setDataVersion(DATA_VERSION2);
document.setUpdatedBy(UPDATED_BY);
document.setUpdateDate(updateDate);
documentDao.updateDocument(document.getId(), document);
Document storedDocument = datastore.get(documentDao.databaseCollection(), MorphiaDocument.class, new ObjectId(id));
assertThat(storedDocument).isNotNull();
SoftAssertions assertions = new SoftAssertions();
assertions.assertThat(storedDocument.getId()).isEqualTo(id);
assertions.assertThat(storedDocument.getCollectionId()).isEqualTo(COLLECTION_ID);
assertions.assertThat(storedDocument.getCreatedBy()).isEqualTo(CREATED_BY);
assertions.assertThat(storedDocument.getCreationDate()).isEqualTo(CREATION_DATE);
assertions.assertThat(storedDocument.getUpdatedBy()).isEqualTo(UPDATED_BY);
assertions.assertThat(storedDocument.getUpdateDate()).isEqualTo(updateDate);
assertions.assertThat(storedDocument.getDataVersion()).isEqualTo(DATA_VERSION2);
assertions.assertAll();
}
use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.
the class MorphiaDocumentDao method createDocument.
@Override
public Document createDocument(final Document document) {
MorphiaDocument morphiaDocument = new MorphiaDocument(document);
datastore.insert(databaseCollection(), morphiaDocument);
return morphiaDocument;
}
Aggregations