use of org.jbpm.process.workitem.core.TestWorkItemManager 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.process.workitem.core.TestWorkItemManager in project jbpm-work-items by kiegroup.
the class IFTTTWorkitemHandlerTest method testSendTriggerRequest.
@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\":\"testValue1\",\"value3\":\"testValue1\"}";
assertEquals(testValueJSONString, handler.getRequestBody());
}
use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm-work-items by kiegroup.
the class JabberWorkItemHandlerTest method testSendMessage.
@Test
public void testSendMessage() throws Exception {
ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
doNothing().when(xmppConnection).connect();
doNothing().when(xmppConnection).login(anyString(), anyString());
doNothing().when(xmppConnection).sendPacket(any(Presence.class));
doNothing().when(xmppConnection).disconnect();
when(xmppConnection.getChatManager()).thenReturn(chatManager);
when(chatManager.createChat(anyString(), anyObject())).thenReturn(chat);
TestWorkItemManager manager = new TestWorkItemManager();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("User", "myuser");
workItem.setParameter("Password", "mypassword");
workItem.setParameter("Server", "myserver");
workItem.setParameter("Port", "123");
workItem.setParameter("Service", "myservice");
workItem.setParameter("Text", "hello world");
workItem.setParameter("To", "someperson");
JabberWorkItemHandler handler = new JabberWorkItemHandler();
handler.setConf(connectionConf);
handler.setConnection(xmppConnection);
handler.executeWorkItem(workItem, manager);
assertNotNull(manager.getResults());
assertEquals(1, manager.getResults().size());
assertTrue(manager.getResults().containsKey(workItem.getId()));
verify(chat).sendMessage(messageCaptor.capture());
assertEquals("hello world", messageCaptor.getValue().getBody());
}
use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.
the class BusinessRuleTaskHandlerTest method testDrlStatefulBusinessRuleTaskWithScanner.
@Ignore("ignored as it is unstable on jenkins for unknown reason")
@Test
public void testDrlStatefulBusinessRuleTaskWithScanner() throws Exception {
TestWorkItemManager manager = new TestWorkItemManager();
BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID, ARTIFACT_ID, VERSION, 2000);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setId(999);
Person person = new Person("john");
workItem.setParameter("person", person);
workItem.setParameter("KieSessionType", BusinessRuleTaskHandler.STATEFULL_TYPE);
handler.executeWorkItem(workItem, manager);
Map<String, Object> results = manager.getResults(workItem.getId());
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(35, ((Person) results.get("person")).getAge().intValue());
// build and deploy new version
createAndDeployJar(ks, ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION), ks.getResources().newClassPathResource("businessRule2.drl"));
// setup waiting mechanism to wait for scanner update
CountDownLatch latch = new CountDownLatch(1);
handler.getKieContainer().getKieBase().addEventListener(new DefaultKieBaseEventListener() {
@Override
public void afterRuleAdded(AfterRuleAddedEvent event) {
latch.countDown();
}
});
latch.await(10, TimeUnit.SECONDS);
person = new Person("john");
workItem.setParameter("person", person);
workItem.setParameter("KieSessionType", BusinessRuleTaskHandler.STATEFULL_TYPE);
handler.executeWorkItem(workItem, manager);
results = manager.getResults(workItem.getId());
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(45, ((Person) results.get("person")).getAge().intValue());
}
use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.
the class BusinessRuleTaskHandlerTest method testDmnBusinessRuleTaskNoScanner.
@Test
public void testDmnBusinessRuleTaskNoScanner() {
TestWorkItemManager manager = new TestWorkItemManager();
BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID, ARTIFACT_ID, VERSION);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setId(999);
workItem.setParameter("Language", BusinessRuleTaskHandler.DMN_LANG);
workItem.setParameter("Namespace", "https://www.drools.org/kie-dmn");
workItem.setParameter("Model", "0020-vacation-days");
workItem.setParameter("Age", 16);
workItem.setParameter("Years of Service", 1);
handler.executeWorkItem(workItem, manager);
Map<String, Object> results = manager.getResults(workItem.getId());
assertNotNull(results);
assertEquals(7, results.size());
assertEquals(27, ((BigDecimal) results.get("Total Vacation Days")).intValue());
}
Aggregations