use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class CompetingSignalsTest method testCompetingSignals.
@Deployment
public void testCompetingSignals() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("CompetingSignalsProcess");
String processInstanceId = processInstance.getId();
log.debug("test thread starts thread one");
SignalThread threadOne = new SignalThread(processInstanceId);
threadOne.startAndWaitUntilControlIsReturned();
log.debug("test thread continues to start thread two");
SignalThread threadTwo = new SignalThread(processInstanceId);
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());
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class CompetingSignalsTest method testCompetingSignalsWithRetry.
@Deployment(resources = { "org/activiti/engine/test/concurrency/CompetingSignalsTest.testCompetingSignals.bpmn20.xml" })
public void testCompetingSignalsWithRetry() throws Exception {
RuntimeServiceImpl runtimeServiceImpl = (RuntimeServiceImpl) runtimeService;
CommandExecutorImpl before = (CommandExecutorImpl) runtimeServiceImpl.getCommandExecutor();
try {
CommandInterceptor retryInterceptor = new RetryInterceptor();
retryInterceptor.setNext(before.getFirst());
runtimeServiceImpl.setCommandExecutor(new CommandExecutorImpl(before.getDefaultConfig(), retryInterceptor));
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("CompetingSignalsProcess");
String processInstanceId = processInstance.getId();
log.debug("test thread starts thread one");
SignalThread threadOne = new SignalThread(processInstanceId);
threadOne.startAndWaitUntilControlIsReturned();
log.debug("test thread continues to start thread two");
SignalThread threadTwo = new SignalThread(processInstanceId);
threadTwo.startAndWaitUntilControlIsReturned();
log.debug("test thread notifies thread 1");
threadOne.proceedAndWaitTillDone();
assertNull(threadOne.exception);
log.debug("test thread notifies thread 2");
threadTwo.proceedAndWaitTillDone();
assertNull(threadTwo.exception);
} finally {
// restore the command executor
runtimeServiceImpl.setCommandExecutor(before);
}
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class FormDataResourceTest method testSubmitFormData.
@Deployment
public void testSubmitFormData() throws Exception {
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("SpeakerName", "John Doe");
Address address = new Address();
variableMap.put("address", address);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
String processInstanceId = processInstance.getId();
String processDefinitionId = processInstance.getProcessDefinitionId();
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("taskId", task.getId());
ArrayNode propertyArray = objectMapper.createArrayNode();
requestNode.put("properties", propertyArray);
ObjectNode propNode = objectMapper.createObjectNode();
propNode.put("id", "room");
propNode.put("value", 123l);
propertyArray.add(propNode);
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_INTERNAL_SERVER_ERROR));
propNode = objectMapper.createObjectNode();
propNode.put("id", "street");
propNode.put("value", "test");
propertyArray.add(propNode);
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT));
task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
assertNull(task);
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNull(processInstance);
List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
Map<String, HistoricVariableInstance> historyMap = new HashMap<String, HistoricVariableInstance>();
for (HistoricVariableInstance historicVariableInstance : variables) {
historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance);
}
assertEquals("123", historyMap.get("room").getValue());
assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId());
processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
processInstanceId = processInstance.getId();
task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
requestNode.put("taskId", task.getId());
propNode = objectMapper.createObjectNode();
propNode.put("id", "direction");
propNode.put("value", "nowhere");
propertyArray.add(propNode);
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
propNode.put("value", "up");
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT));
task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
assertNull(task);
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNull(processInstance);
variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
historyMap.clear();
for (HistoricVariableInstance historicVariableInstance : variables) {
historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance);
}
assertEquals("123", historyMap.get("room").getValue());
assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId());
assertEquals("up", historyMap.get("direction").getValue());
requestNode = objectMapper.createObjectNode();
requestNode.put("processDefinitionId", processDefinitionId);
propertyArray = objectMapper.createArrayNode();
requestNode.put("properties", propertyArray);
propNode = objectMapper.createObjectNode();
propNode.put("id", "number");
propNode.put("value", 123);
propertyArray.add(propNode);
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode.get("id").asText());
assertEquals(processDefinitionId, responseNode.get("processDefinitionId").asText());
task = taskService.createTaskQuery().processInstanceId(responseNode.get("id").asText()).singleResult();
assertNotNull(task);
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class HistoricProcessInstanceCollectionResourceTest method testQueryProcessInstances.
/**
* Test querying historic process instance based on variables.
* GET history/historic-process-instances
*/
@Deployment
public void testQueryProcessInstances() throws Exception {
Calendar startTime = Calendar.getInstance();
processEngineConfiguration.getClock().setCurrentTime(startTime.getTime());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
startTime.add(Calendar.DAY_OF_YEAR, 1);
processEngineConfiguration.getClock().setCurrentTime(startTime.getTime());
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCES);
assertResultsPresentInDataResponse(url + "?finished=true", processInstance.getId());
assertResultsPresentInDataResponse(url + "?finished=false", processInstance2.getId());
assertResultsPresentInDataResponse(url + "?processDefinitionId=" + processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance2.getId());
assertResultsPresentInDataResponse(url + "?processDefinitionId=" + processInstance.getProcessDefinitionId() + "&finished=true", processInstance.getId());
assertResultsPresentInDataResponse(url + "?processDefinitionKey=oneTaskProcess", processInstance.getId(), processInstance2.getId());
// Without tenant ID, before setting tenant
assertResultsPresentInDataResponse(url + "?withoutTenantId=true", processInstance.getId(), processInstance2.getId());
// Set tenant on deployment
managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
startTime.add(Calendar.DAY_OF_YEAR, 1);
processEngineConfiguration.getClock().setCurrentTime(startTime.getTime());
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKeyAndTenantId("oneTaskProcess", "myTenant");
// Without tenant ID, after setting tenant
assertResultsPresentInDataResponse(url + "?withoutTenantId=true", processInstance.getId(), processInstance2.getId());
// Tenant id
assertResultsPresentInDataResponse(url + "?tenantId=myTenant", processInstance3.getId());
assertResultsPresentInDataResponse(url + "?tenantId=anotherTenant");
// Tenant id like
assertResultsPresentInDataResponse(url + "?tenantIdLike=" + encode("%enant"), processInstance3.getId());
assertResultsPresentInDataResponse(url + "?tenantIdLike=anotherTenant");
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url + "?processDefinitionKey=oneTaskProcess&sort=startTime"), 200);
// Check status and size
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
assertEquals(3, dataNode.size());
assertEquals(processInstance.getId(), dataNode.get(0).get("id").asText());
assertEquals(processInstance2.getId(), dataNode.get(1).get("id").asText());
assertEquals(processInstance3.getId(), dataNode.get(2).get("id").asText());
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class HistoricProcessInstanceCommentResourceTest method testGetComment.
/**
* Test getting a comment for a historic process instance.
* GET history/historic-process-instances/{processInstanceId}/comments/{commentId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetComment() throws Exception {
ProcessInstance pi = null;
try {
pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// Add a comment as "kermit"
identityService.setAuthenticatedUserId("kermit");
Comment comment = taskService.addComment(null, pi.getId(), "This is a comment...");
identityService.setAuthenticatedUserId(null);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())), 200);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("kermit", responseNode.get("author").textValue());
assertEquals("This is a comment...", responseNode.get("message").textValue());
assertEquals(comment.getId(), responseNode.get("id").textValue());
assertTrue(responseNode.get("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())));
assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
assertTrue(responseNode.get("taskUrl").isNull());
assertTrue(responseNode.get("taskId").isNull());
// Test with unexisting process-instance
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, "unexistinginstance", "123")), HttpStatus.SC_NOT_FOUND));
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), "unexistingcomment")), HttpStatus.SC_NOT_FOUND));
} finally {
if (pi != null) {
List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
for (Comment c : comments) {
taskService.deleteComment(c.getId());
}
}
}
}
Aggregations