use of org.apache.http.client.methods.HttpPut in project Activiti by Activiti.
the class ExecutionResourceTest method testSignalEventExecutionWithvariables.
/**
* Test signalling a single execution, with signal event.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecutionWithvariables() throws Exception {
Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
assertNotNull(signalExecution);
ArrayNode variables = objectMapper.createArrayNode();
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "signalEventReceived");
requestNode.put("signalName", "alert");
requestNode.put("variables", variables);
ObjectNode varNode = objectMapper.createObjectNode();
variables.add(varNode);
varNode.put("name", "myVar");
varNode.put("value", "Variable set when signal event is receieved");
Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
assertNotNull(waitingExecution);
// Sending signal event causes the execution to end (scope-execution for the catching event)
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, waitingExecution.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_NO_CONTENT);
closeResponse(response);
// Check if process is moved on to the other wait-state
waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
assertNotNull(waitingExecution);
assertEquals(signalExecution.getId(), waitingExecution.getId());
Map<String, Object> vars = runtimeService.getVariables(waitingExecution.getId());
assertEquals(1, vars.size());
assertEquals("Variable set when signal event is receieved", vars.get("myVar"));
}
use of org.apache.http.client.methods.HttpPut in project Activiti by Activiti.
the class ExecutionResourceTest method testIllegalExecutionAction.
/**
* Test executing an illegal action on an execution.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testIllegalExecutionAction() throws Exception {
Execution execution = runtimeService.startProcessInstanceByKey("processOne");
assertNotNull(execution);
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "badaction");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, execution.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST);
closeResponse(response);
}
use of org.apache.http.client.methods.HttpPut in project Activiti by Activiti.
the class ProcessInstanceResourceTest method testSuspendProcessInstance.
/**
* Test suspending a single process instance.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testSuspendProcessInstance() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "suspend");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
// Check engine id instance is suspended
assertEquals(1, runtimeService.createProcessInstanceQuery().suspended().processInstanceId(processInstance.getId()).count());
// Check resulting instance is suspended
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(processInstance.getId(), responseNode.get("id").textValue());
assertTrue(responseNode.get("suspended").booleanValue());
// Suspending again should result in conflict
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}
use of org.apache.http.client.methods.HttpPut in project Activiti by Activiti.
the class ProcessInstanceResourceTest method testActivateProcessInstance.
/**
* Test suspending a single process instance.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testActivateProcessInstance() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
runtimeService.suspendProcessInstanceById(processInstance.getId());
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "activate");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
// Check engine id instance is suspended
assertEquals(1, runtimeService.createProcessInstanceQuery().active().processInstanceId(processInstance.getId()).count());
// Check resulting instance is suspended
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(processInstance.getId(), responseNode.get("id").textValue());
assertFalse(responseNode.get("suspended").booleanValue());
// Activating again should result in conflict
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}
use of org.apache.http.client.methods.HttpPut in project Activiti by Activiti.
the class ProcessInstanceVariableResourceTest method testUpdateProcessVariable.
/**
* Test updating a single process variable, including "not found" check.
*
* PUT runtime/process-instances/{processInstanceId}/variables/{variableName}
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testUpdateProcessVariable() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue"));
runtimeService.setVariable(processInstance.getId(), "myVar", "value");
// Update variable
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("name", "myVar");
requestNode.put("value", "updatedValue");
requestNode.put("type", "string");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVar"));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("updatedValue", responseNode.get("value").asText());
// Try updating with mismatch between URL and body variableName
requestNode.put("name", "unexistingVariable");
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST));
// Try updating unexisting property
requestNode.put("name", "unexistingVariable");
httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "unexistingVariable"));
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}
Aggregations