use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.DeploymentsClient in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeployments.
@Test
public void testGetDeployments() throws Exception {
// testGetDeployments#1: Getting deployments with admin-user
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
ListResponse<Deployment> deploymentResponse = deploymentsClient.getDeployments();
Map<String, Deployment> deploymentMap = new HashMap<String, Deployment>();
for (Deployment deployment : deploymentResponse.getList()) {
deploymentMap.put(deployment.getName(), deployment);
}
assertEquals(5, deploymentResponse.getList().size());
assertTrue(deploymentMap.containsKey("review-pooled.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("review.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("parallel-review-group.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("parallel-review.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("adhoc.bpmn20.xml"));
// testGetDeployments#2: Check all deployment fields in resulting deployment
org.activiti.engine.repository.Deployment activitiDeployment = activitiProcessEngine.getRepositoryService().createDeploymentQuery().deploymentName("adhoc.bpmn20.xml").processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
assertNotNull(activitiDeployment);
Deployment adhocDeployment = deploymentMap.get("adhoc.bpmn20.xml");
assertEquals(activitiDeployment.getId(), adhocDeployment.getId());
assertEquals(activitiDeployment.getCategory(), adhocDeployment.getCategory());
assertEquals(activitiDeployment.getName(), adhocDeployment.getName());
assertEquals(activitiDeployment.getDeploymentTime(), adhocDeployment.getDeployedAt());
Map<String, String> params = new HashMap<String, String>();
params.put("maxItems", "2");
JSONObject deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
JSONObject paginationJSON = (JSONObject) deploymentsListObject.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>();
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.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");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.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");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.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");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.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.workflow.api.tests.WorkflowApiClient.DeploymentsClient 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.workflow.api.tests.WorkflowApiClient.DeploymentsClient 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.workflow.api.tests.WorkflowApiClient.DeploymentsClient in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeploymentsWithNonAdminUser.
@Test
public void testGetDeploymentsWithNonAdminUser() throws Exception {
// deployments-get#1
initApiClientWithTestUser();
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
try {
deploymentsClient.getDeployments();
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Permission was denied", expected.getHttpResponse());
}
}
Aggregations