Search in sources :

Example 26 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class IdentifierJbpmRestIntegrationTest method testBasicJbpmRequest.

@Test
public void testBasicJbpmRequest() throws Exception {
    KieContainerResource resource = new KieContainerResource(CONTAINER, releaseId);
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(CONTAINER_ID, resource.getContainerId());
    valuesMap.put(PROCESS_ID, HUMAN_TASK_OWN_TYPE_ID);
    Response response = null;
    try {
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap));
        logger.info("[POST] " + clientRequest.getUri());
        // we set strict json parameter
        MediaType type = getMediaType();
        type = new MediaType(type.getType(), type.getSubtype(), Collections.singletonMap("strict", "true"));
        logger.info("media type : {}", type);
        response = clientRequest.request(type).post(Entity.entity("", type));
        Assert.assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
        Assertions.assertThat((String) response.getHeaders().getFirst("Content-Type")).startsWith(getMediaType().toString());
        String serialized = response.readEntity(String.class);
        response.close();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        Object wrapId = null;
        Object id = null;
        logger.info("Value returned {} {}", serialized, getMediaType());
        if (marshallingFormat.equals(MarshallingFormat.JAXB)) {
            wrapId = marshaller.unmarshall(serialized, Long.class);
            id = ((Long) wrapId);
        } else {
            try {
                wrapId = new JSONObject(serialized);
                id = ((JSONObject) wrapId).getString("value");
            } catch (JSONException ex) {
                Assert.fail("expected json object from kie server " + ex.getMessage());
            }
        }
        assertNotNull("object not returned", wrapId);
        valuesMap.put(PROCESS_INST_ID, id);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + ABORT_PROCESS_INST_DEL_URI, valuesMap));
        logger.info("[DELETE] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).delete();
        int noContentStatusCode = Response.Status.NO_CONTENT.getStatusCode();
        int okStatusCode = Response.Status.OK.getStatusCode();
        assertTrue("Wrong status code returned: " + response.getStatus(), response.getStatus() == noContentStatusCode || response.getStatus() == okStatusCode);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) JSONException(org.json.JSONException) Response(javax.ws.rs.core.Response) JSONObject(org.json.JSONObject) MediaType(javax.ws.rs.core.MediaType) JSONObject(org.json.JSONObject) WebTarget(javax.ws.rs.client.WebTarget) KieContainerResource(org.kie.server.api.model.KieContainerResource) Test(org.junit.Test)

Example 27 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class ProcessServiceRestOnlyIntegrationTest method testProcessWhichBelongsToAContainer.

@Test
public void testProcessWhichBelongsToAContainer() {
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
    valuesMap.put(RestURI.PROCESS_ID, PROCESS_ID_USERTASK);
    Response response = null;
    try {
        // start process instance
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap));
        logger.debug("[POST] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).post(createEntity(""));
        assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
        Long pid = response.readEntity(JaxbLong.class).unwrap();
        assertThat(pid).isNotNull();
        response.close();
        // find process instances which are deployed in the given container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_BY_CONTAINER_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        ProcessInstanceList processInstanceList = marshaller.unmarshall(response.readEntity(String.class), ProcessInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(processInstanceList.getItems()).hasSize(1);
        response.close();
        // find process instances of non-existing container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, NON_EXISTING_CONTAINER_ID);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_BY_CONTAINER_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        assertThat(response.readEntity(String.class)).contains(NON_EXISTING_CONTAINER_ID);
        assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode());
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) JaxbLong(org.kie.server.api.model.type.JaxbLong) WebTarget(javax.ws.rs.client.WebTarget) JaxbLong(org.kie.server.api.model.type.JaxbLong) Test(org.junit.Test)

Example 28 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class ProcessServiceRestOnlyIntegrationTest method testProcessVariablesHistoryWhichBelongsToAContainer.

