use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testMethodNotAllowedURIs.
@Test
public void testMethodNotAllowedURIs() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
HttpResponse response = publicApiClient.get("public", "process-definitions", null, null, null, null);
assertEquals(200, response.getStatusCode());
response = publicApiClient.post("public", "process-definitions", null, null, null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.delete("public", "process-definitions", null, null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.put("public", "process-definitions", null, null, null, null, null);
assertEquals(405, response.getStatusCode());
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(processDefinition);
response = publicApiClient.get("public", "process-definitions", processDefinition.getId(), null, null, null);
assertEquals(200, response.getStatusCode());
response = publicApiClient.post("public", "process-definitions", processDefinition.getId(), null, null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.delete("public", "process-definitions", processDefinition.getId(), null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.put("public", "process-definitions", processDefinition.getId(), null, null, null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.get("public", "process-definitions", processDefinition.getId(), "start-form-model", null, null);
assertEquals(200, response.getStatusCode());
response = publicApiClient.post("public", "process-definitions", processDefinition.getId(), "start-form-model", null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.delete("public", "process-definitions", processDefinition.getId(), "start-form-model", null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.put("public", "process-definitions", processDefinition.getId(), "start-form-model", null, null, null);
assertEquals(405, response.getStatusCode());
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitions.
@Test
public void testGetProcessDefinitions() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
// Get all process definitions
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
ListResponse<ProcessDefinition> processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(null);
Map<String, ProcessDefinition> processDefinitionMap = getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
assertTrue(processDefinitionMap.containsKey("activitiReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(5, processDefinitionMap.size());
// Check fields of a resulting process-definition
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
ProcessDefinition adhocDefinitionRest = processDefinitionMap.get("activitiAdhoc");
assertEquals(activitiDefinition.getId(), adhocDefinitionRest.getId());
assertEquals("activitiAdhoc", adhocDefinitionRest.getKey());
assertEquals(activitiDefinition.getDeploymentId(), adhocDefinitionRest.getDeploymentId());
assertEquals(activitiDefinition.getCategory(), adhocDefinitionRest.getCategory());
assertEquals(activitiDefinition.getName(), adhocDefinitionRest.getName());
assertEquals(activitiDefinition.getVersion(), adhocDefinitionRest.getVersion());
assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinitionRest.isGraphicNotationDefined());
assertEquals("wf:submitAdhocTask", adhocDefinitionRest.getStartFormResourceKey());
assertEquals("New Task", adhocDefinitionRest.getTitle());
assertEquals("Assign a new task to yourself or a colleague", adhocDefinitionRest.getDescription());
Map<String, String> params = new HashMap<String, String>();
params.put("maxItems", "2");
JSONObject definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
JSONObject paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "2");
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "5");
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "0");
params.put("maxItems", "7");
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testMethodNotAllowedURIs.
@Test
public void testMethodNotAllowedURIs() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
HttpResponse response = publicApiClient.get("public", "processes", null, null, null, null);
assertEquals(200, response.getStatusCode());
response = publicApiClient.put("public", "processes", null, null, null, null, null);
assertEquals(405, response.getStatusCode());
final ProcessInfo processInfo = startAdhocProcess(requestContext, null);
try {
response = publicApiClient.get("public", "processes", processInfo.getId(), null, null, null);
assertEquals(200, response.getStatusCode());
response = publicApiClient.post("public", "processes", processInfo.getId(), null, null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.put("public", "processes", processInfo.getId(), null, null, null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.get("public", "processes", processInfo.getId(), "activities", null, null);
assertEquals(200, response.getStatusCode());
response = publicApiClient.post("public", "processes", processInfo.getId(), "activities", null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.delete("public", "processes", processInfo.getId(), "activities", null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.put("public", "processes", processInfo.getId(), "activities", null, null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.get("public", "processes", processInfo.getId(), "tasks", null, null);
assertEquals(200, response.getStatusCode());
response = publicApiClient.post("public", "processes", processInfo.getId(), "tasks", null, null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.delete("public", "processes", processInfo.getId(), "tasks", null);
assertEquals(405, response.getStatusCode());
response = publicApiClient.put("public", "processes", processInfo.getId(), "tasks", null, null, null);
assertEquals(405, response.getStatusCode());
} finally {
cleanupProcessInstance(processInfo.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessVariables.
@Test
public void testGetProcessVariables() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
final RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
ProcessInfo processRest = startAdhocProcess(requestContext, null);
try {
assertNotNull(processRest);
String processInstanceId = processRest.getId();
JSONObject processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
assertNotNull(processvariables);
validateVariablesResponse(processvariables, requestContext.getRunAsUser());
// get variables with admin from same network
publicApiClient.setRequestContext(adminContext);
processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
assertNotNull(processvariables);
validateVariablesResponse(processvariables, requestContext.getRunAsUser());
// get variables with admin from other network
publicApiClient.setRequestContext(otherContext);
try {
processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
fail("forbidden expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
}
// get variables with non existing process id
try {
processvariables = publicApiClient.processesClient().getProcessvariables("fakeid");
fail("not found expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method getProcessImage.
@Test
public void getProcessImage() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo processRest = startAdhocProcess(requestContext, null);
HttpResponse response = publicApiClient.processesClient().getImage(processRest.getId());
assertEquals(200, response.getStatusCode());
cleanupProcessInstance(processRest.getId());
try {
response = publicApiClient.processesClient().getImage("fakeId");
fail("Exception expected");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
}
Aggregations