use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testGETOperationWithJsonTrasformation.
@Test
public void testGETOperationWithJsonTrasformation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/json");
workItem.setParameter("Method", "GET");
workItem.setParameter("ResultClass", Person.class.getName());
WorkItemManager manager = new TestWorkItemManager();
handler.executeWorkItem(workItem, manager);
Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
Person result = (Person) results.get(PARAM_RESULT);
assertNotNull("result cannot be null", result);
assertEquals("Person Json", result.getName());
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);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testPOSTOperationWithXmlTransformation.
@Test
public void testPOSTOperationWithXmlTransformation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/xml");
workItem.setParameter("Method", "POST");
workItem.setParameter(PARAM_CONTENT_TYPE, "Application/XML;charset=utf-8");
workItem.setParameter(contentParamName, "<person><name>john</name><age>25</age></person>");
workItem.setParameter("ResultClass", Person.class.getName());
WorkItemManager manager = new TestWorkItemManager();
handler.executeWorkItem(workItem, manager);
Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
Person result = (Person) results.get(PARAM_RESULT);
assertNotNull("result cannot be null", result);
assertEquals("Post john", result.getName());
assertEquals(25, result.getAge().intValue());
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);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testPUTOperationWithCharsetSpecified.
@Test
public void testPUTOperationWithCharsetSpecified() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
String nonAsciiData = "\u0418\u0432\u0430\u043d";
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<person><age>25</age><name>Put " + nonAsciiData + "</name></person>";
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/xml-charset");
workItem.setParameter("Method", "PUT");
workItem.setParameter(PARAM_CONTENT_TYPE, "application/xml; charset=utf-8");
workItem.setParameter(contentParamName, "<person><name>" + nonAsciiData + "</name><age>25</age></person>");
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);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testGETOperationWithInvalidTimeout.
@Test
public void testGETOperationWithInvalidTimeout() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL);
workItem.setParameter("Method", "GET");
workItem.setParameter(PARAM_CONNECT_TIMEOUT, "");
workItem.setParameter(PARAM_READ_TIMEOUT, "");
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("Hello from REST", 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);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testHandleErrorOnNotSuccessfulResponse.
@Test
public void testHandleErrorOnNotSuccessfulResponse() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/notexisting");
workItem.setParameter("Method", "GET");
workItem.setParameter("HandleResponseErrors", "true");
WorkItemManager manager = new TestWorkItemManager();
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(serverURL + "/notexisting", e.getEndoint());
assertEquals("", e.getResponse());
}
}
Aggregations