use of org.camunda.bpm.engine.repository.ProcessDefinitionQuery in project camunda-bpm-platform by camunda.
the class TaskRestServiceInteractionTest method testGetSingleTaskHal.
@Test
@SuppressWarnings("unchecked")
public void testGetSingleTaskHal() {
// setup user query mock
List<User> mockUsers = Arrays.asList(MockProvider.mockUser().id(EXAMPLE_TASK_ASSIGNEE_NAME).build(), MockProvider.mockUser().id(EXAMPLE_TASK_OWNER).build());
UserQuery sampleUserQuery = mock(UserQuery.class);
when(sampleUserQuery.userIdIn(eq(EXAMPLE_TASK_ASSIGNEE_NAME), eq(EXAMPLE_TASK_OWNER))).thenReturn(sampleUserQuery);
when(sampleUserQuery.userIdIn(eq(EXAMPLE_TASK_OWNER), eq(EXAMPLE_TASK_ASSIGNEE_NAME))).thenReturn(sampleUserQuery);
when(sampleUserQuery.listPage(eq(0), eq(2))).thenReturn(mockUsers);
when(sampleUserQuery.count()).thenReturn((long) mockUsers.size());
when(processEngine.getIdentityService().createUserQuery()).thenReturn(sampleUserQuery);
// setup group query mock
List<Group> mockGroups = Arrays.asList(MockProvider.mockGroup().id(mockCandidateGroupIdentityLink.getGroupId()).build(), MockProvider.mockGroup().id(mockCandidateGroup2IdentityLink.getGroupId()).build());
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
when(sampleGroupQuery.groupIdIn(eq(EXAMPLE_GROUP_ID), eq(EXAMPLE_GROUP_ID2))).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.groupIdIn(eq(EXAMPLE_GROUP_ID2), eq(EXAMPLE_GROUP_ID))).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.listPage(eq(0), eq(2))).thenReturn(mockGroups);
when(sampleGroupQuery.count()).thenReturn((long) mockGroups.size());
when(processEngine.getIdentityService().createGroupQuery()).thenReturn(sampleGroupQuery);
// setup process definition query mock
List<ProcessDefinition> mockDefinitions = MockProvider.createMockDefinitions();
ProcessDefinitionQuery sampleProcessDefinitionQuery = mock(ProcessDefinitionQuery.class);
when(sampleProcessDefinitionQuery.listPage(0, 1)).thenReturn(mockDefinitions);
when(sampleProcessDefinitionQuery.processDefinitionIdIn(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).thenReturn(sampleProcessDefinitionQuery);
when(sampleProcessDefinitionQuery.count()).thenReturn(1l);
when(processEngine.getRepositoryService().createProcessDefinitionQuery()).thenReturn(sampleProcessDefinitionQuery);
// setup case definition query mock
List<CaseDefinition> mockCaseDefinitions = MockProvider.createMockCaseDefinitions();
CaseDefinitionQuery sampleCaseDefinitionQuery = mock(CaseDefinitionQuery.class);
when(sampleCaseDefinitionQuery.listPage(0, 1)).thenReturn(mockCaseDefinitions);
when(sampleCaseDefinitionQuery.caseDefinitionIdIn(MockProvider.EXAMPLE_CASE_DEFINITION_ID)).thenReturn(sampleCaseDefinitionQuery);
when(sampleCaseDefinitionQuery.count()).thenReturn(1l);
when(processEngine.getRepositoryService().createCaseDefinitionQuery()).thenReturn(sampleCaseDefinitionQuery);
Response response = given().header("accept", Hal.APPLICATION_HAL_JSON).pathParam("id", EXAMPLE_TASK_ID).then().expect().statusCode(Status.OK.getStatusCode()).body("id", equalTo(EXAMPLE_TASK_ID)).body("name", equalTo(MockProvider.EXAMPLE_TASK_NAME)).body("assignee", equalTo(MockProvider.EXAMPLE_TASK_ASSIGNEE_NAME)).body("created", equalTo(MockProvider.EXAMPLE_TASK_CREATE_TIME)).body("due", equalTo(MockProvider.EXAMPLE_TASK_DUE_DATE)).body("delegationState", equalTo(MockProvider.EXAMPLE_TASK_DELEGATION_STATE.toString())).body("description", equalTo(MockProvider.EXAMPLE_TASK_DESCRIPTION)).body("executionId", equalTo(MockProvider.EXAMPLE_TASK_EXECUTION_ID)).body("owner", equalTo(MockProvider.EXAMPLE_TASK_OWNER)).body("parentTaskId", equalTo(MockProvider.EXAMPLE_TASK_PARENT_TASK_ID)).body("priority", equalTo(MockProvider.EXAMPLE_TASK_PRIORITY)).body("processDefinitionId", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).body("processInstanceId", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)).body("taskDefinitionKey", equalTo(MockProvider.EXAMPLE_TASK_DEFINITION_KEY)).body("suspended", equalTo(MockProvider.EXAMPLE_TASK_SUSPENSION_STATE)).body("caseExecutionId", equalTo(MockProvider.EXAMPLE_CASE_EXECUTION_ID)).body("caseInstanceId", equalTo(MockProvider.EXAMPLE_CASE_INSTANCE_ID)).body("caseDefinitionId", equalTo(MockProvider.EXAMPLE_CASE_DEFINITION_ID)).body("tenantId", equalTo(MockProvider.EXAMPLE_TENANT_ID)).body("_links.assignee.href", endsWith(EXAMPLE_TASK_ASSIGNEE_NAME)).body("_links.caseDefinition.href", endsWith(EXAMPLE_CASE_DEFINITION_ID)).body("_links.caseExecution.href", endsWith(EXAMPLE_CASE_EXECUTION_ID)).body("_links.caseInstance.href", endsWith(EXAMPLE_CASE_INSTANCE_ID)).body("_links.execution.href", endsWith(EXAMPLE_TASK_EXECUTION_ID)).body("_links.owner.href", endsWith(EXAMPLE_TASK_OWNER)).body("_links.parentTask.href", endsWith(EXAMPLE_TASK_PARENT_TASK_ID)).body("_links.processDefinition.href", endsWith(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).body("_links.processInstance.href", endsWith(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)).body("_links.identityLink.href", endsWith("/task/" + EXAMPLE_TASK_ID + "/identity-links")).body("_links.self.href", endsWith(EXAMPLE_TASK_ID)).when().get(SINGLE_TASK_URL);
String content = response.asString();
// validate embedded users:
List<Map<String, Object>> embeddedUsers = from(content).getList("_embedded.user");
Assert.assertEquals("There should be two users returned.", 2, embeddedUsers.size());
Map<String, Object> embeddedUser = embeddedUsers.get(0);
assertNotNull("The returned user should not be null.", embeddedUser);
assertEquals(MockProvider.EXAMPLE_TASK_ASSIGNEE_NAME, embeddedUser.get("id"));
assertEquals(MockProvider.EXAMPLE_USER_FIRST_NAME, embeddedUser.get("firstName"));
assertEquals(MockProvider.EXAMPLE_USER_LAST_NAME, embeddedUser.get("lastName"));
assertEquals(MockProvider.EXAMPLE_USER_EMAIL, embeddedUser.get("email"));
assertNull(embeddedUser.get("_embedded"));
Map<String, Object> links = (Map<String, Object>) embeddedUser.get("_links");
assertEquals(1, links.size());
assertHalLink(links, "self", UserRestService.PATH + "/" + MockProvider.EXAMPLE_TASK_ASSIGNEE_NAME);
embeddedUser = embeddedUsers.get(1);
assertNotNull("The returned user should not be null.", embeddedUser);
assertEquals(MockProvider.EXAMPLE_TASK_OWNER, embeddedUser.get("id"));
assertEquals(MockProvider.EXAMPLE_USER_FIRST_NAME, embeddedUser.get("firstName"));
assertEquals(MockProvider.EXAMPLE_USER_LAST_NAME, embeddedUser.get("lastName"));
assertEquals(MockProvider.EXAMPLE_USER_EMAIL, embeddedUser.get("email"));
assertNull(embeddedUser.get("_embedded"));
links = (Map<String, Object>) embeddedUser.get("_links");
assertEquals(1, links.size());
assertHalLink(links, "self", UserRestService.PATH + "/" + MockProvider.EXAMPLE_TASK_OWNER);
// validate embedded groups:
List<Map<String, Object>> embeddedGroups = from(content).getList("_embedded.group");
Assert.assertEquals("There should be two groups returned.", 2, embeddedGroups.size());
Map<String, Object> embeddedGroup = embeddedGroups.get(0);
assertNotNull("The returned group should not be null.", embeddedGroup);
assertEquals(MockProvider.EXAMPLE_GROUP_ID, embeddedGroup.get("id"));
assertEquals(MockProvider.EXAMPLE_GROUP_NAME, embeddedGroup.get("name"));
assertEquals(MockProvider.EXAMPLE_GROUP_TYPE, embeddedGroup.get("type"));
assertNull(embeddedGroup.get("_embedded"));
links = (Map<String, Object>) embeddedGroup.get("_links");
assertEquals(1, links.size());
assertHalLink(links, "self", GroupRestService.PATH + "/" + MockProvider.EXAMPLE_GROUP_ID);
embeddedGroup = embeddedGroups.get(1);
assertNotNull("The returned group should not be null.", embeddedGroup);
assertEquals(MockProvider.EXAMPLE_GROUP_ID2, embeddedGroup.get("id"));
assertEquals(MockProvider.EXAMPLE_GROUP_NAME, embeddedGroup.get("name"));
assertEquals(MockProvider.EXAMPLE_GROUP_TYPE, embeddedGroup.get("type"));
assertNull(embeddedGroup.get("_embedded"));
links = (Map<String, Object>) embeddedGroup.get("_links");
assertEquals(1, links.size());
assertHalLink(links, "self", GroupRestService.PATH + "/" + MockProvider.EXAMPLE_GROUP_ID2);
// validate embedded processDefinitions:
List<Map<String, Object>> embeddedDefinitions = from(content).getList("_embedded.processDefinition");
Assert.assertEquals("There should be one processDefinition returned.", 1, embeddedDefinitions.size());
Map<String, Object> embeddedProcessDefinition = embeddedDefinitions.get(0);
Assert.assertNotNull("The returned processDefinition should not be null.", embeddedProcessDefinition);
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID, embeddedProcessDefinition.get("id"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY, embeddedProcessDefinition.get("key"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_CATEGORY, embeddedProcessDefinition.get("category"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_NAME, embeddedProcessDefinition.get("name"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_DESCRIPTION, embeddedProcessDefinition.get("description"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_VERSION, embeddedProcessDefinition.get("version"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_RESOURCE_NAME, embeddedProcessDefinition.get("resource"));
Assert.assertEquals(MockProvider.EXAMPLE_DEPLOYMENT_ID, embeddedProcessDefinition.get("deploymentId"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_DIAGRAM_RESOURCE_NAME, embeddedProcessDefinition.get("diagram"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_IS_SUSPENDED, embeddedProcessDefinition.get("suspended"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_APPLICATION_CONTEXT_PATH, embeddedProcessDefinition.get("contextPath"));
links = (Map<String, Object>) embeddedProcessDefinition.get("_links");
Assert.assertEquals(3, links.size());
assertHalLink(links, "self", "/process-definition/" + MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);
assertHalLink(links, "deployment", "/deployment/" + MockProvider.EXAMPLE_DEPLOYMENT_ID);
assertHalLink(links, "resource", "/deployment/" + MockProvider.EXAMPLE_DEPLOYMENT_ID + "/resources/" + MockProvider.EXAMPLE_PROCESS_DEFINITION_RESOURCE_NAME);
// validate embedded caseDefinitions:
List<Map<String, Object>> embeddedCaseDefinitions = from(content).getList("_embedded.caseDefinition");
Assert.assertEquals("There should be one caseDefinition returned.", 1, embeddedCaseDefinitions.size());
Map<String, Object> embeddedCaseDefinition = embeddedCaseDefinitions.get(0);
Assert.assertNotNull("The returned caseDefinition should not be null.", embeddedCaseDefinition);
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_ID, embeddedCaseDefinition.get("id"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_KEY, embeddedCaseDefinition.get("key"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_CATEGORY, embeddedCaseDefinition.get("category"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_NAME, embeddedCaseDefinition.get("name"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_VERSION, embeddedCaseDefinition.get("version"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_RESOURCE_NAME, embeddedCaseDefinition.get("resource"));
Assert.assertEquals(MockProvider.EXAMPLE_DEPLOYMENT_ID, embeddedCaseDefinition.get("deploymentId"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_APPLICATION_CONTEXT_PATH, embeddedCaseDefinition.get("contextPath"));
links = (Map<String, Object>) embeddedCaseDefinition.get("_links");
Assert.assertEquals(3, links.size());
assertHalLink(links, "self", "/case-definition/" + MockProvider.EXAMPLE_CASE_DEFINITION_ID);
assertHalLink(links, "deployment", "/deployment/" + MockProvider.EXAMPLE_DEPLOYMENT_ID);
assertHalLink(links, "resource", "/deployment/" + MockProvider.EXAMPLE_DEPLOYMENT_ID + "/resources/" + MockProvider.EXAMPLE_CASE_DEFINITION_RESOURCE_NAME);
// validate embedded identity links
List<Map<String, Object>> embeddedIdentityLinks = from(content).getList("_embedded.identityLink");
assertEquals("There should be three identityLink returned", 4, embeddedIdentityLinks.size());
assertEmbeddedIdentityLink(mockAssigneeIdentityLink, embeddedIdentityLinks.get(0));
assertEmbeddedIdentityLink(mockOwnerIdentityLink, embeddedIdentityLinks.get(1));
assertEmbeddedIdentityLink(mockCandidateGroupIdentityLink, embeddedIdentityLinks.get(2));
assertEmbeddedIdentityLink(mockCandidateGroup2IdentityLink, embeddedIdentityLinks.get(3));
}
use of org.camunda.bpm.engine.repository.ProcessDefinitionQuery in project camunda-bpm-platform by camunda.
the class ProcessDefinitionRestServiceQueryTest method setUpMockDefinitionQuery.
private ProcessDefinitionQuery setUpMockDefinitionQuery(List<ProcessDefinition> mockedDefinitions) {
ProcessDefinitionQuery sampleDefinitionsQuery = mock(ProcessDefinitionQuery.class);
when(sampleDefinitionsQuery.list()).thenReturn(mockedDefinitions);
when(sampleDefinitionsQuery.count()).thenReturn((long) mockedDefinitions.size());
when(processEngine.getRepositoryService().createProcessDefinitionQuery()).thenReturn(sampleDefinitionsQuery);
return sampleDefinitionsQuery;
}
use of org.camunda.bpm.engine.repository.ProcessDefinitionQuery in project camunda-bpm-platform by camunda.
the class MultiTenancyProcessDefinitionQueryTest method testQueryByTenantIds.
public void testQueryByTenantIds() {
ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().tenantIdIn(TENANT_ONE, TENANT_TWO);
assertThat(query.count(), is(2L));
}
use of org.camunda.bpm.engine.repository.ProcessDefinitionQuery in project camunda-bpm-platform by camunda.
the class MultiTenancyProcessDefinitionQueryTest method testQueryByLatestNoTenantIdSet.
public void testQueryByLatestNoTenantIdSet() {
// deploy a second version for tenant one
deploymentForTenant(TENANT_ONE, emptyProcess);
ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).latestVersion();
// one definition for each tenant
assertThat(query.count(), is(3L));
Map<String, ProcessDefinition> processDefinitionsForTenant = getProcessDefinitionsForTenant(query.list());
assertThat(processDefinitionsForTenant.get(TENANT_ONE).getVersion(), is(2));
assertThat(processDefinitionsForTenant.get(TENANT_TWO).getVersion(), is(1));
assertThat(processDefinitionsForTenant.get(null).getVersion(), is(1));
}
use of org.camunda.bpm.engine.repository.ProcessDefinitionQuery in project camunda-bpm-platform by camunda.
the class MultiTenancyProcessDefinitionQueryTest method testQueryAuthenticatedTenant.
public void testQueryAuthenticatedTenant() {
identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();
assertThat(query.count(), is(2L));
assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
assertThat(query.tenantIdIn(TENANT_TWO).count(), is(0L));
assertThat(query.tenantIdIn(TENANT_ONE, TENANT_TWO).includeProcessDefinitionsWithoutTenantId().count(), is(2L));
}
Aggregations