use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeploymentById.
@Test
public void testGetDeploymentById() throws Exception {
// Use admin-user for tenant
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
// Fetch the actual deployment from activiti
org.activiti.engine.repository.Deployment activitiDeployment = activitiProcessEngine.getRepositoryService().createDeploymentQuery().deploymentName("adhoc.bpmn20.xml").processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
assertNotNull(activitiDeployment);
// Do the actual API-call
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
Deployment deployment = deploymentsClient.findDeploymentById(activitiDeployment.getId());
assertNotNull(deployment);
assertEquals(activitiDeployment.getId(), deployment.getId());
assertEquals(activitiDeployment.getCategory(), deployment.getCategory());
assertEquals(activitiDeployment.getName(), deployment.getName());
assertEquals(activitiDeployment.getDeploymentTime(), deployment.getDeployedAt());
try {
deploymentsClient.findDeploymentById("fakeid");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// get deployment with default user
try {
publicApiClient.setRequestContext(requestContext);
deploymentsClient.findDeploymentById(activitiDeployment.getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeploymentsEmpty.
@Test
public void testGetDeploymentsEmpty() throws Exception {
// Create a new test-network, not added to the test-fixture to prevent being used
// in other tests
String networkName = AbstractTestFixture.TEST_DOMAIN_PREFIX + "999";
final TestNetwork testNetwork = repoService.createNetworkWithAlias(networkName, true);
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@SuppressWarnings("synthetic-access")
public Void execute() throws Throwable {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
testNetwork.create();
return null;
}
}, false, true);
// Delete all deployments in the network
List<org.activiti.engine.repository.Deployment> deployments = activitiProcessEngine.getRepositoryService().createDeploymentQuery().processDefinitionKeyLike("@" + testNetwork.getId() + "@%").list();
for (org.activiti.engine.repository.Deployment deployment : deployments) {
activitiProcessEngine.getRepositoryService().deleteDeployment(deployment.getId(), true);
}
// Fetch deployments using tenant-admin
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + testNetwork.getId();
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), tenantAdmin));
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
ListResponse<Deployment> deploymentResponse = deploymentsClient.getDeployments();
assertEquals(0, deploymentResponse.getList().size());
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionById.
@Test
public void testGetProcessDefinitionById() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
// Get a single process definitions
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
ProcessDefinition adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
assertNotNull(adhocDefinition);
// Check fields of a resulting process-definition
assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
assertEquals("activitiAdhoc", adhocDefinition.getKey());
assertEquals(activitiDefinition.getDeploymentId(), adhocDefinition.getDeploymentId());
assertEquals(activitiDefinition.getCategory(), adhocDefinition.getCategory());
assertEquals(activitiDefinition.getName(), adhocDefinition.getName());
assertEquals(activitiDefinition.getVersion(), adhocDefinition.getVersion());
assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinition.isGraphicNotationDefined());
assertEquals("wf:submitAdhocTask", adhocDefinition.getStartFormResourceKey());
// get process definition with admin
publicApiClient.setRequestContext(adminContext);
adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
assertNotNull(adhocDefinition);
// Check fields of a resulting process-definition
assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
assertEquals("activitiAdhoc", adhocDefinition.getKey());
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionsImage.
@Test
public void testGetProcessDefinitionsImage() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
try {
HttpResponse response = processDefinitionsClient.findImageById(activitiDefinition.getId());
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), expected.getHttpResponse().getStatusCode());
assertTrue(expected.getMessage().contains("No image available"));
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testAuthenticationAndAuthorization.
@Test
public void testAuthenticationAndAuthorization() throws Exception {
// Fetching process definitions as admin should be possible
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(requestContext.getNetworkId(), tenantAdmin));
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());
// Fetching process definitions as admin from another tenant shouldn't be possible
TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
publicApiClient.setRequestContext(otherContext);
processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(null);
processDefinitionMap = getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
// the response should contain process definitions from the new tenant
assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
assertTrue(processDefinitionMap.containsKey("activitiReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(5, processDefinitionMap.size());
// Fetching a specific process definitions as admin should be possible
publicApiClient.setRequestContext(requestContext);
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
// Get a single process definitions
ProcessDefinition adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
assertNotNull(adhocDefinition);
// Check fields of a resulting process-definition
assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
assertEquals("activitiAdhoc", adhocDefinition.getKey());
assertEquals(activitiDefinition.getDeploymentId(), adhocDefinition.getDeploymentId());
assertEquals(activitiDefinition.getCategory(), adhocDefinition.getCategory());
assertEquals(activitiDefinition.getName(), adhocDefinition.getName());
assertEquals(activitiDefinition.getVersion(), adhocDefinition.getVersion());
assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinition.isGraphicNotationDefined());
assertEquals("wf:submitAdhocTask", adhocDefinition.getStartFormResourceKey());
// Fetching a specific process definitions as admin from another tenant should not be possible
publicApiClient.setRequestContext(otherContext);
try {
adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
fail("not found expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
// Fetching the start form model of a process definition as admin should be possible
publicApiClient.setRequestContext(requestContext);
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"));
// Fetching a specific process definitions as admin from another tenant should not be possible
publicApiClient.setRequestContext(otherContext);
try {
model = processDefinitionsClient.findStartFormModel(activitiDefinition.getId());
fail("not found expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
}
Aggregations