use of org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateActionsHandler in project kie-wb-common by kiegroup.
the class DocumentUploadTest method testDrop.
@Test
public void testDrop() {
Document doc = mock(Document.class);
when(doc.getId()).thenReturn(DOC_1);
when(doc.getName()).thenReturn(DOC_1);
when(doc.getSize()).thenReturn(1024);
when(doc.getLastModified()).thenReturn((double) System.currentTimeMillis());
File file = mock(File.class);
documentUpload.doUpload(doc, file);
verify(instance).get();
verify(view).addDocument(any());
List<DocumentPreview> previews = (List<DocumentPreview>) documentUpload.getCurrentPreviews();
Assertions.assertThat(previews).isNotNull().hasSize(1);
ArgumentCaptor<DocumentData> documentDataArgumentCaptor = ArgumentCaptor.forClass(DocumentData.class);
DocumentPreview preview = previews.get(0);
verify(preview).init(documentDataArgumentCaptor.capture());
DocumentData documentData = documentDataArgumentCaptor.getValue();
Assertions.assertThat(documentData).isNotNull().hasFieldOrPropertyWithValue("contentId", DOC_1).hasFieldOrPropertyWithValue("fileName", DOC_1).hasFieldOrPropertyWithValue("size", Long.valueOf(1024));
ArgumentCaptor<DocumentPreviewStateActionsHandler> handlerCaptor = ArgumentCaptor.forClass(DocumentPreviewStateActionsHandler.class);
verify(preview).setStateHandler(handlerCaptor.capture());
DocumentPreviewStateActionsHandler handler = handlerCaptor.getValue();
ArgumentCaptor<Command> startUploadCaptor = ArgumentCaptor.forClass(Command.class);
ArgumentCaptor<ParameterizedCommand> uploadResultCaptor = ArgumentCaptor.forClass(ParameterizedCommand.class);
verify(uploader).upload(eq(DOC_1), any(), startUploadCaptor.capture(), uploadResultCaptor.capture());
startUploadCaptor.getValue().execute();
verify(preview).setState(DocumentPreviewState.UPLOADING);
uploadResultCaptor.getValue().execute(false);
verify(preview).setState(DocumentPreviewState.ERROR);
DocumentPreviewStateAction action = ((List<DocumentPreviewStateAction>) handler.getCurrentStateActions()).get(1);
action.execute();
verify(uploader).remove(eq(DOC_1), any());
uploadResultCaptor.getValue().execute(true);
verify(preview).setState(DocumentPreviewState.UPLOADED);
}
Aggregations