Search in sources :

Example 1 with RESTWorkItemHandler

use of org.jbpm.process.workitem.rest.RESTWorkItemHandler in project jbpm by kiegroup.

the class RestServiceInvokeTest method testPost.

@Test
@RunAsClient
public void testPost() throws Exception {
    System.out.println("### Running proccess ...");
    KieSession ksession = getSession(rrs.getResource(RegisterRestService.BPMN_CALL_REST_SERVICE));
    ksession.getWorkItemManager().registerWorkItemHandler("REST", new RESTWorkItemHandler());
    HashMap<String, Object> arguments = new HashMap<String, Object>();
    arguments.put("Url", RegisterRestService.SERVICE_URL + "PersonList/add");
    arguments.put("Method", "POST");
    arguments.put("ContentType", "application/json");
    arguments.put("Content", "{ \"name\": \"Marek\",  \"middlename\": \"-\", \"surname\": \"Baluch\" }");
    WorkflowProcessInstance pi = (WorkflowProcessInstance) ksession.startProcess(RegisterRestService.PROCESS_CALL_REST_SERVICE, arguments);
    Assertions.assertThat(pi.getVariable("Result")).as("REST call failed - Wrong response.").isEqualTo("Ok");
    Assertions.assertThat(pi.getVariable("Status")).as("REST call failed - Wrong status code.").isEqualTo(200);
    Assertions.assertThat(pi.getState()).as("Process did not finish").isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) RESTWorkItemHandler(org.jbpm.process.workitem.rest.RESTWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Example 2 with RESTWorkItemHandler

use of org.jbpm.process.workitem.rest.RESTWorkItemHandler in project jbpm by kiegroup.

the class RestServiceInvokeTest method testGet.

@Test
@RunAsClient
public void testGet() throws Exception {
    System.out.println("### Running proccess ...");
    KieSession ksession = getSession(rrs.getResource(RegisterRestService.BPMN_CALL_REST_SERVICE_SIMPLE));
    ksession.getWorkItemManager().registerWorkItemHandler("REST", new RESTWorkItemHandler());
    HashMap<String, Object> arguments = new HashMap<String, Object>();
    arguments.put("Url", RegisterRestService.SERVICE_URL + "PersonList/ping");
    WorkflowProcessInstance pi = (WorkflowProcessInstance) ksession.startProcess(RegisterRestService.PROCESS_CALL_REST_SERVICE_SIMPLE, arguments);
    Assertions.assertThat(pi.getVariable("Result")).as("REST call failed - Wrong response.").isEqualTo("pong");
    Assertions.assertThat(pi.getVariable("Status")).as("REST call failed - Wrong status code.").isEqualTo(200);
    Assertions.assertThat(pi.getState()).as("Process did not finish").isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) RESTWorkItemHandler(org.jbpm.process.workitem.rest.RESTWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Example 3 with RESTWorkItemHandler

use of org.jbpm.process.workitem.rest.RESTWorkItemHandler in project jbpm by kiegroup.

the class RestServiceInvokeTest method testDelete.

@Test
@RunAsClient
public void testDelete() throws Exception {
    System.out.println("### Running proccess ...");
    KieSession ksession = getSession(rrs.getResource(RegisterRestService.BPMN_CALL_REST_SERVICE));
    ksession.getWorkItemManager().registerWorkItemHandler("REST", new RESTWorkItemHandler());
    HashMap<String, Object> arguments = new HashMap<String, Object>();
    arguments.put("Url", RegisterRestService.SERVICE_URL + "PersonList/delete?name=Don&middlename=Non&surname=Existent");
    arguments.put("Method", "DELETE");
    arguments.put("ContentType", "text/plain");
    WorkflowProcessInstance pi = (WorkflowProcessInstance) ksession.startProcess(RegisterRestService.PROCESS_CALL_REST_SERVICE, arguments);
    Assertions.assertThat(pi.getVariable("Result")).as("REST call failed - Wrong response.").isEqualTo("Fail");
    Assertions.assertThat(pi.getVariable("Status")).as("REST call failed - Wrong status code.").isEqualTo(200);
    Assertions.assertThat(pi.getState()).as("Process did not finish").isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) RESTWorkItemHandler(org.jbpm.process.workitem.rest.RESTWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Example 4 with RESTWorkItemHandler

use of org.jbpm.process.workitem.rest.RESTWorkItemHandler in project jbpm by kiegroup.

the class RestServiceInvokeTest method testSecuredFail.

@Test
@RunAsClient
public void testSecuredFail() throws Exception {
    System.out.println("### Running proccess ...");
    KieSession ksession = getSession(rrs.getResource(RegisterRestService.BPMN_CALL_REST_SERVICE_SIMPLE));
    ksession.getWorkItemManager().registerWorkItemHandler("REST", new RESTWorkItemHandler("undefined", "user"));
    HashMap<String, Object> arguments = new HashMap<String, Object>();
    arguments.put("Url", RegisterRestService.SERVICE_URL + "PersonList/securedPing");
    WorkflowProcessInstance pi = (WorkflowProcessInstance) ksession.startProcess(RegisterRestService.PROCESS_CALL_REST_SERVICE_SIMPLE, arguments);
    Assertions.assertThat(pi.getVariable("Status")).as("REST call failed").isEqualTo((Object) 401);
    Assertions.assertThat(pi.getState()).as("Process did not finish").isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) RESTWorkItemHandler(org.jbpm.process.workitem.rest.RESTWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Example 5 with RESTWorkItemHandler

use of org.jbpm.process.workitem.rest.RESTWorkItemHandler in project jbpm by kiegroup.

the class RestServiceInvokeTest method testSecuredGet.

@Test
@RunAsClient
public void testSecuredGet() throws Exception {
    System.out.println("### Running proccess ...");
    KieSession ksession = getSession(rrs.getResource(RegisterRestService.BPMN_CALL_REST_SERVICE_SIMPLE));
    ksession.getWorkItemManager().registerWorkItemHandler("REST", new RESTWorkItemHandler("ibek", "ibek1234;"));
    HashMap<String, Object> arguments = new HashMap<String, Object>();
    arguments.put("Url", RegisterRestService.SERVICE_URL + "PersonList/securedPing");
    WorkflowProcessInstance pi = (WorkflowProcessInstance) ksession.startProcess(RegisterRestService.PROCESS_CALL_REST_SERVICE_SIMPLE, arguments);
    Assertions.assertThat(pi.getVariable("Result")).as("REST call failed - Wrong response.").isEqualTo("securedPong");
    Assertions.assertThat(pi.getVariable("Status")).as("REST call failed - Wrong status code.").isEqualTo(200);
    Assertions.assertThat(pi.getState()).as("Process did not finish").isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) RESTWorkItemHandler(org.jbpm.process.workitem.rest.RESTWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)5 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)5 RESTWorkItemHandler (org.jbpm.process.workitem.rest.RESTWorkItemHandler)5 JbpmContainerTest (org.jbpm.test.container.JbpmContainerTest)5 Test (org.junit.Test)5 KieSession (org.kie.api.runtime.KieSession)5 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)5