Search in sources :

Example 81 with Deployment

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());
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 82 with Deployment

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);
    }
}
Also used : CommandExecutorImpl(org.activiti.engine.impl.cfg.CommandExecutorImpl) CommandInterceptor(org.activiti.engine.impl.interceptor.CommandInterceptor) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RuntimeServiceImpl(org.activiti.engine.impl.RuntimeServiceImpl) RetryInterceptor(org.activiti.engine.impl.interceptor.RetryInterceptor) Deployment(org.activiti.engine.test.Deployment)

Example 83 with Deployment

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);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Deployment(org.activiti.engine.test.Deployment)

Example 84 with Deployment

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());
}
Also used : Task(org.activiti.engine.task.Task) ChangeDeploymentTenantIdCmd(org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd) Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 85 with Deployment

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());
            }
        }
    }
}
Also used : Comment(org.activiti.engine.task.Comment) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Deployment (org.activiti.engine.test.Deployment)1178 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)846 Task (org.activiti.engine.task.Task)549 HashMap (java.util.HashMap)277 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)218 Execution (org.activiti.engine.runtime.Execution)151 Date (java.util.Date)94 Job (org.activiti.engine.runtime.Job)91 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)87 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)87 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)85 JsonNode (com.fasterxml.jackson.databind.JsonNode)66 Calendar (java.util.Calendar)63 DelegateTask (org.activiti.engine.delegate.DelegateTask)52 StringEntity (org.apache.http.entity.StringEntity)50 ArrayList (java.util.ArrayList)49 HttpGet (org.apache.http.client.methods.HttpGet)49 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)41 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)34 ActivitiException (org.activiti.engine.ActivitiException)31