Search in sources :

Example 96 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class JobResourceTest method testExecuteJob.

/**
   * Test executing a single job. 
   */
@Deployment(resources = { "org/activiti/rest/service/api/management/JobResourceTest.testTimerProcess.bpmn20.xml" })
public void testExecuteJob() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "execute");
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
    // Job should be executed
    assertNull(managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 97 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class JobResourceTest method testGetJob.

/**
   * Test getting a single job. 
   */
@Deployment(resources = { "org/activiti/rest/service/api/management/JobResourceTest.testTimerProcess.bpmn20.xml" })
public void testGetJob() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
    Calendar now = Calendar.getInstance();
    now.set(Calendar.MILLISECOND, 0);
    processEngineConfiguration.getClock().setCurrentTime(now.getTime());
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId())), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(timerJob.getId(), responseNode.get("id").textValue());
    assertEquals(timerJob.getExceptionMessage(), responseNode.get("exceptionMessage").textValue());
    assertEquals(timerJob.getExecutionId(), responseNode.get("executionId").textValue());
    assertEquals(timerJob.getProcessDefinitionId(), responseNode.get("processDefinitionId").textValue());
    assertEquals(timerJob.getProcessInstanceId(), responseNode.get("processInstanceId").textValue());
    assertEquals(timerJob.getRetries(), responseNode.get("retries").intValue());
    assertEquals(timerJob.getDuedate(), getDateFromISOString(responseNode.get("dueDate").textValue()));
    assertEquals("", responseNode.get("tenantId").textValue());
    // Set tenant on deployment
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId())), HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("myTenant", responseNode.get("tenantId").textValue());
}
Also used : 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) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 98 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class GroupCollectionResourceTest method testGetGroups.

/**
   * Test getting all groups.
   */
@Deployment
public void testGetGroups() throws Exception {
    List<Group> savedGroups = new ArrayList<Group>();
    try {
        Group group1 = identityService.newGroup("testgroup1");
        group1.setName("Test group");
        group1.setType("Test type");
        identityService.saveGroup(group1);
        savedGroups.add(group1);
        Group group2 = identityService.newGroup("testgroup2");
        group2.setName("Another group");
        group2.setType("Another type");
        identityService.saveGroup(group2);
        savedGroups.add(group2);
        Group group3 = identityService.createGroupQuery().groupId("admin").singleResult();
        assertNotNull(group3);
        // Test filter-less
        String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION);
        assertResultsPresentInDataResponse(url, group1.getId(), group2.getId(), group3.getId());
        // Test based on name
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?name=" + encode("Test group");
        assertResultsPresentInDataResponse(url, group1.getId());
        // Test based on name like
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?nameLike=" + encode("% group");
        assertResultsPresentInDataResponse(url, group2.getId(), group1.getId());
        // Test based on type
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?type=" + encode("Another type");
        assertResultsPresentInDataResponse(url, group2.getId());
        // Test based on group member
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?member=kermit";
        assertResultsPresentInDataResponse(url, group3.getId());
        // Test based on potentialStarter
        String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey("simpleProcess").singleResult().getId();
        repositoryService.addCandidateStarterGroup(processDefinitionId, "admin");
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?potentialStarter=" + processDefinitionId;
        assertResultsPresentInDataResponse(url, group3.getId());
    } finally {
        // Delete groups after test passes or fails
        if (!savedGroups.isEmpty()) {
            for (Group group : savedGroups) {
                identityService.deleteGroup(group.getId());
            }
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) ArrayList(java.util.ArrayList) Deployment(org.activiti.engine.test.Deployment)

Example 99 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class WebServiceSimplisticTest method testWebResponseKeywordName.

@Deployment
public void testWebResponseKeywordName() throws Exception {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("PrefixVariable", "The counter has the value ");
    variables.put("SuffixVariable", ". Good news Keyword");
    ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey("webServiceInvocationWithSimplisticDataFlow", variables);
    waitForJobExecutorToProcessAllJobs(10000L, 250L);
    String response = (String) processEngine.getRuntimeService().getVariable(instance.getId(), "OutputVariable");
    assertEquals("The counter has the value -1. Good news Keyword", response);
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 100 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class WebServiceSimplisticTest method testWebResponseNoName.

@Deployment
public void testWebResponseNoName() throws Exception {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("PrefixVariable", "The counter has the value ");
    variables.put("SuffixVariable", ". Good news (NO NAME)");
    ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey("webServiceInvocationWithSimplisticDataFlow", variables);
    waitForJobExecutorToProcessAllJobs(10000L, 250L);
    String response = (String) processEngine.getRuntimeService().getVariable(instance.getId(), "OutputVariable");
    assertEquals("The counter has the value -1. Good news (NO NAME)", response);
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) 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