Search in sources :

Example 31 with HttpPut

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

the class UserResourceTest method testUpdateUserNoFields.

/**
   * Test updating a single user passing in no fields in the json, user should remain unchanged.
   */
public void testUpdateUserNoFields() 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;
        ObjectNode taskUpdateRequest = objectMapper.createObjectNode();
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()));
        httpPut.setEntity(new StringEntity(taskUpdateRequest.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("testuser", responseNode.get("id").textValue());
        assertEquals("Fred", responseNode.get("firstName").textValue());
        assertEquals("McDonald", responseNode.get("lastName").textValue());
        assertEquals("no-reply@activiti.org", responseNode.get("email").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())));
        // Check user is updated in activiti
        newUser = identityService.createUserQuery().userId(newUser.getId()).singleResult();
        assertEquals("McDonald", newUser.getLastName());
        assertEquals("Fred", newUser.getFirstName());
        assertEquals("no-reply@activiti.org", newUser.getEmail());
        assertNull(newUser.getPassword());
    } finally {
        // Delete user after test fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) User(org.activiti.engine.identity.User) 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 32 with HttpPut

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

the class UserResourceTest method testUpdateUser.

/**
   * Test updating a single user.
   */
public void testUpdateUser() 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;
        ObjectNode taskUpdateRequest = objectMapper.createObjectNode();
        taskUpdateRequest.put("firstName", "Tijs");
        taskUpdateRequest.put("lastName", "Barrez");
        taskUpdateRequest.put("email", "no-reply@alfresco.org");
        taskUpdateRequest.put("password", "updatedpassword");
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()));
        httpPut.setEntity(new StringEntity(taskUpdateRequest.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("testuser", responseNode.get("id").textValue());
        assertEquals("Tijs", responseNode.get("firstName").textValue());
        assertEquals("Barrez", responseNode.get("lastName").textValue());
        assertEquals("no-reply@alfresco.org", responseNode.get("email").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())));
        // Check user is updated in activiti
        newUser = identityService.createUserQuery().userId(newUser.getId()).singleResult();
        assertEquals("Barrez", newUser.getLastName());
        assertEquals("Tijs", newUser.getFirstName());
        assertEquals("no-reply@alfresco.org", newUser.getEmail());
        assertEquals("updatedpassword", newUser.getPassword());
    } finally {
        // Delete user after test fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) User(org.activiti.engine.identity.User) 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 33 with HttpPut

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

the class UserInfoResourceTest method testUpdateInfoForUnexistingUser.

/**
   * Test update the info for an unexisting user.
   */
public void testUpdateInfoForUnexistingUser() throws Exception {
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("value", "Updated value");
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "unexisting", "key1"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HttpPut(org.apache.http.client.methods.HttpPut)

Example 34 with HttpPut

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

the class UserPictureResourceTest method testUpdatePictureWithCustomMimeType.

public void testUpdatePictureWithCustomMimeType() 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;
        Map<String, String> additionalFields = new HashMap<String, String>();
        additionalFields.put("mimeType", MediaType.IMAGE_PNG.toString());
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId()));
        httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("myPicture.png", "image/png", new ByteArrayInputStream("this is the picture raw byte stream".getBytes()), additionalFields));
        closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
        Picture picture = identityService.getUserPicture(newUser.getId());
        assertNotNull(picture);
        assertEquals("image/png", picture.getMimeType());
        assertEquals("this is the picture raw byte stream", new String(picture.getBytes()));
    } finally {
        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : User(org.activiti.engine.identity.User) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Picture(org.activiti.engine.identity.Picture) HttpPut(org.apache.http.client.methods.HttpPut)

Example 35 with HttpPut

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

the class GroupResourceTest method testUpdateGroupNullFields.

/**
   * Test updating a single user passing in null-values.
   */
public void testUpdateGroupNullFields() 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", (JsonNode) null);
        requestNode.put("type", (JsonNode) null);
        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());
        assertNull(responseNode.get("name").textValue());
        assertNull(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);
        assertNull(createdGroup.getName());
        assertNull(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)

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