Java Code Examples for org.drools.core.process.instance.impl.WorkItemImpl#setParameter()

The following examples show how to use org.drools.core.process.instance.impl.WorkItemImpl#setParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RiotWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetLastMatchInfo() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("SummonerName",
                          "testSummonerName");

    LastSummonerMatchWorkitemHandler handler = new LastSummonerMatchWorkitemHandler("testApiKey");

    handler.setRiotAuth(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("LastMatch") instanceof MatchReference);

    MatchReference matchReference = (MatchReference) manager.getResults().get(workItem.getId()).get("LastMatch");
    assertNotNull(matchReference);
    assertEquals(11111L,
                 matchReference.getGameId());
}
 
Example 2
Source File: JiraWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveIssue() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("IssueKey",
                          "testIssueKey");
    workItem.setParameter("Resolution",
                          "testResolved");
    workItem.setParameter("ResolutionComment",
                          "testResolutionComment");

    ResolveIssueWorkitemHandler handler = new ResolveIssueWorkitemHandler("testusername",
                                                                          "testpassword",
                                                                          "testjiraurl");
    handler.setAuth(auth);

    handler.executeWorkItem(workItem,
                            manager);

    assertNotNull(manager.getResults());
    assertEquals(1,
                 manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));
}
 
Example 3
Source File: TwitterWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendDirectMessage() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Message",
                          "hello there");
    workItem.setParameter("ScreenName",
                          "testScreenName");

    SendDirectMessageWorkitemHandler handler = new SendDirectMessageWorkitemHandler("testConsumerKey",
                                                                                    "testConsumerSecret",
                                                                                    "testAccessKey",
                                                                                    "testAccessSecret");
    handler.setAuth(auth);

    handler.executeWorkItem(workItem,
                            manager);
    assertNotNull(manager.getResults());
    assertEquals(1,
                 manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));
}
 
Example 4
Source File: ExecuteSqlWorkItemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoResults() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("SQLStatement",
                          "select * from Person where id = 100");
    ExecuteSqlWorkItemHandler handler = new ExecuteSqlWorkItemHandler(DS_NAME);
    handler.executeWorkItem(workItem,
                            manager);
    assertNotNull(manager.getResults());
    assertEquals(1,
                 manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));

    List<String> resultLines = (List<String>) manager.getResults().get(workItem.getId()).get("Result");
    assertNotNull(resultLines);
    assertEquals(0,
                 resultLines.size());
}
 
Example 5
Source File: GithubWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testForkRepository() throws Exception {

    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("RepoOwner",
                          "testRepoOwner");
    workItem.setParameter("RepoName",
                          "testRepoName");
    workItem.setParameter("Organization",
                          "testOrganization");

    ForkRepositoryWorkitemHandler handler = new ForkRepositoryWorkitemHandler("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("ForkedRepoInfo") instanceof RepositoryInfo);
}
 
Example 6
Source File: ExecuteSqlWorkItemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("SQLStatement",
                          "update Person set age=4 where id = 3");
    ExecuteSqlWorkItemHandler handler = new ExecuteSqlWorkItemHandler(DS_NAME);
    handler.executeWorkItem(workItem,manager);
    assertNotNull(manager.getResults());
    assertEquals(1,manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));

    int changes = (int) manager.getResults().get(workItem.getId()).get("Result");
    assertEquals(1,changes);

}
 
Example 7
Source File: ParserWorkItemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testXmlToObject() {
    WorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter(ParserWorkItemHandler.INPUT,
                          PERSON_XML);
    workItem.setParameter(ParserWorkItemHandler.FORMAT,
                          ParserWorkItemHandler.XML);
    workItem.setParameter(ParserWorkItemHandler.TYPE,
                          "org.jbpm.process.workitem.parser.Person");
    handler.executeWorkItem(workItem,
                            manager);

    Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
    Person result = (Person) results.get(ParserWorkItemHandler.RESULT);
    assertEquals(AGE,
                 result.getAge());
    assertEquals(NAME,
                 result.getName());
}
 
Example 8
Source File: DockerWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testDockerInspectContainer() throws Exception {

    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("ContainerId",
                          "testContainerId");

    InspectContainerWorkitemHandler handler = new InspectContainerWorkitemHandler();
    handler.setDockerClient(dockerClient);

    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("ContainerInfo") instanceof SerializableInspectContainerResponse);
}
 
