Search in sources :

Example 11 with DocumentImpl

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());
    }
}
Also used : InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) WriteMode(com.dropbox.core.v2.files.WriteMode) Before(org.junit.Before)

Example 12 with DocumentImpl

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);
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Matchers.anyString(org.mockito.Matchers.anyString) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Example 13 with DocumentImpl

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());
}
Also used : ImageClassificationResult(org.jbpm.process.workitem.ibm.watson.result.ImageClassificationResult) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) ArrayList(java.util.ArrayList) List(java.util.List) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Test(org.junit.Test)

Example 14 with DocumentImpl

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());
}
Also used : FaceDetectionResult(org.jbpm.process.workitem.ibm.watson.result.FaceDetectionResult) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) ArrayList(java.util.ArrayList) List(java.util.List) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Test(org.junit.Test)

Example 15 with DocumentImpl

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());
}
Also used : DocumentData(org.kie.workbench.common.forms.dynamic.model.document.DocumentData) HashMap(java.util.HashMap) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DocumentImpl (org.jbpm.document.service.impl.DocumentImpl)16 Date (java.util.Date)10 Test (org.junit.Test)10 Document (org.jbpm.document.Document)9 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)6 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)6 HashMap (java.util.HashMap)5 Matchers.anyString (org.mockito.Matchers.anyString)5 AbstractBaseTest (org.jbpm.test.AbstractBaseTest)4 InputStream (java.io.InputStream)3 DocumentData (org.kie.workbench.common.forms.dynamic.model.document.DocumentData)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)2 WriteMode (com.dropbox.core.v2.files.WriteMode)1 Drive (com.google.api.services.drive.Drive)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1