use of org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadResponse in project kie-wb-common by kiegroup.
the class UploadedDocumentServiceImplTest method testSuccessfullyUpload.
@Test
public void testSuccessfullyUpload() {
DocumentUploadChunk chunk1 = new DocumentUploadChunk(DOC_ID, DOC_NAME, 0, 3, Base64.getEncoder().encodeToString(PART_1.getBytes()));
DocumentUploadResponse response = uploadedDocumentService.uploadContent(chunk1);
validateResponse(response, DocumentUploadResponse.DocumentUploadState.UPLOADING, true);
DocumentUploadSession session = uploadedDocumentService.getUploadSessions().get(DOC_ID);
Assertions.assertThat(session).isNotNull();
Assertions.assertThat(session.getChunks()).isNotNull().hasSize(1).containsExactly(chunk1);
checkParts(1);
DocumentUploadChunk chunk2 = new DocumentUploadChunk(DOC_ID, DOC_NAME, 1, 3, Base64.getEncoder().encodeToString(PART_2.getBytes()));
response = uploadedDocumentService.uploadContent(chunk2);
validateResponse(response, DocumentUploadResponse.DocumentUploadState.UPLOADING, true);
session = uploadedDocumentService.getUploadSessions().get(DOC_ID);
Assertions.assertThat(session).isNotNull();
Assertions.assertThat(session.getChunks()).isNotNull().hasSize(2).containsExactly(chunk1, chunk2);
checkParts(2);
DocumentUploadChunk chunk3 = new DocumentUploadChunk(DOC_ID, DOC_NAME, 3, 3, Base64.getEncoder().encodeToString(PART_3.getBytes()));
response = uploadedDocumentService.uploadContent(chunk3);
validateResponse(response, DocumentUploadResponse.DocumentUploadState.FINISH, true);
session = uploadedDocumentService.getUploadSessions().get(DOC_ID);
Assertions.assertThat(session).isNull();
File file = storage.getRootFolder().resolve(DOC_ID).resolve(DOC_NAME).toFile();
Assertions.assertThat(file).isNotNull().exists();
String content = new String(storage.getContent(DOC_ID));
Assertions.assertThat(content).isNotNull().isEqualTo(PART_1 + PART_2 + PART_3);
}
use of org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadResponse in project kie-wb-common by kiegroup.
the class UploadedDocumentServiceImpl method merge.
private DocumentUploadResponse merge(DocumentUploadSession session) {
try {
session.setState(DocumentUploadSession.State.MERGING);
storage.merge(session);
uploadSessions.remove(session.getDocumentId());
return new DocumentUploadResponse(DocumentUploadResponse.DocumentUploadState.FINISH, true);
} catch (Exception ex) {
logger.warn("Error uploading content: ", ex);
return new DocumentUploadResponse(DocumentUploadResponse.DocumentUploadState.FINISH, false);
}
}
use of org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadResponse in project kie-wb-common by kiegroup.
the class UploadedDocumentServiceImplTest method testUploadWithError.
@Test
public void testUploadWithError() throws Exception {
doThrow(new RuntimeException("Exception")).when(storage).uploadContentChunk(any());
DocumentUploadChunk chunk = new DocumentUploadChunk(DOC_ID, DOC_NAME, 0, 3, Base64.getEncoder().encodeToString(PART_1.getBytes()));
DocumentUploadResponse response = uploadedDocumentService.uploadContent(chunk);
validateResponse(response, DocumentUploadResponse.DocumentUploadState.FINISH, false);
}
use of org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadResponse in project kie-wb-common by kiegroup.
the class UploadedDocumentServiceImplTest method testMergeWithError.
@Test
public void testMergeWithError() throws Exception {
doThrow(new RuntimeException("Exception")).when(storage).merge(any());
DocumentUploadChunk chunk = new DocumentUploadChunk(DOC_ID, DOC_NAME, 0, 1, Base64.getEncoder().encodeToString(PART_1.getBytes()));
DocumentUploadResponse response = uploadedDocumentService.uploadContent(chunk);
validateResponse(response, DocumentUploadResponse.DocumentUploadState.FINISH, false);
}
use of org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadResponse in project kie-wb-common by kiegroup.
the class UploadedDocumentServiceImplTest method testAbortUpload.
@Test
public void testAbortUpload() {
DocumentUploadChunk chunk = new DocumentUploadChunk(DOC_ID, DOC_NAME, 0, 3, Base64.getEncoder().encodeToString(PART_1.getBytes()));
DocumentUploadResponse response = uploadedDocumentService.uploadContent(chunk);
validateResponse(response, DocumentUploadResponse.DocumentUploadState.UPLOADING, true);
DocumentUploadSession session = uploadedDocumentService.getUploadSessions().get(DOC_ID);
Assertions.assertThat(session).isNotNull();
Assertions.assertThat(session.getChunks()).isNotNull().hasSize(1).containsExactly(chunk);
checkParts(1);
uploadedDocumentService.removeContent(DOC_ID);
assertEquals(DocumentUploadSession.State.ABORTED, session.getState());
}
Aggregations