use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testPOSTOperationWithPathParamAndNoContent.
@Test
public void testPOSTOperationWithPathParamAndNoContent() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL + "/john");
workItem.setParameter("Method", "POST");
WorkItemManager manager = new TestWorkItemManager(workItem);
handler.executeWorkItem(workItem, manager);
String result = (String) workItem.getResult("Result");
assertNotNull("result cannot be null", result);
assertEquals("Created resource with name john", result);
int responseCode = (Integer) workItem.getResult("Status");
assertNotNull(responseCode);
assertEquals(200, responseCode);
String responseMsg = (String) workItem.getResult("StatusMsg");
assertNotNull(responseMsg);
assertEquals("request to endpoint " + workItem.getParameter("Url") + " successfully completed OK", responseMsg);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testPOSTOperation.
@Test
public void testPOSTOperation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<person><age>25</age><name>Post john</name></person>";
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL + "/xml");
workItem.setParameter("Method", "POST");
workItem.setParameter("ContentType", "application/xml");
workItem.setParameter("Content", "<person><name>john</name><age>25</age></person>");
WorkItemManager manager = new TestWorkItemManager(workItem);
handler.executeWorkItem(workItem, manager);
String result = (String) workItem.getResult("Result");
assertNotNull("result cannot be null", result);
assertEquals(expected, result);
int responseCode = (Integer) workItem.getResult("Status");
assertNotNull(responseCode);
assertEquals(200, responseCode);
String responseMsg = (String) workItem.getResult("StatusMsg");
assertNotNull(responseMsg);
assertEquals("request to endpoint " + workItem.getParameter("Url") + " successfully completed OK", responseMsg);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testUnsupportedOperation.
@Test(expected = IllegalArgumentException.class)
public void testUnsupportedOperation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL + "/xml/john");
workItem.setParameter("Method", "HEAD");
WorkItemManager manager = new TestWorkItemManager(workItem);
handler.executeWorkItem(workItem, manager);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testGETOperationWithCustomTimeout.
@Test
public void testGETOperationWithCustomTimeout() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL);
workItem.setParameter("Method", "GET");
workItem.setParameter("ConnectTimeout", "30000");
workItem.setParameter("ReadTimeout", "25000");
WorkItemManager manager = new TestWorkItemManager(workItem);
handler.executeWorkItem(workItem, manager);
String result = (String) workItem.getResult("Result");
assertNotNull("result cannot be null", result);
assertEquals("Hello from REST", result);
int responseCode = (Integer) workItem.getResult("Status");
assertNotNull(responseCode);
assertEquals(200, responseCode);
String responseMsg = (String) workItem.getResult("StatusMsg");
assertNotNull(responseMsg);
assertEquals("request to endpoint " + workItem.getParameter("Url") + " successfully completed OK", responseMsg);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testHandleErrorOnNotSuccessfulResponse.
@Test
public void testHandleErrorOnNotSuccessfulResponse() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL + "/notexisting");
workItem.setParameter("Method", "GET");
workItem.setParameter("HandleResponseErrors", "true");
WorkItemManager manager = new TestWorkItemManager(workItem);
try {
handler.executeWorkItem(workItem, manager);
fail("Should throw exception as it was instructed to do so");
} catch (WorkItemHandlerRuntimeException ex) {
RESTServiceException e = (RESTServiceException) ex.getCause().getCause();
assertEquals(405, e.getStatus());
assertEquals(SERVER_URL + "/notexisting", e.getEndoint());
assertEquals("", e.getResponse());
}
}
Aggregations