use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class ExecutionVariableResourceTest method testDeleteExecutionVariable.
/**
* Test deleting a single execution variable, including "not found" check.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testDeleteExecutionVariable() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", Collections.singletonMap("myVariable", (Object) "processValue"));
Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
assertNotNull(childExecution);
runtimeService.setVariableLocal(childExecution.getId(), "myVariable", "childValue");
// Delete variable local
HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVariable"));
CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
closeResponse(response);
assertFalse(runtimeService.hasVariableLocal(childExecution.getId(), "myVariable"));
// Global variable should remain unaffected
assertTrue(runtimeService.hasVariable(childExecution.getId(), "myVariable"));
// Delete variable global
httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVariable") + "?scope=global");
response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
closeResponse(response);
assertFalse(runtimeService.hasVariableLocal(childExecution.getId(), "myVariable"));
assertFalse(runtimeService.hasVariable(childExecution.getId(), "myVariable"));
// Run the same delete again, variable is not there so 404 should be returned
response = executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND);
closeResponse(response);
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class ExecutionVariableResourceTest method testGetExecutionDataForIllegalVariables.
/**
* Test getting an execution variable, for illegal vars.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutionDataForIllegalVariables() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");
runtimeService.setVariableLocal(processInstance.getId(), "localTaskVariable", "this is a plain string variable");
// Try getting data for non-binary variable
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, processInstance.getId(), "localTaskVariable")), HttpStatus.SC_NOT_FOUND);
closeResponse(response);
// Try getting data for unexisting property
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, processInstance.getId(), "unexistingVariable")), HttpStatus.SC_NOT_FOUND);
closeResponse(response);
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class ProcessInstanceCollectionResourceTest method testStartProcessWithVariables.
/**
* Test starting a process instance passing in variables to set.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testStartProcessWithVariables() throws Exception {
ArrayNode variablesNode = objectMapper.createArrayNode();
// String variable
ObjectNode stringVarNode = variablesNode.addObject();
stringVarNode.put("name", "stringVariable");
stringVarNode.put("value", "simple string value");
stringVarNode.put("type", "string");
ObjectNode integerVarNode = variablesNode.addObject();
integerVarNode.put("name", "integerVariable");
integerVarNode.put("value", 1234);
integerVarNode.put("type", "integer");
ObjectNode shortVarNode = variablesNode.addObject();
shortVarNode.put("name", "shortVariable");
shortVarNode.put("value", 123);
shortVarNode.put("type", "short");
ObjectNode longVarNode = variablesNode.addObject();
longVarNode.put("name", "longVariable");
longVarNode.put("value", 4567890L);
longVarNode.put("type", "long");
ObjectNode doubleVarNode = variablesNode.addObject();
doubleVarNode.put("name", "doubleVariable");
doubleVarNode.put("value", 123.456);
doubleVarNode.put("type", "double");
ObjectNode booleanVarNode = variablesNode.addObject();
booleanVarNode.put("name", "booleanVariable");
booleanVarNode.put("value", Boolean.TRUE);
booleanVarNode.put("type", "boolean");
// Date
Calendar varCal = Calendar.getInstance();
String isoString = getISODateString(varCal.getTime());
ObjectNode dateVarNode = variablesNode.addObject();
dateVarNode.put("name", "dateVariable");
dateVarNode.put("value", isoString);
dateVarNode.put("type", "date");
ObjectNode requestNode = objectMapper.createObjectNode();
// Start using process definition key, passing in variables
requestNode.put("processDefinitionKey", "processOne");
requestNode.put("variables", variablesNode);
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertEquals("processTask", responseNode.get("activityId").asText());
assertEquals(false, responseNode.get("ended").asBoolean());
JsonNode variablesArrayNode = responseNode.get("variables");
assertEquals(0, variablesArrayNode.size());
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
assertNotNull(processInstance);
// Check if engine has correct variables set
Map<String, Object> processVariables = runtimeService.getVariables(processInstance.getId());
assertEquals(7, processVariables.size());
assertEquals("simple string value", processVariables.get("stringVariable"));
assertEquals(1234, processVariables.get("integerVariable"));
assertEquals((short) 123, processVariables.get("shortVariable"));
assertEquals(4567890L, processVariables.get("longVariable"));
assertEquals(123.456, processVariables.get("doubleVariable"));
assertEquals(Boolean.TRUE, processVariables.get("booleanVariable"));
assertEquals(dateFormat.parse(isoString), processVariables.get("dateVariable"));
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class ProcessInstanceSuspensionTest method testJobsNotVisisbleToAcquisitionIfDefinitionSuspended.
@Deployment(resources = { "org/activiti/engine/test/db/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisisbleToAcquisitionIfDefinitionSuspended() {
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
runtimeService.startProcessInstanceByKey(pd.getKey());
// now there is one job:
Job job = managementService.createJobQuery().singleResult();
assertNotNull(job);
makeSureJobDue(job);
// the acquirejobs command sees the job:
AcquiredJobEntities acquiredJobs = executeAcquireJobsCommand();
assertEquals(1, acquiredJobs.size());
// suspend the process instance:
repositoryService.suspendProcessDefinitionById(pd.getId());
// now, the acquirejobs command does not see the job:
acquiredJobs = executeAcquireJobsCommand();
assertEquals(0, acquiredJobs.size());
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class CompetingJoinTest method testCompetingJoins.
@Deployment
public void testCompetingJoins() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("CompetingJoinsProcess");
Execution execution1 = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("wait1").singleResult();
Execution execution2 = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("wait2").singleResult();
log.debug("test thread starts thread one");
SignalThread threadOne = new SignalThread(execution1.getId());
threadOne.startAndWaitUntilControlIsReturned();
log.debug("test thread continues to start thread two");
SignalThread threadTwo = new SignalThread(execution2.getId());
threadTwo.startAndWaitUntilControlIsReturned();
log.debug("test thread notifies thread 1");
threadOne.proceedAndWaitTillDone();
assertNull(threadOne.exception);
log.debug("test thread notifies thread 2");
threadTwo.proceedAndWaitTillDone();
assertNotNull(threadTwo.exception);
assertTextPresent("was updated by another transaction concurrently", threadTwo.exception.getMessage());
}
Aggregations