Search in sources :

Example 16 with HttpDelete

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

the class TaskVariableResourceTest method testDeleteTaskVariable.

/**
   * Test deleting a single task variable in all scopes, including "not found" check.
   * 
   * DELETE runtime/tasks/{taskId}/variables/{variableName}
   */
@Deployment
public void testDeleteTaskVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "overlappingVariable", "taskValue");
    taskService.setVariableLocal(task.getId(), "anotherTaskVariable", "taskValue");
    // Delete variable without scope, local should be presumed -> local removed and global should be retained
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable"));
    closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
    assertFalse(taskService.hasVariableLocal(task.getId(), "overlappingVariable"));
    assertTrue(taskService.hasVariable(task.getId(), "overlappingVariable"));
    // Delete local scope variable
    httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "anotherTaskVariable") + "?scope=local");
    closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
    assertFalse(taskService.hasVariableLocal(task.getId(), "anotherTaskVariable"));
    // Delete global scope variable
    assertTrue(taskService.hasVariable(task.getId(), "overlappingVariable"));
    httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable") + "?scope=global");
    closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
    assertFalse(taskService.hasVariable(task.getId(), "overlappingVariable"));
    // Run the same delete again, variable is not there so 404 should be returned
    closeResponse(executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND));
}
Also used : Task(org.activiti.engine.task.Task) HttpDelete(org.apache.http.client.methods.HttpDelete) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 17 with HttpDelete

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

the class TaskVariablesCollectionResourceTest method testDeleteAllLocalVariables.

/**
   * Test deleting all local task variables.
   * DELETE runtime/tasks/{taskId}/variables
   */
@Deployment
public void testDeleteAllLocalVariables() throws Exception {
    // Start process with all types of variables
    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("var1", "This is a ProcVariable");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    // Set local task variables
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    Map<String, Object> taskVariables = new HashMap<String, Object>();
    taskVariables.put("var1", "This is a TaskVariable");
    taskVariables.put("var2", 123);
    taskService.setVariablesLocal(task.getId(), taskVariables);
    assertEquals(2, taskService.getVariablesLocal(task.getId()).size());
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
    closeResponse(executeBinaryRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
    // Check if local variables are gone and global remain unchanged
    assertEquals(0, taskService.getVariablesLocal(task.getId()).size());
    assertEquals(1, taskService.getVariables(task.getId()).size());
}
Also used : Task(org.activiti.engine.task.Task) HttpDelete(org.apache.http.client.methods.HttpDelete) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 18 with HttpDelete

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

the class HistoricProcessInstanceResourceTest method testGetProcessInstance.

/**
   * Test retrieval of historic process instance. 
   * GET history/historic-process-instances/{processInstanceId}
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder().processDefinitionKey("oneTaskProcess").processInstanceName("processName").start();
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, processInstance.getId())), HttpStatus.SC_OK);
    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertEquals("processName", responseNode.get("name").textValue());
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    taskService.complete(task.getId());
    response = executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, processInstance.getId())), HttpStatus.SC_NO_CONTENT);
    assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusLine().getStatusCode());
    closeResponse(response);
}
Also used : Task(org.activiti.engine.task.Task) HttpDelete(org.apache.http.client.methods.HttpDelete) 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 19 with HttpDelete

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

the class JobResourceTest method testDeleteJob.

/**
   * Test deleting a single job. 
   */
@Deployment(resources = { "org/activiti/rest/service/api/management/JobResourceTest.testTimerProcess.bpmn20.xml" })
public void testDeleteJob() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId()));
    CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
    // Job should be deleted
    assertNull(managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult());
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) 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 20 with HttpDelete

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

the class UserInfoResourceTest method testDeleteInfoForUserWithoutInfo.

/**
   * Test deleting the info for a user who doesn't have that info set
   */
public void testDeleteInfoForUserWithoutInfo() throws Exception {
    User savedUser = null;
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("no-reply@activiti.org");
        identityService.saveUser(newUser);
        savedUser = newUser;
        closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "testuser", "key1")), HttpStatus.SC_NOT_FOUND));
    } finally {
        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : User(org.activiti.engine.identity.User) HttpDelete(org.apache.http.client.methods.HttpDelete)

Aggregations

HttpDelete (org.apache.http.client.methods.HttpDelete)95 HttpResponse (org.apache.http.HttpResponse)21 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)19 Test (org.junit.Test)17 HttpPut (org.apache.http.client.methods.HttpPut)14 HttpGet (org.apache.http.client.methods.HttpGet)13 Deployment (org.activiti.engine.test.Deployment)12 HttpPost (org.apache.http.client.methods.HttpPost)12 IOException (java.io.IOException)11 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)11 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)11 Task (org.activiti.engine.task.Task)9 StringEntity (org.apache.http.entity.StringEntity)7 RequestExecutor (org.apache.stanbol.commons.testing.http.RequestExecutor)7 HttpEntity (org.apache.http.HttpEntity)6 URI (java.net.URI)5 User (org.activiti.engine.identity.User)5 Header (org.apache.http.Header)5 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)5 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)5