use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm-work-items by kiegroup.
the class GithubWorkitemHandlerTest method testMergePullRequest.
@Test
public void testMergePullRequest() throws Exception {
TestWorkItemManager manager = new TestWorkItemManager();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("RepoOwner", "testRepoOwner");
workItem.setParameter("RepoName", "testRepoName");
workItem.setParameter("PullRequestNum", "10");
workItem.setParameter("CommitMessage", "testCommitMessage");
MergePullRequestWorkitemHandler handler = new MergePullRequestWorkitemHandler("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("IsMerged") instanceof Boolean);
Boolean isPullRequestMerged = (Boolean) manager.getResults().get(workItem.getId()).get("IsMerged");
assertNotNull(isPullRequestMerged);
assertTrue(isPullRequestMerged.booleanValue());
}
use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm-work-items by kiegroup.
the class ArchiveWorkitemHandlerTest method testWithTempFile.
@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()));
}
use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm-work-items by kiegroup.
the class ArchiveWorkitemHandlerTest method testNoFilesSpecified.
@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()));
}
use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.
the class JMSSendTaskWorkItemHandlerTest method testSendMessage.
@Test
public void testSendMessage() throws Exception {
ArgumentCaptor<byte[]> bytesCaptor = ArgumentCaptor.forClass(byte[].class);
when(connectionFactory.createConnection()).thenReturn(connection);
when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);
when(session.createProducer(any(Destination.class))).thenReturn(producer);
when(session.createBytesMessage()).thenReturn(message);
doNothing().when(producer).close();
doNothing().when(session).close();
doNothing().when(connection).close();
doNothing().when(producer).send(any(Message.class));
TestWorkItemManager manager = new TestWorkItemManager();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Signal", "mysignal");
workItem.setParameter("SignalProcessInstanceId", "abcde");
workItem.setParameter("SignalWorkItemId", "12345");
workItem.setParameter("SignalDeploymentId", "deployment-123");
workItem.setProcessInstanceId(123L);
workItem.setDeploymentId("deploy-123");
workItem.setParameter("Data", "hello world");
JMSSendTaskWorkItemHandler handler = new JMSSendTaskWorkItemHandler(connectionFactory, destination, false, false);
handler.executeWorkItem(workItem, manager);
assertNotNull(manager.getResults());
assertEquals(1, manager.getResults().size());
assertTrue(manager.getResults().containsKey(workItem.getId()));
verify(message).writeBytes(bytesCaptor.capture());
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytesCaptor.getValue());
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
String messageVal = (String) objectInputStream.readObject();
assertTrue("hello world".equals(messageVal));
}
use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testDELETEOperation.
@Test
public void testDELETEOperation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<person><age>-1</age><name>deleted john</name></person>";
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/xml/john");
workItem.setParameter("Method", "DELETE");
WorkItemManager manager = new TestWorkItemManager();
handler.executeWorkItem(workItem, manager);
Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
String result = (String) results.get(PARAM_RESULT);
assertNotNull("result cannot be null", result);
assertEquals(expected, result);
int responseCode = (Integer) results.get(PARAM_STATUS);
assertNotNull(responseCode);
assertEquals(200, responseCode);
String responseMsg = (String) results.get(PARAM_STATUS_MSG);
assertNotNull(responseMsg);
assertEquals("request to endpoint " + workItem.getParameter("Url") + " successfully completed OK", responseMsg);
}
Aggregations