Search in sources :

Example 6 with MorphiaDocument

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);
}
Also used : MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) Test(org.junit.Test)

Example 7 with MorphiaDocument

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();
}
Also used : ObjectId(org.bson.types.ObjectId) SoftAssertions(org.assertj.core.api.SoftAssertions) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) Test(org.junit.Test)

Example 8 with MorphiaDocument

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;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument)

Example 9 with MorphiaDocument

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();
}
Also used : LocalDateTime(java.time.LocalDateTime) ObjectId(org.bson.types.ObjectId) SoftAssertions(org.assertj.core.api.SoftAssertions) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) Test(org.junit.Test)

Example 10 with MorphiaDocument

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;
}
Also used : MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument)

Aggregations

MorphiaDocument (io.lumeer.storage.mongodb.model.MorphiaDocument)10 Test (org.junit.Test)5 Document (io.lumeer.api.model.Document)4 DataDocument (io.lumeer.engine.api.data.DataDocument)4 ObjectId (org.bson.types.ObjectId)3 SoftAssertions (org.assertj.core.api.SoftAssertions)2 WriteResult (com.mongodb.WriteResult)1 Project (io.lumeer.api.model.Project)1 ResourceType (io.lumeer.api.model.ResourceType)1 DocumentDao (io.lumeer.storage.api.dao.DocumentDao)1 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)1 WriteFailedException (io.lumeer.storage.mongodb.exception.WriteFailedException)1 ID (io.lumeer.storage.mongodb.model.common.MorphiaEntity.ID)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RequestScoped (javax.enterprise.context.RequestScoped)1 Ignore (org.junit.Ignore)1