Search in sources :

Example 61 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserInfoResourceTest method testUpdateUnexistingInfo.

/**
   * Test deleting the info for a user who doesn't have that info set
   */
public void testUpdateUnexistingInfo() 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 requestNode = objectMapper.createObjectNode();
        requestNode.put("value", "Updated value");
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "testuser", "key1"));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
    } finally {
        // Delete user after test passes or 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) HttpPut(org.apache.http.client.methods.HttpPut)

Example 62 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserPictureResourceTest method testGetPictureForUserWithoutPicture.

/**
   * Test getting the picture for a user who doesn't have a îcture set
   */
public void testGetPictureForUserWithoutPicture() 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;
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId())), HttpStatus.SC_NOT_FOUND);
        // response content type application/json;charset=UTF-8
        assertEquals("application/json", response.getEntity().getContentType().getValue().split(";")[0]);
        closeResponse(response);
    } finally {
        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : User(org.activiti.engine.identity.User) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 63 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserPictureResourceTest method testUpdatePicture.

public void testUpdatePicture() 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;
        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()), null));
        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) ByteArrayInputStream(java.io.ByteArrayInputStream) Picture(org.activiti.engine.identity.Picture) HttpPut(org.apache.http.client.methods.HttpPut)

Example 64 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserPictureResourceTest method testGetUserPicture.

/**
   * Test getting the picture for a user.
   */
public void testGetUserPicture() 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;
        // Create picture for user
        Picture thePicture = new Picture("this is the picture raw byte stream".getBytes(), "image/png");
        identityService.setUserPicture(newUser.getId(), thePicture);
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId())), HttpStatus.SC_OK);
        assertEquals("this is the picture raw byte stream", IOUtils.toString(response.getEntity().getContent()));
        // Check if media-type is correct
        assertEquals("image/png", response.getEntity().getContentType().getValue());
        closeResponse(response);
    } finally {
        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}
Also used : User(org.activiti.engine.identity.User) Picture(org.activiti.engine.identity.Picture) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 65 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class GroupMembershipResourceTest method testCreateMembershipAlreadyExisting.

public void testCreateMembershipAlreadyExisting() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);
        User testUser = identityService.newUser("testuser");
        identityService.saveUser(testUser);
        identityService.createMembership("testuser", "testgroup");
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("userId", "testuser");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_MEMBERSHIP_COLLECTION, "testgroup"));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT));
    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
        // Ignore, since the group may not have been created in the test
        // or already deleted
        }
        try {
            identityService.deleteUser("testuser");
        } 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) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) User(org.activiti.engine.identity.User) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Aggregations

User (org.activiti.engine.identity.User)94 Group (org.activiti.engine.identity.Group)22 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 Task (org.activiti.engine.task.Task)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)9 Picture (org.activiti.engine.identity.Picture)9 StringEntity (org.apache.http.entity.StringEntity)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ArrayList (java.util.ArrayList)7 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)7 HttpPut (org.apache.http.client.methods.HttpPut)7 HttpGet (org.apache.http.client.methods.HttpGet)6 UserQuery (org.activiti.engine.identity.UserQuery)5 HttpDelete (org.apache.http.client.methods.HttpDelete)5 HttpPost (org.apache.http.client.methods.HttpPost)4 Item (com.vaadin.data.Item)3 ActivitiException (org.activiti.engine.ActivitiException)3 IdentityService (org.activiti.engine.IdentityService)3