Search in sources :

Example 21 with HttpDelete

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

the class TaskEventResourceTest method testDeleteEvent.

/**
   * Test delete event for a task.
   * DELETE runtime/tasks/{taskId}/events/{eventId}
   */
public void testDeleteEvent() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        taskService.setAssignee(task.getId(), "kermit");
        taskService.addUserIdentityLink(task.getId(), "gonzo", "someType");
        List<Event> events = taskService.getTaskEvents(task.getId());
        assertEquals(2, events.size());
        for (Event event : events) {
            HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_EVENT, task.getId(), event.getId()));
            closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
        }
        events = taskService.getTaskEvents(task.getId());
        assertEquals(0, events.size());
    } 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 : Task(org.activiti.engine.task.Task) HttpDelete(org.apache.http.client.methods.HttpDelete) Event(org.activiti.engine.task.Event)

Example 22 with HttpDelete

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

the class ProcessInstanceVariableResourceTest method testDeleteProcessVariable.

/**
   * Test deleting a single process variable in, including "not found" check.
   * 
   * DELETE runtime/process-instances/{processInstanceId}/variables/{variableName}
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testDeleteProcessVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("myVariable", (Object) "processValue"));
    // Delete variable
    closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVariable")), HttpStatus.SC_NO_CONTENT));
    assertFalse(runtimeService.hasVariable(processInstance.getId(), "myVariable"));
    // Run the same delete again, variable is not there so 404 should be returned
    closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVariable")), HttpStatus.SC_NOT_FOUND));
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 23 with HttpDelete

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

the class ProcessDefinitionIdentityLinksResourceTest method testDeleteCandidateStarterFromProcessDefinition.

@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testDeleteCandidateStarterFromProcessDefinition() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    repositoryService.addCandidateStarterGroup(processDefinition.getId(), "admin");
    repositoryService.addCandidateStarterUser(processDefinition.getId(), "kermit");
    // Delete user candidate
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINK, processDefinition.getId(), "users", "kermit"));
    CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
    // Check if group-link remains
    List<IdentityLink> remainingLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
    assertEquals(1, remainingLinks.size());
    assertEquals("admin", remainingLinks.get(0).getGroupId());
    // Delete group candidate
    httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINK, processDefinition.getId(), "groups", "admin"));
    response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
    // Check if all links are removed
    remainingLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
    assertEquals(0, remainingLinks.size());
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 24 with HttpDelete

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

the class ExecutionVariableResourceTest method testDeleteExecutionVariable.

/**
   * Test deleting a single execution variable, including "not found" check.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testDeleteExecutionVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", Collections.singletonMap("myVariable", (Object) "processValue"));
    Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
    assertNotNull(childExecution);
    runtimeService.setVariableLocal(childExecution.getId(), "myVariable", "childValue");
    // Delete variable local
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVariable"));
    CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
    assertFalse(runtimeService.hasVariableLocal(childExecution.getId(), "myVariable"));
    // Global variable should remain unaffected
    assertTrue(runtimeService.hasVariable(childExecution.getId(), "myVariable"));
    // Delete variable global
    httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVariable") + "?scope=global");
    response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
    assertFalse(runtimeService.hasVariableLocal(childExecution.getId(), "myVariable"));
    assertFalse(runtimeService.hasVariable(childExecution.getId(), "myVariable"));
    // Run the same delete again, variable is not there so 404 should be returned
    response = executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
}
Also used : Execution(org.activiti.engine.runtime.Execution) HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 25 with HttpDelete

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

the class ModelResourceTest method testDeleteModel.

public void testDeleteModel() throws Exception {
    Model model = null;
    try {
        Calendar now = Calendar.getInstance();
        now.set(Calendar.MILLISECOND, 0);
        processEngineConfiguration.getClock().setCurrentTime(now.getTime());
        model = repositoryService.newModel();
        model.setCategory("Model category");
        model.setKey("Model key");
        model.setMetaInfo("Model metainfo");
        model.setName("Model name");
        model.setVersion(2);
        repositoryService.saveModel(model);
        HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
        closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
        // Check if the model is really gone
        assertNull(repositoryService.createModelQuery().modelId(model.getId()).singleResult());
        model = null;
    } finally {
        if (model != null) {
            try {
                repositoryService.deleteModel(model.getId());
            } catch (Throwable ignore) {
            // Ignore, model might not be created
            }
        }
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Calendar(java.util.Calendar) Model(org.activiti.engine.repository.Model)

Aggregations

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