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());
}
}
}
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());
}
}
}
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));
}
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());
}
}
}
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
}
}
}
Aggregations