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