Search in sources :

Example 1 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery 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));
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessDefinitionQuery(org.camunda.bpm.engine.repository.ProcessDefinitionQuery) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) CaseDefinitionQuery(org.camunda.bpm.engine.repository.CaseDefinitionQuery) Response(com.jayway.restassured.response.Response) UserQuery(org.camunda.bpm.engine.identity.UserQuery) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) EqualsMap(org.camunda.bpm.engine.rest.helper.EqualsMap) VariableMap(org.camunda.bpm.engine.variable.VariableMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.

the class ProcessEngineRestServiceTest method createIdentityMocks.

private void createIdentityMocks() {
    // identity
    UserQuery sampleUserQuery = mock(UserQuery.class);
    GroupQuery sampleGroupQuery = mock(GroupQuery.class);
    List<User> mockUsers = new ArrayList<User>();
    User mockUser = MockProvider.createMockUser();
    mockUsers.add(mockUser);
    // user query
    when(sampleUserQuery.memberOfGroup(anyString())).thenReturn(sampleUserQuery);
    when(sampleUserQuery.list()).thenReturn(mockUsers);
    // group query
    List<Group> mockGroups = MockProvider.createMockGroups();
    when(sampleGroupQuery.groupMember(anyString())).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.orderByGroupName()).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.asc()).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.list()).thenReturn(mockGroups);
    when(mockIdentityService.createGroupQuery()).thenReturn(sampleGroupQuery);
    when(mockIdentityService.createUserQuery()).thenReturn(sampleUserQuery);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) UserQuery(org.camunda.bpm.engine.identity.UserQuery) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) ArrayList(java.util.ArrayList)

Example 3 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.

the class GroupRestServiceImpl method getGroupCount.

protected CountResultDto getGroupCount(GroupQueryDto queryDto) {
    GroupQuery query = queryDto.toQuery(getProcessEngine());
    long count = query.count();
    return new CountResultDto(count);
}
Also used : CountResultDto(org.camunda.bpm.engine.rest.dto.CountResultDto) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery)

Example 4 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.

the class AuthenticationFilterPathMatchingTest method setup.

@Before
public void setup() throws ServletException {
    currentEngine = getProcessEngine(engineName);
    authorizationServiceMock = mock(AuthorizationServiceImpl.class);
    identityServiceMock = mock(IdentityServiceImpl.class);
    repositoryServiceMock = mock(RepositoryService.class);
    when(currentEngine.getAuthorizationService()).thenReturn(authorizationServiceMock);
    when(currentEngine.getIdentityService()).thenReturn(identityServiceMock);
    // for authentication
    userMock = MockProvider.createMockUser();
    List<Group> groupMocks = MockProvider.createMockGroups();
    groupIds = setupGroupQueryMock(groupMocks);
    List<Tenant> tenantMocks = Collections.singletonList(MockProvider.createMockTenant());
    tenantIds = setupTenantQueryMock(tenantMocks);
    GroupQuery mockGroupQuery = mock(GroupQuery.class);
    when(identityServiceMock.createGroupQuery()).thenReturn(mockGroupQuery);
    when(mockGroupQuery.groupMember(anyString())).thenReturn(mockGroupQuery);
    when(mockGroupQuery.list()).thenReturn(groupMocks);
    setupFilter();
}
Also used : Group(org.camunda.bpm.engine.identity.Group) Tenant(org.camunda.bpm.engine.identity.Tenant) IdentityServiceImpl(org.camunda.bpm.engine.impl.IdentityServiceImpl) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) AuthorizationServiceImpl(org.camunda.bpm.engine.impl.AuthorizationServiceImpl) RepositoryService(org.camunda.bpm.engine.RepositoryService) Before(org.junit.Before)

Example 5 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.

the class AuthenticationFilterPathMatchingTest method setupGroupQueryMock.

protected List<String> setupGroupQueryMock(List<Group> groups) {
    GroupQuery mockGroupQuery = mock(GroupQuery.class);
    when(identityServiceMock.createGroupQuery()).thenReturn(mockGroupQuery);
    when(mockGroupQuery.groupMember(anyString())).thenReturn(mockGroupQuery);
    when(mockGroupQuery.list()).thenReturn(groups);
    List<String> groupIds = new ArrayList<String>();
    for (Group groupMock : groups) {
        groupIds.add(groupMock.getId());
    }
    return groupIds;
}
Also used : Group(org.camunda.bpm.engine.identity.Group) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

GroupQuery (org.camunda.bpm.engine.identity.GroupQuery)34 Group (org.camunda.bpm.engine.identity.Group)22 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)10 ArrayList (java.util.ArrayList)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 User (org.camunda.bpm.engine.identity.User)5 UserQuery (org.camunda.bpm.engine.identity.UserQuery)4 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)4 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)3 Tenant (org.camunda.bpm.engine.identity.Tenant)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Response (com.jayway.restassured.response.Response)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 IdentityService (org.camunda.bpm.engine.IdentityService)1 RepositoryService (org.camunda.bpm.engine.RepositoryService)1