Example 9
Source File: ParserWorkItemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testObjectToJson() {
    WorkItemManager manager = new TestWorkItemManager();
    Person p = new Person(NAME,
                          AGE);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter(ParserWorkItemHandler.INPUT,
                          p);
    workItem.setParameter(ParserWorkItemHandler.FORMAT,
                          ParserWorkItemHandler.JSON);
    handler.executeWorkItem(workItem,
                            manager);
    Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
    String result = (String) results.get(ParserWorkItemHandler.RESULT);
    assertEquals(PERSON_JSON,
                 result);
}
 
Example 10
Source File: ArchiveWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoFilesSpecified() {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Archive",
                          "testfile.txt");
    workItem.setParameter("Files",
                          new ArrayList<File>());

    ArchiveWorkItemHandler archiveWorkItemHandler = new ArchiveWorkItemHandler();
    archiveWorkItemHandler.setLogThrownException(true);
    archiveWorkItemHandler.executeWorkItem(workItem,
                                           manager);

    assertEquals(1,
                 manager.getAbortedWorkItems().size());
    assertTrue(manager.getAbortedWorkItems().contains(workItem.getId()));
}
 
Example 11
Source File: WatsonWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 12
Source File: IFTTTWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendTriggerRequest() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();

    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Trigger",
                          "testTrigger");
    workItem.setParameter("Value1",
                          "testValue1");
    workItem.setParameter("Value2",
                          "testValue2");
    workItem.setParameter("Value3",
                          "testValue3");

    IFTTTWorkitemHandler handler = new IFTTTWorkitemHandler("testKey");
    handler.setClient(client);
    handler.executeWorkItem(workItem,
                            manager);

    assertNotNull(manager.getResults());
    assertEquals(1,
                 manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));

    String testValueJSONString = "{\"value1\":\"testValue1\",\"value2\":\"testValue2\",\"value3\":\"testValue3\"}";
    assertEquals(testValueJSONString,
                 handler.getRequestBody());
}
 
Example 13
Source File: OktaWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetUsers() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("UserIds",
                          "testUserId1,testUserId2");

    GetUsersWorkitemHandler handler = new GetUsersWorkitemHandler(oktaClient);
    handler.setLogThrownException(true);
    handler.executeWorkItem(workItem,
                            manager);
    assertNotNull(manager.getResults());
}
 
Example 14
Source File: ArchiveWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTempFile() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setId(123L);

    File tempFile = tempFolder.newFile("tempFile1.txt");
    FileUtils.writeStringToFile(tempFile,
                                "temp file content",
                                "UTF-8");
    File tempFileTwo = tempFolder.newFile("tempFile2.txt");
    FileUtils.writeStringToFile(tempFileTwo,
                                "temp file2 content",
                                "UTF-8");

    List<java.io.File> filesList = new ArrayList<>();
    filesList.add(tempFile);
    filesList.add(tempFileTwo);

    workItem.setParameter("Archive",
                          "testfile.txt");
    workItem.setParameter("Files",
                          filesList);

    ArchiveWorkItemHandler archiveWorkItemHandler = new ArchiveWorkItemHandler();
    archiveWorkItemHandler.setLogThrownException(true);
    archiveWorkItemHandler.executeWorkItem(workItem,
                                           manager);

    assertNotNull(manager.getResults());
    assertEquals(1,
                 manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));
}
 
Example 15
Source File: GoogleMapsWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Test
public void testSpeedLimits() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("PlaceIds",
                          "id1,id2,id3,id4");

    SpeedLimitsWorkitemHandler handler = new SpeedLimitsWorkitemHandler(context);
    handler.setLogThrownException(true);
    handler.executeWorkItem(workItem,
                            manager);
    assertNotNull(manager.getResults());
}
 
Example 16
Source File: GoogleSheetsWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadSheetValues() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("SheetId",
                          "testSheetId");
    workItem.setParameter("Range",
                          "Class Data!A2:E");

    ReadSheetValuesWorkitemHandler handler = new ReadSheetValuesWorkitemHandler("testAppName",
                                                                                "{}");
    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("SheetValues") instanceof List);

    List<List<Object>> returnValues = (List<List<Object>>) (manager.getResults().get(workItem.getId())).get("SheetValues");
    assertNotNull(returnValues);
    assertEquals("testValueOne",
                 returnValues.get(0).get(0));
    assertEquals("testValueTwo",
                 returnValues.get(0).get(1));
}
 
Example 17
Source File: GoogleMapsWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Test
public void testDirections() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Origin",
                          "Atlanta");
    workItem.setParameter("Destination",
                          "Dallas");

    DirectionsWorkitemHandler handler = new DirectionsWorkitemHandler(context);
    handler.setLogThrownException(true);
    handler.executeWorkItem(workItem,
                            manager);
    assertNotNull(manager.getResults());
}
 
