Search in sources :

Example 41 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.

the class ProcessInstanceIdentityLinkResourceTest method testGetSingleIdentityLink.

/**
   * Test getting a single identity link for a process instance.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceIdentityLinkResourceTest.process.bpmn20.xml" })
public void testGetSingleIdentityLink() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    runtimeService.addUserIdentityLink(processInstance.getId(), "kermit", "myType");
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, processInstance.getId(), "kermit", "myType")), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("kermit", responseNode.get("user").textValue());
    assertEquals("myType", responseNode.get("type").textValue());
    assertTrue(responseNode.get("group").isNull());
    assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, processInstance.getId(), "kermit", "myType")));
    // Test with unexisting process
    closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS, "kermit", "myType")), HttpStatus.SC_NOT_FOUND));
}
Also used : 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 42 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.

the class ProcessInstanceResourceTest method testGetProcessInstance.

/**
   * Test getting a single process instance.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testGetProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder().processDefinitionKey("processOne").businessKey("myBusinessKey").processInstanceName("myProcessName").start();
    String url = buildUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId());
    CloseableHttpResponse response = executeRequest(new HttpGet(url), HttpStatus.SC_OK);
    // Check resulting instance
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertEquals("myBusinessKey", responseNode.get("businessKey").textValue());
    assertEquals("myProcessName", responseNode.get("name").textValue());
    assertEquals("processTask", responseNode.get("activityId").textValue());
    assertFalse(responseNode.get("suspended").booleanValue());
    assertEquals("", responseNode.get("tenantId").textValue());
    assertTrue(responseNode.get("url").asText().equals(url));
    assertTrue(responseNode.get("processDefinitionUrl").asText().equals(buildUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));
    // Check result after tenant has been changed
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())), HttpStatus.SC_OK);
    // Check resulting instance tenant id
    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) 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 43 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.

the class ProcessInstanceResourceTest method testSuspendProcessInstance.

/**
   * Test suspending a single process instance.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testSuspendProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "suspend");
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
    // Check engine id instance is suspended
    assertEquals(1, runtimeService.createProcessInstanceQuery().suspended().processInstanceId(processInstance.getId()).count());
    // Check resulting instance is suspended
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("suspended").booleanValue());
    // Suspending again should result in conflict
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}
Also used : 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) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 44 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.

the class ProcessInstanceResourceTest method testActivateProcessInstance.

/**
   * Test suspending a single process instance.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testActivateProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "activate");
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
    // Check engine id instance is suspended
    assertEquals(1, runtimeService.createProcessInstanceQuery().active().processInstanceId(processInstance.getId()).count());
    // Check resulting instance is suspended
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertFalse(responseNode.get("suspended").booleanValue());
    // Activating again should result in conflict
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}
Also used : 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) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 45 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.

the class TaskAttachmentResourceTest method testCreateAttachment.

/**
   * Test creating a single attachments for a task
   * POST runtime/tasks/{taskId}/attachments/{attachmentId}
   */
public void testCreateAttachment() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", "Simple attachment");
        requestNode.put("description", "Simple attachment description");
        requestNode.put("type", "simpleType");
        requestNode.put("externalUrl", "http://activiti.org");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        // Check if attachment is created
        List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
        assertEquals(1, attachments.size());
        Attachment urlAttachment = attachments.get(0);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertEquals(urlAttachment.getId(), responseNode.get("id").textValue());
        assertEquals("simpleType", responseNode.get("type").textValue());
        assertEquals("Simple attachment", responseNode.get("name").textValue());
        assertEquals("Simple attachment description", responseNode.get("description").textValue());
        assertEquals("http://activiti.org", responseNode.get("externalUrl").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())));
        assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
        assertTrue(responseNode.get("contentUrl").isNull());
        assertTrue(responseNode.get("processInstanceUrl").isNull());
        assertFalse(responseNode.get("time").isNull());
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Attachment(org.activiti.engine.task.Attachment) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1314 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)502 HttpGet (org.apache.http.client.methods.HttpGet)485 Test (org.junit.Test)370 IOException (java.io.IOException)362 HttpPost (org.apache.http.client.methods.HttpPost)286 HttpEntity (org.apache.http.HttpEntity)248 StringEntity (org.apache.http.entity.StringEntity)229 JsonNode (com.fasterxml.jackson.databind.JsonNode)126 StatusLine (org.apache.http.StatusLine)121 URI (java.net.URI)118 InputStream (java.io.InputStream)112 ArrayList (java.util.ArrayList)87 Deployment (org.activiti.engine.test.Deployment)87 RequestConfig (org.apache.http.client.config.RequestConfig)87 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)87 HttpPut (org.apache.http.client.methods.HttpPut)79 Map (java.util.Map)75 Header (org.apache.http.Header)75 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)73