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();
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
Aggregations