@Test
public void testProcessVariablesHistoryWhichBelongsToAContainer() {
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
    valuesMap.put(RestURI.PROCESS_ID, PROCESS_ID_USERTASK);
    Response response = null;
    try {
        // start process instance
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap));
        logger.debug("[POST] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).post(createEntity(""));
        assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
        Long pid = response.readEntity(JaxbLong.class).unwrap();
        assertThat(pid).isNotNull();
        response.close();
        // find process instance variable which belongs to a process instance in a deployed container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, pid);
        valuesMap.put(VAR_NAME, "stringData");
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VAR_INSTANCE_BY_VAR_NAME_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        VariableInstanceList variableInstanceList = marshaller.unmarshall(response.readEntity(String.class), VariableInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(variableInstanceList.getItems()).isEmpty();
        response.close();
        // find process instance variable which belongs to a non-existing process instance
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, "-1");
        valuesMap.put(VAR_NAME, "stringData");
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VAR_INSTANCE_BY_VAR_NAME_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        variableInstanceList = marshaller.unmarshall(response.readEntity(String.class), VariableInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(variableInstanceList.getItems()).isEmpty();
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) JaxbLong(org.kie.server.api.model.type.JaxbLong) VariableInstanceList(org.kie.server.api.model.instance.VariableInstanceList) WebTarget(javax.ws.rs.client.WebTarget) JaxbLong(org.kie.server.api.model.type.JaxbLong) Test(org.junit.Test)

Example 29 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class ProcessServiceRestOnlyIntegrationTest method testProcessDefinitionWhichBelongsToAContainer.

@Test
public void testProcessDefinitionWhichBelongsToAContainer() {
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
    Response response = null;
    try {
        // find process definitions which belong to the given container
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        ProcessDefinitionList processDefinitionList = marshaller.unmarshall(response.readEntity(String.class), ProcessDefinitionList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        // we didn't specify pageSize, so it will be 10 by default
        assertThat(processDefinitionList.getItems()).hasSize(10);
        response.close();
        // find process definitions of non-existing container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, NON_EXISTING_CONTAINER_ID);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode());
        assertThat(response.readEntity(String.class)).contains(NON_EXISTING_CONTAINER_ID);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 30 with Marshaller

use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.

the class OptaPlannerJmsResponseHandlerIntegrationTest method testSolverWithAsyncResponseHandler.

@Test
public void testSolverWithAsyncResponseHandler() throws Exception {
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader());
    ResponseCallback responseCallback = new BlockingResponseCallback(marshaller);
    ResponseHandler asyncResponseHandler = new AsyncResponseHandler(responseCallback);
    solverClient.setResponseHandler(asyncResponseHandler);
    SolverInstance response = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertThat(response).isNull();
    SolverInstance solver = responseCallback.get(SolverInstance.class);
    assertThat(solver).isNotNull();
    assertThat(solver.getContainerId()).isEqualTo(CONTAINER_1_ID);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    List<SolverInstance> solverInstanceList = solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(solverInstanceList).isNull();
    SolverInstanceList solverList = responseCallback.get(SolverInstanceList.class);
    assertThat(solverList).isNotNull();
    assertThat(solverList.getContainers()).isNotNull().isNotEmpty().hasSize(1);
    solver = solverList.getContainers().get(0);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(5, 15));
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertThat(response).isNull();
    solver = responseCallback.get(SolverInstance.class);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.SOLVING);
    solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertThat(response).isNull();
    solver = responseCallback.get(SolverInstance.class);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isIn(SolverInstance.SolverStatus.TERMINATING_EARLY, SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(response).isNull();
    solverList = responseCallback.get(SolverInstanceList.class);
    assertThat(solverList).isNotNull();
    assertThat(solverList.getContainers()).isNullOrEmpty();
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) Marshaller(org.kie.server.api.marshalling.Marshaller) ResponseHandler(org.kie.server.client.jms.ResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList) OptaplannerKieServerBaseIntegrationTest(org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest) Test(org.junit.Test)

Aggregations

Marshaller (org.kie.server.api.marshalling.Marshaller)65 Test (org.junit.Test)48 HashMap (java.util.HashMap)12 WebTarget (javax.ws.rs.client.WebTarget)11 BeforeClass (org.junit.BeforeClass)10 ArrayList (java.util.ArrayList)9 MarshallingFormat (org.kie.server.api.marshalling.MarshallingFormat)9 Response (javax.ws.rs.core.Response)8 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)8 Command (org.kie.api.command.Command)8 ExecutionResults (org.kie.api.runtime.ExecutionResults)8 HashSet (java.util.HashSet)7 JaxbLong (org.kie.server.api.model.type.JaxbLong)6 KieContainerInstance (org.kie.server.services.api.KieContainerInstance)4 CallContainerCommand (org.kie.server.api.commands.CallContainerCommand)3 KieContainerResource (org.kie.server.api.model.KieContainerResource)3 KieServerCommand (org.kie.server.api.model.KieServerCommand)3 ServiceResponse (org.kie.server.api.model.ServiceResponse)3 Date (java.util.Date)2 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)2