Search in sources :

Example 31 with Document

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

the class DocumentFacadeIT method testCreateDocument.

@Test
public void testCreateDocument() {
    Collection storedCollection = collectionDao.getCollectionById(collection.getId());
    assertThat(storedCollection.getDocumentsCount()).isEqualTo(0);
    assertThat(storedCollection.getAttributes()).extracting(Attribute::getFullName).isEmpty();
    Document document = prepareDocument();
    LocalDateTime beforeTime = LocalDateTime.now();
    String id = documentFacade.createDocument(collection.getId(), document).getId();
    assertThat(id).isNotNull();
    Document storedDocument = documentDao.getDocumentById(id);
    assertThat(storedDocument).isNotNull();
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(storedDocument.getId()).isEqualTo(id);
    assertions.assertThat(storedDocument.getCollectionId()).isEqualTo(collection.getId());
    assertions.assertThat(storedDocument.getCreatedBy()).isEqualTo(USER);
    assertions.assertThat(storedDocument.getCreationDate()).isAfterOrEqualTo(beforeTime).isBeforeOrEqualTo(LocalDateTime.now());
    assertions.assertThat(storedDocument.getUpdatedBy()).isNull();
    assertions.assertThat(storedDocument.getUpdateDate()).isNull();
    assertions.assertThat(storedDocument.getDataVersion()).isEqualTo(1);
    assertions.assertThat(storedDocument.getData()).isNull();
    assertions.assertAll();
    DataDocument storedData = dataDao.getData(collection.getId(), id);
    assertThat(storedData).isNotNull();
    assertThat(storedData).containsEntry(KEY1, VALUE1);
    assertThat(storedData).containsEntry(KEY2, VALUE2);
    storedCollection = collectionDao.getCollectionById(collection.getId());
    assertThat(storedCollection.getDocumentsCount()).isEqualTo(1);
    assertThat(storedCollection.getAttributes()).extracting(Attribute::getFullName).containsOnly(KEY1, KEY2);
    assertThat(findCollectionAttribute(storedCollection, KEY1).getUsageCount()).isEqualTo(1);
    assertThat(findCollectionAttribute(storedCollection, KEY2).getUsageCount()).isEqualTo(1);
}
Also used : LocalDateTime(java.time.LocalDateTime) DataDocument(io.lumeer.engine.api.data.DataDocument) SoftAssertions(org.assertj.core.api.SoftAssertions) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 32 with Document

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

the class DocumentFacadeIT method testGetDocuments.

@Test
public void testGetDocuments() {
    String id1 = createDocument().getId();
    String id2 = createDocument().getId();
    Pagination pagination = new Pagination(null, null);
    List<Document> documents = documentFacade.getDocuments(collection.getId(), pagination);
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id2);
}
Also used : Pagination(io.lumeer.api.model.Pagination) 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