Search in sources :

Example 71 with Deployment

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

the class ProcessDefinitionResourceTest method testGetProcessDefinition.

/**
  * Test getting a single process definition.
  * GET repository/process-definitions/{processDefinitionResource}
  */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetProcessDefinition() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals(processDefinition.getId(), responseNode.get("id").textValue());
    assertEquals(processDefinition.getKey(), responseNode.get("key").textValue());
    assertEquals(processDefinition.getCategory(), responseNode.get("category").textValue());
    assertEquals(processDefinition.getVersion(), responseNode.get("version").intValue());
    assertEquals(processDefinition.getDescription(), responseNode.get("description").textValue());
    assertEquals(processDefinition.getName(), responseNode.get("name").textValue());
    assertFalse(responseNode.get("graphicalNotationDefined").booleanValue());
    // Check URL's
    assertEquals(httpGet.getURI().toString(), responseNode.get("url").asText());
    assertEquals(processDefinition.getDeploymentId(), responseNode.get("deploymentId").textValue());
    assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, processDefinition.getDeploymentId())));
    assertTrue(URLDecoder.decode(responseNode.get("resource").textValue(), "UTF-8").endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName())));
    assertTrue(responseNode.get("diagramResource").isNull());
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 72 with Deployment

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

the class ProcessDefinitionResourceTest method testGetProcessDefinitionWithGraphicalNotation.

/**
   * Test getting a single process definition with a graphical notation defined.
   * GET repository/process-definitions/{processDefinitionResource}
   */
@Deployment
public void testGetProcessDefinitionWithGraphicalNotation() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals(processDefinition.getId(), responseNode.get("id").textValue());
    assertEquals(processDefinition.getKey(), responseNode.get("key").textValue());
    assertEquals(processDefinition.getCategory(), responseNode.get("category").textValue());
    assertEquals(processDefinition.getVersion(), responseNode.get("version").intValue());
    assertEquals(processDefinition.getDescription(), responseNode.get("description").textValue());
    assertEquals(processDefinition.getName(), responseNode.get("name").textValue());
    assertTrue(responseNode.get("graphicalNotationDefined").booleanValue());
    // Check URL's
    assertEquals(httpGet.getURI().toString(), responseNode.get("url").asText());
    assertEquals(processDefinition.getDeploymentId(), responseNode.get("deploymentId").textValue());
    assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, processDefinition.getDeploymentId())));
    assertTrue(URLDecoder.decode(responseNode.get("resource").textValue(), "UTF-8").endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName())));
    assertTrue(URLDecoder.decode(responseNode.get("diagramResource").textValue(), "UTF-8").endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName())));
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 73 with Deployment

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

the class ProcessDefinitionResourceTest method testSuspendAlreadySuspendedProcessDefinition.

/**
   * Test suspending already suspended process definition.
   * POST repository/process-definitions/{processDefinitionId}
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testSuspendAlreadySuspendedProcessDefinition() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());
    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertTrue(processDefinition.isSuspended());
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "suspend");
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_CONFLICT);
    closeResponse(response);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 74 with Deployment

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

the class ExecutionVariableResourceTest method testGetExecutionVariable.

/**
   * Test getting an execution variable. GET
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutionVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");
    runtimeService.setVariable(processInstance.getId(), "variable", "processValue");
    Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
    assertNotNull(childExecution);
    runtimeService.setVariableLocal(childExecution.getId(), "variable", "childValue");
    // Get local scope variable
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "variable")), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("local", responseNode.get("scope").asText());
    assertEquals("childValue", responseNode.get("value").asText());
    assertEquals("variable", responseNode.get("name").asText());
    assertEquals("string", responseNode.get("type").asText());
    // Get global scope variable
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "variable") + "?scope=global"), HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("global", responseNode.get("scope").asText());
    assertEquals("processValue", responseNode.get("value").asText());
    assertEquals("variable", responseNode.get("name").asText());
    assertEquals("string", responseNode.get("type").asText());
    // Illegal scope
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, processInstance.getId(), "variable") + "?scope=illegal"), HttpStatus.SC_BAD_REQUEST);
    closeResponse(response);
    // Unexisting process
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, "unexisting", "variable")), HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
    // Unexisting variable
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, processInstance.getId(), "unexistingVariable")), HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
}
Also used : Execution(org.activiti.engine.runtime.Execution) 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 75 with Deployment

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

the class ExecutionVariableResourceTest method testGetExecutionVariableData.

/**
   * Test getting execution variable data.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutionVariableData() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");
    runtimeService.setVariableLocal(processInstance.getId(), "var", "This is a binary piece of text".getBytes());
    Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
    assertNotNull(childExecution);
    runtimeService.setVariableLocal(childExecution.getId(), "var", "This is a binary piece of text in the child execution".getBytes());
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, childExecution.getId(), "var")), HttpStatus.SC_OK);
    String actualResponseBytesAsText = IOUtils.toString(response.getEntity().getContent());
    closeResponse(response);
    assertEquals("This is a binary piece of text in the child execution", actualResponseBytesAsText);
    assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
    // Test global scope
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, childExecution.getId(), "var") + "?scope=global"), HttpStatus.SC_OK);
    actualResponseBytesAsText = IOUtils.toString(response.getEntity().getContent());
    closeResponse(response);
    assertEquals("This is a binary piece of text", actualResponseBytesAsText);
    assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
}
Also used : Execution(org.activiti.engine.runtime.Execution) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) 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