Search in sources :

Example 66 with StringEntity

use of org.apache.http.entity.StringEntity in project Activiti by Activiti.

the class TaskResourceTest method testInvalidTaskAction.

/**
   * Test executing an invalid action on a single task.
   * POST runtime/tasks/{taskId}
   */
public void testInvalidTaskAction() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        String taskId = task.getId();
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("action", "unexistingaction");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
        // Clean historic tasks with no runtime-counterpart
        List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().list();
        for (HistoricTaskInstance task : historicTasks) {
            historyService.deleteHistoricTaskInstance(task.getId());
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 67 with StringEntity

use of org.apache.http.entity.StringEntity in project Activiti by Activiti.

the class ProcessDefinitionResourceTest method testSuspendProcessDefinition.

/**
    * Test suspending a process definition.
    * POST repository/process-definitions/{processDefinitionId}
    */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testSuspendProcessDefinition() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertFalse(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_OK);
    // Check "OK" status
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertTrue(responseNode.get("suspended").booleanValue());
    // Check if process-definitoin is suspended
    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertTrue(processDefinition.isSuspended());
}
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) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 68 with StringEntity

use of org.apache.http.entity.StringEntity in project Activiti by Activiti.

the class ProcessDefinitionResourceTest method testActivateProcessDefinition.

/**
   * Test activating a suspended process definition.
   * POST repository/process-definitions/{processDefinitionId}
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testActivateProcessDefinition() 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", "activate");
    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_OK);
    // Check "OK" status
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertFalse(responseNode.get("suspended").booleanValue());
    // Check if process-definitoin is suspended
    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertFalse(processDefinition.isSuspended());
}
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) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 69 with StringEntity

use of org.apache.http.entity.StringEntity in project Activiti by Activiti.

the class ProcessDefinitionResourceTest method testIllegalAction.

/**
   * Test executing an unexisting action.
   * 
   * POST repository/process-definitions/{processDefinitionId}
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testIllegalAction() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertFalse(processDefinition.isSuspended());
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "unexistingaction");
    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_BAD_REQUEST);
    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 70 with StringEntity

use of org.apache.http.entity.StringEntity in project Activiti by Activiti.

the class ProcessDefinitionResourceTest method testSuspendProcessDefinitionDelayed.

/**
   * Test suspending a process definition on a certain date.
   * POST repository/process-definitions/{processDefinitionId}
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testSuspendProcessDefinitionDelayed() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertFalse(processDefinition.isSuspended());
    ObjectNode requestNode = objectMapper.createObjectNode();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, 2);
    // Format the date using ISO date format
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    String dateString = formatter.print(cal.getTimeInMillis());
    requestNode.put("action", "suspend");
    requestNode.put("date", dateString);
    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_OK);
    // Check "OK" status
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertTrue(responseNode.get("suspended").booleanValue());
    // Check if process-definition is not yet suspended
    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertFalse(processDefinition.isSuspended());
    // Force suspension by altering time
    cal.add(Calendar.HOUR, 1);
    processEngineConfiguration.getClock().setCurrentTime(cal.getTime());
    waitForJobExecutorToProcessAllJobs(5000, 100);
    // Check if process-definition is suspended
    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertTrue(processDefinition.isSuspended());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Calendar(java.util.Calendar) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Aggregations

StringEntity (org.apache.http.entity.StringEntity)456 HttpPost (org.apache.http.client.methods.HttpPost)249 HttpResponse (org.apache.http.HttpResponse)147 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)141 Test (org.junit.Test)105 HttpPut (org.apache.http.client.methods.HttpPut)94 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)88 IOException (java.io.IOException)84 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)68 HttpEntity (org.apache.http.HttpEntity)60 JsonNode (com.fasterxml.jackson.databind.JsonNode)54 Deployment (org.activiti.engine.test.Deployment)50 TestHttpClient (io.undertow.testutils.TestHttpClient)30 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)27 StatusLine (org.apache.http.StatusLine)27 HttpGet (org.apache.http.client.methods.HttpGet)27 Gson (com.google.gson.Gson)24 UnsupportedEncodingException (java.io.UnsupportedEncodingException)24 ProtocolVersion (org.apache.http.ProtocolVersion)24 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)23