use of io.lumeer.engine.api.data.DataDocument 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);
}
use of io.lumeer.engine.api.data.DataDocument 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);
}
use of io.lumeer.engine.api.data.DataDocument 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);
}
use of io.lumeer.engine.api.data.DataDocument 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);
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class ImportFacadeIT method testImportEmptyCSV.
@Test
public void testImportEmptyCSV() {
final String emptyCSV = "";
ImportedCollection importedCollection = createImportObject(emptyCSV);
Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
assertThat(collection).isNotNull();
List<DataDocument> data = dataDao.getData(collection.getId(), query());
assertThat(data).isEmpty();
}
Aggregations