use of org.jbpm.document.service.impl.DocumentImpl in project jbpm-work-items by kiegroup.
the class DropboxWorkitemHandlerTest method setUp.
@Before
public void setUp() {
try {
testDoc = new DocumentImpl();
testDoc.setName("testDoc.txt");
testDoc.setIdentifier("testDoc");
testDoc.setLastModified(new Date());
testDoc.setContent(new String("test doc content").getBytes());
InputStream testInputStream = IOUtils.toInputStream("test doc content", "UTF-8");
when(auth.authorize(anyString(), anyString())).thenReturn(client);
when(client.files()).thenReturn(fileRequests);
// upload
when(fileRequests.uploadBuilder(anyString())).thenReturn(uploadBuilder);
when(uploadBuilder.withMode(any(WriteMode.class))).thenReturn(uploadBuilder);
when(uploadBuilder.withClientModified(any(Date.class))).thenReturn(uploadBuilder);
when(uploadBuilder.uploadAndFinish(any(java.io.InputStream.class))).thenReturn(metaData);
// download
when(fileRequests.downloadBuilder(anyString())).thenReturn(downloadBuilder);
when(downloadBuilder.start()).thenReturn(downloader);
when(downloader.getInputStream()).thenReturn(testInputStream);
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.jbpm.document.service.impl.DocumentImpl in project jbpm-work-items by kiegroup.
the class GithubWorkitemHandlerTest method testCreateGist.
@Test
public void testCreateGist() throws Exception {
DocumentImpl testGistDoc = new org.jbpm.document.service.impl.DocumentImpl();
testGistDoc.setContent(new String("Test gist file content").getBytes());
testGistDoc.setName("testGistFile.txt");
TestWorkItemManager manager = new TestWorkItemManager();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Content", testGistDoc);
workItem.setParameter("Description", "test gist");
workItem.setParameter("IsPublic", "true");
CreateGistWorkitemHandler handler = new CreateGistWorkitemHandler("testusername", "testpassword");
handler.setAuth(auth);
handler.executeWorkItem(workItem, manager);
assertNotNull(manager.getResults());
assertEquals(1, manager.getResults().size());
assertTrue(manager.getResults().containsKey(workItem.getId()));
assertTrue((manager.getResults().get(workItem.getId())).get("GistURL") instanceof String);
String createdGistURL = (String) manager.getResults().get(workItem.getId()).get("GistURL");
assertNotNull(createdGistURL);
assertEquals("testGistURL", createdGistURL);
}
use of org.jbpm.document.service.impl.DocumentImpl in project jbpm-work-items by kiegroup.
the class WatsonWorkitemHandlerTest method testClassifyImage.
@Test
public void testClassifyImage() throws Exception {
when(auth.getService(anyString())).thenReturn(associationService);
TestWorkItemManager manager = new TestWorkItemManager();
DocumentImpl imageToClassify = new DocumentImpl();
imageToClassify.setName("testImageToClassify.png");
imageToClassify.setContent(new String("testImageContent").getBytes());
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("ImageToClassify", imageToClassify);
ClassifyImageWorkitemHandler handler = new ClassifyImageWorkitemHandler("{testApiKey}");
handler.setAuth(auth);
handler.executeWorkItem(workItem, manager);
assertNotNull(manager.getResults());
assertEquals(1, manager.getResults().size());
assertTrue(manager.getResults().containsKey(workItem.getId()));
assertTrue((manager.getResults().get(workItem.getId())).get("Classification") instanceof List);
List<ImageClassificationResult> returnValues = (List<ImageClassificationResult>) (manager.getResults().get(workItem.getId())).get("Classification");
assertNotNull(returnValues);
assertEquals(1, returnValues.size());
ImageClassificationResult result = returnValues.get(0);
assertTrue(result.getClassScore() == 1);
assertEquals("testClassName", result.getClassName());
assertEquals("testTypeHierarchy", result.getClassTypeHierarchy());
}
use of org.jbpm.document.service.impl.DocumentImpl in project jbpm-work-items by kiegroup.
the class WatsonWorkitemHandlerTest method testDetectFaces.
@Test
public void testDetectFaces() throws Exception {
when(auth.getService(anyString())).thenReturn(recognitionService);
TestWorkItemManager manager = new TestWorkItemManager();
DocumentImpl imagetoDetect = new DocumentImpl();
imagetoDetect.setName("testImageToDetect.png");
imagetoDetect.setContent(new String("testImageContent").getBytes());
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("ImageToDetect", imagetoDetect);
DetectFacesWorkitemHandler handler = new DetectFacesWorkitemHandler("{testApiKey}");
handler.setAuth(auth);
handler.executeWorkItem(workItem, manager);
assertNotNull(manager.getResults());
assertEquals(1, manager.getResults().size());
assertTrue(manager.getResults().containsKey(workItem.getId()));
assertTrue((manager.getResults().get(workItem.getId())).get("Detection") instanceof List);
List<FaceDetectionResult> returnValues = (List<FaceDetectionResult>) (manager.getResults().get(workItem.getId())).get("Detection");
assertNotNull(returnValues);
assertEquals(1, returnValues.size());
FaceDetectionResult result = returnValues.get(0);
assertTrue(result.getMinAge() == 20);
assertTrue(result.getMaxAge() == 35);
assertEquals("male", result.getGender());
assertEquals("testPerson", result.getIdentity());
}
use of org.jbpm.document.service.impl.DocumentImpl in project kie-wb-common by kiegroup.
the class DocumentFieldValueProcessorTest method testDocument2FlatValue.
@Test
public void testDocument2FlatValue() {
Document doc = spy(new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date()));
Map result = new HashMap();
result.put(DocumentFieldValueProcessor.SERVER_TEMPLATE_ID, SERVER_TEMPLATE_ID);
when(context.getAttributes()).thenReturn(result);
DocumentData documentData = processor.toFlatValue(field, doc, context);
verify(doc, never()).getLink();
assertNotNull(documentData);
assertEquals(doc.getName(), documentData.getFileName());
assertEquals(doc.getSize(), documentData.getSize());
assertEquals(EXPECTED_DOWNLOAD_LINK, documentData.getLink());
}
Aggregations