Search in sources :

Example 26 with Document

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

the class SearchFacadeIT method testSearchDocumentsByIds.

@Test
public void testSearchDocumentsByIds() {
    String id1 = createDocument(collectionIds.get(0), "doc1").getId();
    String id2 = createDocument(collectionIds.get(0), "doc2").getId();
    String id3 = createDocument(collectionIds.get(1), "doc3").getId();
    String id4 = createDocument(collectionIds.get(1), "doc4").getId();
    String id5 = createDocument(collectionIds.get(2), "doc5").getId();
    String id6 = createDocument(collectionIds.get(2), "doc6").getId();
    List<Document> documents = searchFacade.searchDocuments(new JsonQuery(null, null, new HashSet<>(Arrays.asList(id1, id4, id6))));
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id4, id6);
    documents = searchFacade.searchDocuments(new JsonQuery(null, null, new HashSet<>(Arrays.asList(id2, id3, id4, id5))));
    assertThat(documents).extracting(Document::getId).containsOnly(id2, id3, 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with Document

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

the class DocumentServiceIT method testUpdateDocument.

@Test
public void testUpdateDocument() {
    String id = createDocument().getId();
    DataDocument data = new DataDocument(KEY1, VALUE2);
    Entity entity = Entity.json(data);
    LocalDateTime beforeUpdateTime = LocalDateTime.now();
    Response response = client.target(DOCUMENTS_URL_PREFIX).path(collection.getId()).path("documents").path(id).path("data").request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    Document storedDocument = documentDao.getDocumentById(id);
    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()).isBeforeOrEqualTo(beforeUpdateTime);
    assertions.assertThat(storedDocument.getUpdatedBy()).isEqualTo(USER);
    assertions.assertThat(storedDocument.getUpdateDate()).isAfterOrEqualTo(beforeUpdateTime).isBeforeOrEqualTo(LocalDateTime.now());
    assertions.assertThat(storedDocument.getDataVersion()).isEqualTo(2);
    assertions.assertThat(storedDocument.getData()).isNull();
    assertions.assertAll();
    DataDocument storedData = dataDao.getData(collection.getId(), id);
    assertThat(storedData).isNotNull();
    assertThat(storedData).containsEntry(KEY1, VALUE2);
    assertThat(storedData).doesNotContainKey(KEY2);
}
Also used : LocalDateTime(java.time.LocalDateTime) Response(javax.ws.rs.core.Response) DataDocument(io.lumeer.engine.api.data.DataDocument) Entity(javax.ws.rs.client.Entity) SoftAssertions(org.assertj.core.api.SoftAssertions) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 28 with Document

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

the class DocumentServiceIT method testPatchDocument.

@Test
public void testPatchDocument() {
    String id = createDocument().getId();
    DataDocument data = new DataDocument(KEY1, VALUE2);
    Entity entity = Entity.json(data);
    LocalDateTime beforeUpdateTime = LocalDateTime.now();
    Response response = client.target(DOCUMENTS_URL_PREFIX).path(collection.getId()).path("documents").path(id).path("data").request(MediaType.APPLICATION_JSON).build("PATCH", entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    Document storedDocument = documentDao.getDocumentById(id);
    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()).isBeforeOrEqualTo(beforeUpdateTime);
    assertions.assertThat(storedDocument.getUpdatedBy()).isEqualTo(USER);
    assertions.assertThat(storedDocument.getUpdateDate()).isAfterOrEqualTo(beforeUpdateTime).isBeforeOrEqualTo(LocalDateTime.now());
    assertions.assertThat(storedDocument.getDataVersion()).isEqualTo(2);
    assertions.assertThat(storedDocument.getData()).isNull();
    assertions.assertAll();
    DataDocument storedData = dataDao.getData(collection.getId(), id);
    assertThat(storedData).isNotNull();
    assertThat(storedData).containsEntry(KEY1, VALUE2);
    assertThat(storedData).containsEntry(KEY2, VALUE2);
}
Also used : LocalDateTime(java.time.LocalDateTime) Response(javax.ws.rs.core.Response) DataDocument(io.lumeer.engine.api.data.DataDocument) Entity(javax.ws.rs.client.Entity) SoftAssertions(org.assertj.core.api.SoftAssertions) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 29 with Document

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

the class DocumentServiceIT method testCreateDocument.

@Test
public void testCreateDocument() {
    Document document = prepareDocument();
    Entity entity = Entity.json(document);
    LocalDateTime beforeTime = LocalDateTime.now();
    Response response = client.target(DOCUMENTS_URL_PREFIX).path(collection.getId()).path("documents").request(MediaType.APPLICATION_JSON).buildPost(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.CREATED);
    assertThat(response.getLocation().getPath()).startsWith(DOCUMENTS_PATH_PREFIX);
    String[] path = response.getLocation().getPath().split("/");
    String id = path[path.length - 1];
    assertThat(ObjectId.isValid(id)).isTrue();
    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);
}
Also used : LocalDateTime(java.time.LocalDateTime) Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) DataDocument(io.lumeer.engine.api.data.DataDocument) SoftAssertions(org.assertj.core.api.SoftAssertions) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 30 with Document

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

the class DocumentFacadeIT method testUpdateDocumentData.

@Test
public void testUpdateDocumentData() {
    Document document = createDocument();
    String id = document.getId();
    Collection 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);
    DataDocument data = new DataDocument(KEY1, VALUE2);
    LocalDateTime beforeUpdateTime = LocalDateTime.now();
    Document updatedDocument = documentFacade.updateDocumentData(collection.getId(), id, data);
    assertThat(updatedDocument).isNotNull();
    Document storedDocument = documentDao.getDocumentById(id);
    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()).isBeforeOrEqualTo(beforeUpdateTime);
    assertions.assertThat(storedDocument.getUpdatedBy()).isEqualTo(USER);
    assertions.assertThat(storedDocument.getUpdateDate()).isAfterOrEqualTo(beforeUpdateTime).isBeforeOrEqualTo(LocalDateTime.now());
    assertions.assertThat(storedDocument.getDataVersion()).isEqualTo(2);
    assertions.assertThat(storedDocument.getData()).isNull();
    assertions.assertAll();
    DataDocument storedData = dataDao.getData(collection.getId(), id);
    assertThat(storedData).isNotNull();
    assertThat(storedData).containsEntry(KEY1, VALUE2);
    assertThat(storedData).doesNotContainKey(KEY2);
    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(0);
}
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)

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