use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionStartModelUnexisting.
@Test
public void testGetProcessDefinitionStartModelUnexisting() throws Exception {
initApiClientWithTestUser();
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
try {
processDefinitionsClient.findStartFormModel("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());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionStartModel.
@Test
public void testGetProcessDefinitionStartModel() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
JSONObject model = processDefinitionsClient.findStartFormModel(activitiDefinition.getId());
assertNotNull(model);
JSONArray entries = (JSONArray) model.get("entries");
assertNotNull(entries);
// Add all entries to a map, to make lookup easier
Map<String, JSONObject> modelFieldsByName = new HashMap<String, JSONObject>();
JSONObject entry = null;
for (int i = 0; i < entries.size(); i++) {
entry = (JSONObject) entries.get(i);
assertNotNull(entry);
entry = (JSONObject) entry.get("entry");
assertNotNull(entry);
modelFieldsByName.put((String) entry.get("name"), entry);
}
// Check well-known properties and their types
// Validate bpm:description
JSONObject modelEntry = modelFieldsByName.get("bpm_workflowDescription");
assertNotNull(modelEntry);
assertEquals("Description", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/bpm/1.0}workflowDescription", modelEntry.get("qualifiedName"));
assertEquals("d:text", modelEntry.get("dataType"));
assertFalse((Boolean) modelEntry.get("required"));
// Validate bpm:description
modelEntry = modelFieldsByName.get("bpm_completionDate");
assertNotNull(modelEntry);
assertEquals("Completion Date", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/bpm/1.0}completionDate", modelEntry.get("qualifiedName"));
assertEquals("d:date", modelEntry.get("dataType"));
assertFalse((Boolean) modelEntry.get("required"));
// Validate cm:owner
modelEntry = modelFieldsByName.get("cm_owner");
assertNotNull(modelEntry);
assertEquals("Owner", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/content/1.0}owner", modelEntry.get("qualifiedName"));
assertEquals("d:text", modelEntry.get("dataType"));
assertFalse((Boolean) modelEntry.get("required"));
// Validate bpm:sendEmailNotifications
modelEntry = modelFieldsByName.get("bpm_sendEMailNotifications");
assertNotNull(modelEntry);
assertEquals("Send Email Notifications", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/bpm/1.0}sendEMailNotifications", modelEntry.get("qualifiedName"));
assertEquals("d:boolean", modelEntry.get("dataType"));
assertFalse((Boolean) modelEntry.get("required"));
// Validate bpm:priority
modelEntry = modelFieldsByName.get("bpm_workflowPriority");
assertNotNull(modelEntry);
assertEquals("Workflow Priority", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/bpm/1.0}workflowPriority", modelEntry.get("qualifiedName"));
assertEquals("d:int", modelEntry.get("dataType"));
assertEquals("2", modelEntry.get("defaultValue"));
assertFalse((Boolean) modelEntry.get("required"));
// Validate bpm:package
modelEntry = modelFieldsByName.get("bpm_package");
assertNotNull(modelEntry);
assertEquals("Content Package", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/bpm/1.0}package", modelEntry.get("qualifiedName"));
assertEquals("bpm:workflowPackage", modelEntry.get("dataType"));
assertFalse((Boolean) modelEntry.get("required"));
// Validate bpm:status
modelEntry = modelFieldsByName.get("bpm_status");
assertNotNull(modelEntry);
assertEquals("Status", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/bpm/1.0}status", modelEntry.get("qualifiedName"));
assertEquals("d:text", modelEntry.get("dataType"));
assertEquals("Not Yet Started", modelEntry.get("defaultValue"));
assertTrue((Boolean) modelEntry.get("required"));
JSONArray allowedValues = (JSONArray) modelEntry.get("allowedValues");
assertNotNull(allowedValues);
assertEquals(5, allowedValues.size());
assertTrue(allowedValues.contains("Not Yet Started"));
assertTrue(allowedValues.contains("In Progress"));
assertTrue(allowedValues.contains("On Hold"));
assertTrue(allowedValues.contains("Cancelled"));
assertTrue(allowedValues.contains("Completed"));
// get start form model with admin
publicApiClient.setRequestContext(adminContext);
model = processDefinitionsClient.findStartFormModel(activitiDefinition.getId());
assertNotNull(model);
entries = (JSONArray) model.get("entries");
assertNotNull(entries);
// Add all entries to a map, to make lookup easier
modelFieldsByName = new HashMap<String, JSONObject>();
for (int i = 0; i < entries.size(); i++) {
entry = (JSONObject) entries.get(i);
assertNotNull(entry);
entry = (JSONObject) entry.get("entry");
assertNotNull(entry);
modelFieldsByName.put((String) entry.get("name"), entry);
}
// Check well-known properties and their types
// Validate bpm:description
modelEntry = modelFieldsByName.get("bpm_workflowDescription");
assertNotNull(modelEntry);
assertEquals("Description", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/bpm/1.0}workflowDescription", modelEntry.get("qualifiedName"));
assertEquals("d:text", modelEntry.get("dataType"));
assertFalse((Boolean) modelEntry.get("required"));
// Validate bpm:description
modelEntry = modelFieldsByName.get("bpm_completionDate");
assertNotNull(modelEntry);
assertEquals("Completion Date", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/bpm/1.0}completionDate", modelEntry.get("qualifiedName"));
assertEquals("d:date", modelEntry.get("dataType"));
assertFalse((Boolean) modelEntry.get("required"));
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient 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.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient 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"));
}
}
Aggregations