Search in sources :

Example 71 with Collection

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

the class CollectionFacadeIT method createCollection.

private Collection createCollection(String code, Attribute attribute) {
    Collection collection = prepareCollection(code);
    collection.getPermissions().updateUserPermissions(USER_PERMISSION);
    collection.getPermissions().updateGroupPermissions(GROUP_PERMISSION);
    collection.updateAttribute(attribute.getFullName(), attribute);
    return collectionDao.createCollection(collection);
}
Also used : JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection)

Example 72 with Collection

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

the class CollectionFacadeIT method testCreateCollection.

@Test
public void testCreateCollection() {
    Collection collection = prepareCollection(CODE);
    Collection returnedCollection = collectionFacade.createCollection(collection);
    assertThat(returnedCollection).isNotNull();
    assertThat(returnedCollection.getId()).isNotNull();
    Collection storedCollection = collectionDao.getCollectionByCode(CODE);
    assertThat(storedCollection).isNotNull();
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(storedCollection.getCode()).isEqualTo(CODE);
    assertions.assertThat(storedCollection.getName()).isEqualTo(NAME);
    assertions.assertThat(storedCollection.getColor()).isEqualTo(COLOR);
    assertions.assertThat(storedCollection.getIcon()).isEqualTo(ICON);
    assertions.assertThat(storedCollection.getPermissions().getUserPermissions()).containsOnly(USER_PERMISSION);
    assertions.assertThat(storedCollection.getPermissions().getGroupPermissions()).isEmpty();
    assertions.assertAll();
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Example 73 with Collection

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

the class CollectionFacadeIT method testGetCollection.

@Test
public void testGetCollection() {
    String collectionId = createCollection(CODE).getId();
    Collection storedCollection = collectionFacade.getCollection(collectionId);
    assertThat(storedCollection).isNotNull();
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(storedCollection.getCode()).isEqualTo(CODE);
    assertions.assertThat(storedCollection.getName()).isEqualTo(NAME);
    assertions.assertThat(storedCollection.getColor()).isEqualTo(COLOR);
    assertions.assertThat(storedCollection.getIcon()).isEqualTo(ICON);
    assertions.assertThat(storedCollection.getPermissions().getGroupPermissions()).isEmpty();
    assertions.assertAll();
    assertPermissions(storedCollection.getPermissions().getUserPermissions(), USER_PERMISSION);
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Example 74 with Collection

use of io.lumeer.api.model.Collection 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)

Example 75 with Collection

use of io.lumeer.api.model.Collection 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)

Aggregations

Collection (io.lumeer.api.model.Collection)77 Test (org.junit.Test)47 JsonCollection (io.lumeer.api.dto.JsonCollection)34 DataDocument (io.lumeer.engine.api.data.DataDocument)17 MorphiaCollection (io.lumeer.storage.mongodb.model.MorphiaCollection)17 SearchQuery (io.lumeer.storage.api.query.SearchQuery)14 SoftAssertions (org.assertj.core.api.SoftAssertions)12 Document (io.lumeer.api.model.Document)8 ImportedCollection (io.lumeer.api.model.ImportedCollection)8 SuggestionQuery (io.lumeer.storage.api.query.SuggestionQuery)8 Response (javax.ws.rs.core.Response)8 JsonAttribute (io.lumeer.api.dto.JsonAttribute)7 Attribute (io.lumeer.api.model.Attribute)7 HashSet (java.util.HashSet)6 JsonQuery (io.lumeer.api.dto.JsonQuery)5 LocalDateTime (java.time.LocalDateTime)4 List (java.util.List)4 JsonDocument (io.lumeer.api.dto.JsonDocument)3 LinkType (io.lumeer.api.model.LinkType)3 CollectionDao (io.lumeer.storage.api.dao.CollectionDao)3