예제 #1
0
  @Test
  public void canUserEditApplicationTest() {
    // Initial setup
    User user = getUser();
    userService.add(user);
    Organization organization = createOrganization();
    Category category = createCategory(organization);
    organization.getCategories().add(category);
    Application application =
        createApplication(category, "Test Application", AppState.GROUP_PUBLISH);
    Group group = createGroup(organization);
    group.getOwnedApplications().add(application);

    entityManager.flush();

    createUserDomain(user, group.getId(), DomainType.GROUP, UserRole.ROLE_GROUP_ADMIN);
    entityManager.flush();

    assertTrue(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test if org admin can edit application
    user = getUser();
    userService.add(user);
    entityManager.flush();
    createUserDomain(user, organization.getId(), DomainType.ORGANIZATION, UserRole.ROLE_ORG_ADMIN);
    entityManager.flush();
    assertTrue(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test user is org user
    user = getUser();
    userService.add(user);
    entityManager.flush();
    createUserDomain(user, organization.getId(), DomainType.ORGANIZATION, UserRole.ROLE_ORG_USER);
    entityManager.flush();
    assertFalse(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test user is not part of organization and not group admin
    user = getUser();
    userService.add(user);
    entityManager.flush();
    assertFalse(userService.canUserEditApplication(user.getId(), application.getId()));
  }
예제 #2
0
  @Test
  public void deleteTest() {
    User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER);

    List<Group> groups = userService.getGroups(user);
    assertTrue(groups.size() == 1);
    List<UserDomain> userGroupDomains =
        userDomainService.getAll(groups.get(0).getId(), DomainType.GROUP);
    assertTrue(userGroupDomains.size() == 1);
    userService.delete(user.getId());
    userGroupDomains = userDomainService.getAll(groups.get(0).getId(), DomainType.GROUP);
    assertTrue(userGroupDomains.size() == 0);
  }