use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionsWhereClause.
@Test
public void testGetProcessDefinitionsWhereClause() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
// Filter on category equals
Map<String, ProcessDefinition> processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')");
assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
assertTrue(processDefinitionMap.containsKey("activitiReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(5, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'unexisting')");
assertEquals(0, processDefinitionMap.size());
// Filter on name equals
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name = 'Adhoc Activiti Process')");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name = 'unexisting')");
assertEquals(0, processDefinitionMap.size());
// Filter on key equals
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key='activitiAdhoc')");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key='unexisting')");
assertEquals(0, processDefinitionMap.size());
// Filter on version equals
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(version='1')");
assertEquals(5, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(version='2')");
assertEquals(0, processDefinitionMap.size());
// Filter on deploymentId equals
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(deploymentId='" + activitiDefinition.getDeploymentId() + "')");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(deploymentId='unexisting')");
assertEquals(0, processDefinitionMap.size());
// Filter on category matches
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category matches('%alfresco.o%'))");
assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
assertTrue(processDefinitionMap.containsKey("activitiReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(5, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category matches('unexisting'))");
assertEquals(0, processDefinitionMap.size());
// Filter on name matches
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name matches('Adhoc Activiti %'))");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name matches('unexisting'))");
assertEquals(0, processDefinitionMap.size());
// Filter on key matches
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key matches('activitiAd%'))");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
// Use AND operator
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org' AND name = 'Adhoc Activiti Process')");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
// Use OR operator
try {
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org' OR name = 'Adhoc Activiti Process')");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(400, e.getHttpResponse().getStatusCode());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionsSorting.
@Test
public void testGetProcessDefinitionsSorting() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
List<ProcessDefinition> processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "name");
assertEquals(5, processDefinitions.size());
List<String> expectedNames = Arrays.asList("Adhoc Activiti Process", "Parallel Group Review And Approve Activiti Process", "Parallel Review And Approve Activiti Process", "Pooled Review And Approve Activiti Process", "Review And Approve Activiti Process");
List<String> names = collect(processDefinitions, new Collector() {
@Override
public String collect(ProcessDefinition definition) {
return definition.getName();
}
});
assertEquals(expectedNames, names);
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "name DESC");
assertEquals(5, processDefinitions.size());
names = collect(processDefinitions, new Collector() {
@Override
public String collect(ProcessDefinition definition) {
return definition.getName();
}
});
Collections.reverse(expectedNames);
assertEquals(expectedNames, names);
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "version DESC");
// all the same version so no sorting
assertEquals(5, processDefinitions.size());
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "id ASC");
assertEquals(5, processDefinitions.size());
List<String> ids = collect(processDefinitions, new Collector() {
@Override
public String collect(ProcessDefinition definition) {
return definition.getId();
}
});
List<String> sortedIds = new ArrayList<>(ids);
Collections.sort(sortedIds);
assertEquals(sortedIds, ids);
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "category ASC");
// all the same
assertEquals(5, processDefinitions.size());
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "key DESC");
assertEquals(5, processDefinitions.size());
List<String> keys = collect(processDefinitions, new Collector() {
@Override
public String collect(ProcessDefinition definition) {
return definition.getKey();
}
});
List<String> sortedKeys = new ArrayList<>(keys);
// order
Collections.sort(sortedKeys);
// reverse order
Collections.reverse(sortedKeys);
assertEquals(sortedKeys, keys);
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "deploymentId ASC");
assertEquals(5, processDefinitions.size());
List<String> deploymentIds = collect(processDefinitions, new Collector() {
@Override
public String collect(ProcessDefinition definition) {
return definition.getDeploymentId();
}
});
List<String> sortedDeploymentIds = new ArrayList<>(deploymentIds);
Collections.sort(sortedDeploymentIds);
assertEquals(sortedDeploymentIds, deploymentIds);
try {
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "sausage ASC");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(400, e.getHttpResponse().getStatusCode());
assertTrue(e.getMessage().contains("OrderBy sausage is not supported, supported items are"));
}
try {
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "deploymentId ASC, key");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(400, e.getHttpResponse().getStatusCode());
assertTrue(e.getHttpResponse().getResponse().contains("Only one orderBy parameter is supported"));
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testDeleteProcessInstanceById.
@Test
public void testDeleteProcessInstanceById() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
final 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);
ProcessesClient processesClient = publicApiClient.processesClient();
// delete with user starting the process instance
ProcessInfo process = startAdhocProcess(requestContext, null);
try {
processesClient.deleteProcessById(process.getId());
// Check if the process was actually deleted
assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
assertNotNull(deletedInstance);
assertNotNull(deletedInstance.getEndTime());
assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
try {
processesClient.deleteProcessById(process.getId());
fail("expected exeception");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(process.getId());
}
// delete with admin in same network as the user starting the process instance
process = startAdhocProcess(requestContext, null);
try {
publicApiClient.setRequestContext(adminContext);
processesClient.deleteProcessById(process.getId());
// Check if the process was actually deleted
assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
assertNotNull(deletedInstance);
assertNotNull(deletedInstance.getEndTime());
assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
} finally {
cleanupProcessInstance(process.getId());
}
// delete with admin from other network as the user starting the process instance
process = startAdhocProcess(requestContext, null);
try {
publicApiClient.setRequestContext(otherContext);
processesClient.deleteProcessById(process.getId());
fail("Expect permission exception");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
} finally {
cleanupProcessInstance(process.getId());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testCreateProcessInstanceWithKey.
@Test
@SuppressWarnings("unchecked")
public void testCreateProcessInstanceWithKey() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject createProcessObject = new JSONObject();
createProcessObject.put("processDefinitionKey", "activitiAdhoc");
final JSONObject variablesObject = new JSONObject();
variablesObject.put("bpm_dueDate", "2013-09-30T00:00:00.000+0300");
variablesObject.put("bpm_priority", 1);
variablesObject.put("bpm_description", "test description");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
createProcessObject.put("variables", variablesObject);
ProcessInfo processRest = processesClient.createProcess(createProcessObject.toJSONString());
assertNotNull(processRest);
Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
assertEquals("test description", variables.get("bpm_description"));
assertEquals(1, variables.get("bpm_priority"));
cleanupProcessInstance(processRest.getId());
// Test same create method with an admin user
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(requestContext.getNetworkId(), tenantAdmin));
processRest = processesClient.createProcess(createProcessObject.toJSONString());
assertNotNull(processRest);
variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
assertEquals("test description", variables.get("bpm_description"));
assertEquals(1, variables.get("bpm_priority"));
cleanupProcessInstance(processRest.getId());
// Test create process with wrong key
publicApiClient.setRequestContext(requestContext);
createProcessObject = new JSONObject();
createProcessObject.put("processDefinitionKey", "activitiAdhoc2");
try {
processRest = processesClient.createProcess(createProcessObject.toJSONString());
fail();
} catch (PublicApiException e) {
// Exception expected because of wrong process definition key
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
assertErrorSummary("No workflow definition could be found with key 'activitiAdhoc2'.", e.getHttpResponse());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstanceByIdUnexisting.
@Test
public void testGetProcessInstanceByIdUnexisting() throws Exception {
initApiClientWithTestUser();
ProcessesClient processesClient = publicApiClient.processesClient();
try {
processesClient.findProcessById("unexisting");
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
}
}
Aggregations