use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testPUTOperationWithJSONHeader.
@Test
public void testPUTOperationWithJSONHeader() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<person><age>25</age><name>Put john</name></person>";
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/xml");
workItem.setParameter("Method", "PUT");
workItem.setParameter(PARAM_CONTENT_TYPE, "application/xml");
workItem.setParameter(contentParamName, "<person><name>john</name><age>25</age></person>");
workItem.setParameter("AcceptHeader", "application/json");
WorkItemManager manager = new TestWorkItemManager();
handler.executeWorkItem(workItem, manager);
Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
int responseCode = (Integer) results.get(PARAM_STATUS);
assertNotNull(responseCode);
assertEquals(406, responseCode);
String responseMsg = (String) results.get(PARAM_STATUS_MSG);
assertNotNull(responseMsg);
assertEquals("endpoint " + serverURL + "/xml could not be reached: ", responseMsg);
}
use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testPUTOperationWithDefaultCharset.
@Test
public void testPUTOperationWithDefaultCharset() {
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 ????</name></person>";
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/xml-charset");
workItem.setParameter("Method", "PUT");
workItem.setParameter(PARAM_CONTENT_TYPE, "application/xml");
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.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testUnsupportedOperation.
@Test(expected = IllegalArgumentException.class)
public void testUnsupportedOperation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/xml/john");
workItem.setParameter("Method", "HEAD");
WorkItemManager manager = new TestWorkItemManager();
handler.executeWorkItem(workItem, manager);
}
use of org.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testPUTOperationWithXMLHeader.
@Test
public void testPUTOperationWithXMLHeader() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<person><age>25</age><name>Put john</name></person>";
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/xml");
workItem.setParameter("Method", "PUT");
workItem.setParameter(PARAM_CONTENT_TYPE, "application/xml");
workItem.setParameter(contentParamName, "<person><name>john</name><age>25</age></person>");
workItem.setParameter("AcceptHeader", "application/xml");
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.jbpm.process.workitem.core.TestWorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testGETOperation.
@Test
public void testGETOperation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL);
workItem.setParameter("Method", "GET");
WorkItemManager manager = new TestWorkItemManager();
handler.executeWorkItem(workItem, manager);
Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
assertNotNull("results cannot be null", results);
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);
}
Aggregations