Example 18
Source File: JPAWorkItemHandlerTest.java    From jbpm-work-items with Apache License 2.0 4 votes vote down vote up
@Test
public void queryWithParameterActionTest() throws Exception {
    WorkItemManager manager = new TestWorkItemManager();
    String DESC = "Cheese";
    Product p1 = new Product("Bread",
                             2f);
    Product p2 = new Product("Milk",
                             3f);
    Product p3 = new Product(DESC,
                             5f);
    create(p1);
    create(p2);
    create(p3);

    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter(JPAWorkItemHandler.P_ACTION,
                          JPAWorkItemHandler.QUERY_ACTION);
    Map<String, Object> params = new HashMap<>();
    params.put("desc",
               DESC);
    workItem.setParameter(JPAWorkItemHandler.P_QUERY,
                          "SELECT p FROM Product p where p.description = :desc");
    workItem.setParameter(JPAWorkItemHandler.P_QUERY_PARAMS,
                          params);
    UserTransaction ut = getUserTransaction();
    ut.begin();
    handler.executeWorkItem(workItem,
                            manager);
    ut.commit();
    Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
    @SuppressWarnings("unchecked")
    List<Product> products = (List<Product>) results.get(JPAWorkItemHandler.P_QUERY_RESULTS);
    assertEquals(1,
                 products.size());
    products = getAllProducts();
    assertEquals(3,
                 products.size());
    for (Product product : products) {
        removeProduct(product);
    }
    products = getAllProducts();
    assertEquals(0,
                 products.size());
}
 
Example 19
Source File: MavenEmbedderWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 4 votes vote down vote up
@Test
public void testCleanInstallSimpleProjectSync() {
    TestWorkItemManager manager = new TestWorkItemManager();
    File simpleTestProjectDir = new File("src/test/resources/simple");

    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Goals",
                          "clean install");
    workItem.setParameter("WorkDirectory",
                          simpleTestProjectDir.getAbsolutePath());
    workItem.setParameter("ProjectRoot",
                          simpleTestProjectDir.getAbsolutePath());

    MavenEmbedderWorkItemHandler handler = new MavenEmbedderWorkItemHandler();

    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("MavenResults") instanceof Map);

    Map<String, String> mavenResults = (Map<String, String>) manager.getResults().get(workItem.getId()).get("MavenResults");
    assertNotNull(mavenResults);
    assertEquals("",
                 mavenResults.get("stderr"));

    // make sure the build ran - check the build dirs
    assertTrue(new File("src/test/resources/simple/target").exists());
    assertTrue(new File("src/test/resources/simple/target/classes").exists());

    // execute workitem handler with "clean" goal to clean the test project and check
    workItem.setParameter("Goals",
                          "clean");

    handler.executeWorkItem(workItem,
                            manager);

    assertNotNull(manager.getResults());
    assertEquals(1,
                 manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));

    // make sure the sample maven project was cleaned
    assertFalse(new File("src/test/resources/simple/target").exists());
    assertFalse(new File("src/test/resources/simple/target/classes").exists());
}
 
Example 20
Source File: MavenEmbedderWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 4 votes vote down vote up
@Test
public void testCleanInstallSimpleProjecAsynctWithCLOptions() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    File simpleTestProjectDir = new File("src/test/resources/simple");

    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Goals",
                          "clean install");
    workItem.setParameter("CLOptions",
                          "-DskipTests -X");
    workItem.setParameter("WorkDirectory",
                          simpleTestProjectDir.getAbsolutePath());
    workItem.setParameter("ProjectRoot",
                          simpleTestProjectDir.getAbsolutePath());
    workItem.setParameter("Mode",
                          "async");

    MavenEmbedderWorkItemHandler handler = new MavenEmbedderWorkItemHandler();

    handler.executeWorkItem(workItem,
                            manager);

    Thread.sleep(10000); // wait for async build to complete

    // make sure the build ran - check the build dirs
    assertTrue(new File("src/test/resources/simple/target").exists());
    assertTrue(new File("src/test/resources/simple/target/classes").exists());

    // execute workitem handler with "clean" command to clean the test project and check
    workItem.setParameter("Goals",
                          "clean");

    handler.executeWorkItem(workItem,
                            manager);

    Thread.sleep(10000); // wait for async build to complete

    // make sure the sample maven project was cleaned
    assertFalse(new File("src/test/resources/simple/target").exists());
    assertFalse(new File("src/test/resources/simple/target/classes").exists());
}