use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class CollectionFacadeIT method testUpdateCollectionAttributeUpdate.
@Test
public void testUpdateCollectionAttributeUpdate() {
JsonAttribute attribute = new JsonAttribute(ATTRIBUTE_NAME, ATTRIBUTE_FULLNAME, ATTRIBUTE_CONSTRAINTS, ATTRIBUTE_COUNT);
Collection collection = createCollection(CODE, attribute);
assertThat(collection.getAttributes()).isNotEmpty();
JsonAttribute updatedAttribute = new JsonAttribute(ATTRIBUTE_NAME, ATTRIBUTE_FULLNAME2, ATTRIBUTE_CONSTRAINTS, ATTRIBUTE_COUNT);
collectionFacade.updateCollectionAttribute(collection.getId(), ATTRIBUTE_FULLNAME, updatedAttribute);
collection = collectionDao.getCollectionByCode(CODE);
assertThat(collection).isNotNull();
assertThat(collection.getAttributes()).hasSize(1);
Attribute storedAttribute = collection.getAttributes().iterator().next();
SoftAssertions assertions = new SoftAssertions();
assertions.assertThat(storedAttribute.getName()).isEqualTo(ATTRIBUTE_NAME);
assertions.assertThat(storedAttribute.getFullName()).isEqualTo(ATTRIBUTE_FULLNAME2);
assertions.assertThat(storedAttribute.getConstraints()).isEqualTo(ATTRIBUTE_CONSTRAINTS);
assertions.assertThat(storedAttribute.getUsageCount()).isEqualTo(ATTRIBUTE_COUNT);
assertions.assertAll();
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class CollectionFacadeIT method createCollection.
private Collection createCollection(String code, String name) {
Collection collection = prepareCollection(code, name);
collection.getPermissions().updateUserPermissions(USER_PERMISSION);
collection.getPermissions().updateGroupPermissions(GROUP_PERMISSION);
return collectionDao.createCollection(collection);
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class CollectionFacadeIT method testUpdateCollection.
@Test
public void testUpdateCollection() {
String collectionId = createCollection(CODE).getId();
Collection updatedCollection = prepareCollection(CODE2);
updatedCollection.getPermissions().removeUserPermission(USER);
collectionFacade.updateCollection(collectionId, updatedCollection);
Collection storedCollection = collectionDao.getCollectionByCode(CODE2);
assertThat(storedCollection).isNotNull();
assertThat(storedCollection.getName()).isEqualTo(NAME);
assertThat(storedCollection.getPermissions().getUserPermissions()).containsOnly(USER_PERMISSION);
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class DocumentFacadeIT method testDeleteDocument.
@Test
public void testDeleteDocument() {
String id = createDocument().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);
documentFacade.deleteDocument(collection.getId(), id);
assertThatThrownBy(() -> documentDao.getDocumentById(id)).isInstanceOf(ResourceNotFoundException.class);
assertThatThrownBy(() -> dataDao.getData(collection.getId(), id)).isInstanceOf(ResourceNotFoundException.class);
storedCollection = collectionDao.getCollectionById(collection.getId());
assertThat(storedCollection.getDocumentsCount()).isEqualTo(0);
assertThat(storedCollection.getAttributes()).extracting(Attribute::getFullName).containsOnly(KEY1, KEY2);
assertThat(findCollectionAttribute(storedCollection, KEY1).getUsageCount()).isEqualTo(0);
assertThat(findCollectionAttribute(storedCollection, KEY2).getUsageCount()).isEqualTo(0);
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class DocumentFacadeIT method testPatchDocumentData.
@Test
public void testPatchDocumentData() {
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.patchDocumentData(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).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);
}
Aggregations