Search in sources :

Example 21 with Document

use of io.lumeer.api.model.Document 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 22 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class MorphiaDocumentDaoTest method testDeleteDocument.

@Test
public void testDeleteDocument() {
    String id = createDocument().getId();
    documentDao.deleteDocument(id);
    Document storedDocument = datastore.get(documentDao.databaseCollection(), MorphiaDocument.class, new ObjectId(id));
    assertThat(storedDocument).isNull();
}
Also used : ObjectId(org.bson.types.ObjectId) 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 23 with Document

use of io.lumeer.api.model.Document 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 24 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class SearchFacadeIT method testSearchDocumentsByCollectionIds.

@Test
public void testSearchDocumentsByCollectionIds() {
    String id1 = createDocument(collectionIds.get(0), "doc1").getId();
    String id2 = createDocument(collectionIds.get(0), "doc2").getId();
    createDocument(collectionIds.get(1), "doc3");
    createDocument(collectionIds.get(1), "doc4");
    String id5 = createDocument(collectionIds.get(2), "doc5").getId();
    String id6 = createDocument(collectionIds.get(2), "doc6").getId();
    List<Document> documents = searchFacade.searchDocuments(new JsonQuery(new HashSet<>(Arrays.asList(collectionIds.get(0), collectionIds.get(2))), null, null));
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id5, id6);
}
Also used : JsonQuery(io.lumeer.api.dto.JsonQuery) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class SearchFacadeIT method testSearchDocumentsByFullText.

@Test
public void testSearchDocumentsByFullText() {
    String id1 = createDocument(collectionIds.get(0), "word").getId();
    String id2 = createDocument(collectionIds.get(0), "fulltext").getId();
    String id3 = createDocument(collectionIds.get(1), "something fulltext").getId();
    String id4 = createDocument(collectionIds.get(1), "some other word").getId();
    String id5 = createDocument(collectionIds.get(2), "full word").getId();
    List<Document> documents = searchFacade.searchDocuments(new JsonQuery("fulltext"));
    assertThat(documents).extracting(Document::getId).containsOnly(id2, id3);
    documents = searchFacade.searchDocuments(new JsonQuery("word"));
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id4, id5);
}
Also used : JsonQuery(io.lumeer.api.dto.JsonQuery) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Aggregations

Document (io.lumeer.api.model.Document)32 DataDocument (io.lumeer.engine.api.data.DataDocument)31 JsonDocument (io.lumeer.api.dto.JsonDocument)21 Test (org.junit.Test)18 SoftAssertions (org.assertj.core.api.SoftAssertions)10 Collection (io.lumeer.api.model.Collection)7 LocalDateTime (java.time.LocalDateTime)7 MorphiaDocument (io.lumeer.storage.mongodb.model.MorphiaDocument)6 JsonQuery (io.lumeer.api.dto.JsonQuery)5 HashSet (java.util.HashSet)4 ObjectId (org.bson.types.ObjectId)4 JsonCollection (io.lumeer.api.dto.JsonCollection)3 Entity (javax.ws.rs.client.Entity)3 Response (javax.ws.rs.core.Response)3 Pagination (io.lumeer.api.model.Pagination)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 WriteResult (com.mongodb.WriteResult)1 CsvParser (com.univocity.parsers.csv.CsvParser)1 CsvParserSettings (com.univocity.parsers.csv.CsvParserSettings)1