use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testGETOperationWithCustomTimeout.
@Test
public void testGETOperationWithCustomTimeout() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL);
workItem.setParameter("Method", "GET");
workItem.setParameter(PARAM_CONNECT_TIMEOUT, "30000");
workItem.setParameter(PARAM_READ_TIMEOUT, "25000");
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 testGETOperationWithXMLHeader.
@Test
public void testGETOperationWithXMLHeader() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL);
workItem.setParameter("Method", "GET");
workItem.setParameter("AcceptHeader", "application/xml");
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 + " could not be reached: ", responseMsg);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testPOSTOperationWithCompleteXmlTransformation.
@Test
public void testPOSTOperationWithCompleteXmlTransformation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
Person request = new Person();
request.setAge(25);
request.setName("john");
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/xml");
workItem.setParameter("Method", "POST");
workItem.setParameter(PARAM_CONTENT_TYPE, "application/xml");
workItem.setParameter(contentParamName, request);
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 testGETOperationWithXmlTrasformation.
@Test
public void testGETOperationWithXmlTrasformation() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/xml");
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 Xml", 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 testGETOperationWithQueryParam.
@Test
public void testGETOperationWithQueryParam() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "?param=test");
workItem.setParameter("Method", "GET");
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 test", 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