Search in sources :

Example 36 with HttpPut

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

the class GroupResourceTest method testUpdateUnexistingGroup.

/**
   * Test updating an unexisting group.
   */
public void testUpdateUnexistingGroup() throws Exception {
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "unexisting"));
    httpPut.setEntity(new StringEntity(objectMapper.createObjectNode().toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpPut(org.apache.http.client.methods.HttpPut)

Example 37 with HttpPut

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

the class GroupResourceTest method testUpdateGroup.

/**
   * Test updating a single group.
   */
public void testUpdateGroup() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", "Updated group");
        requestNode.put("type", "Updated type");
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("testgroup", responseNode.get("id").textValue());
        assertEquals("Updated group", responseNode.get("name").textValue());
        assertEquals("Updated type", responseNode.get("type").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId())));
        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertNotNull(createdGroup);
        assertEquals("Updated group", createdGroup.getName());
        assertEquals("Updated type", createdGroup.getType());
    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
        // Ignore, since the group may not have been created in the test
        // or already deleted
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut)

Example 38 with HttpPut

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

the class GroupResourceTest method testUpdateGroupNoFields.

/**
   * Test updating a single group passing in no fields in the json, user should remain unchanged.
   */
public void testUpdateGroupNoFields() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);
        ObjectNode requestNode = objectMapper.createObjectNode();
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("testgroup", responseNode.get("id").textValue());
        assertEquals("Test group", responseNode.get("name").textValue());
        assertEquals("Test type", responseNode.get("type").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId())));
        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertNotNull(createdGroup);
        assertEquals("Test group", createdGroup.getName());
        assertEquals("Test type", createdGroup.getType());
    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
        // Ignore, since the group may not have been created in the test
        // or already deleted
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut)

Example 39 with HttpPut

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

the class ModelResourceSourceTest method testSetModelEditorSource.

public void testSetModelEditorSource() throws Exception {
    Model model = null;
    try {
        model = repositoryService.newModel();
        model.setName("Model name");
        repositoryService.saveModel(model);
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
        httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream", new ByteArrayInputStream("This is the new editor source".getBytes()), null));
        closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
        assertEquals("This is the new editor source", new String(repositoryService.getModelEditorSource(model.getId())));
    } finally {
        try {
            repositoryService.deleteModel(model.getId());
        } catch (Throwable ignore) {
        // Ignore, model might not be created
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.activiti.engine.repository.Model) HttpPut(org.apache.http.client.methods.HttpPut)

Example 40 with HttpPut

use of org.apache.http.client.methods.HttpPut 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)

Aggregations

HttpPut (org.apache.http.client.methods.HttpPut)153 StringEntity (org.apache.http.entity.StringEntity)89 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)50 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)40 HttpResponse (org.apache.http.HttpResponse)29 Test (org.junit.Test)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)27 Deployment (org.activiti.engine.test.Deployment)27 HttpPost (org.apache.http.client.methods.HttpPost)19 HttpGet (org.apache.http.client.methods.HttpGet)17 IOException (java.io.IOException)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 HttpDelete (org.apache.http.client.methods.HttpDelete)14 HttpEntity (org.apache.http.HttpEntity)13 URI (java.net.URI)12 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)12 HttpHead (org.apache.http.client.methods.HttpHead)11 Execution (org.activiti.engine.runtime.Execution)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)9