Search in sources :

Example 1 with UserGroupRecord

use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.

the class UserGroupPermissionServiceTest method testGrantUserGroupPermissionsWhenUserGroupRecordIsPresentForGivenName.

@Test
public void testGrantUserGroupPermissionsWhenUserGroupRecordIsPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Role role = Mockito.mock(Role.class);
    Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
    Optional<UserGroupRecord> userGroupRecord = getUserGroup();
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
    Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
    userGroupPermissions.add(userGroupPermission);
    userGroupPermissionService.grantUserGroupPermissions("safeBoxId", userGroupPermissions, "user", OffsetDateTime.MAX);
    Mockito.verify(userGroupDao).createUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
Also used : Role(com.nike.cerberus.domain.Role) UserGroupRecord(com.nike.cerberus.record.UserGroupRecord) UserGroupPermissionRecord(com.nike.cerberus.record.UserGroupPermissionRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 2 with UserGroupRecord

use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.

the class UserGroupPermissionServiceTest method testGetUserGroupPermissionsForGivenSafeBoxIdWhenUserGroupPermissionRecordPresent.

@Test
public void testGetUserGroupPermissionsForGivenSafeBoxIdWhenUserGroupPermissionRecordPresent() {
    UserGroupPermissionRecord userGroupPermissionRecord = getUserGroupPermissionRecord();
    List<UserGroupPermissionRecord> userGroupPermissionRecords = new ArrayList<>();
    userGroupPermissionRecords.add(userGroupPermissionRecord);
    Mockito.when(userGroupDao.getUserGroupPermissions("safeBoxId")).thenReturn(userGroupPermissionRecords);
    Optional<UserGroupRecord> userGroupRecord = getUserGroup();
    Mockito.when(userGroupDao.getUserGroup("id")).thenReturn(userGroupRecord);
    Set<UserGroupPermission> userGroupPermissions = userGroupPermissionService.getUserGroupPermissions("safeBoxId");
    Assert.assertFalse(userGroupPermissions.isEmpty());
    Assert.assertEquals(1, userGroupPermissions.size());
}
Also used : UserGroupRecord(com.nike.cerberus.record.UserGroupRecord) UserGroupPermissionRecord(com.nike.cerberus.record.UserGroupPermissionRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 3 with UserGroupRecord

use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.

the class UserGroupPermissionServiceTest method getUserGroup.

private Optional<UserGroupRecord> getUserGroup() {
    UserGroupRecord userGroupRecords = new UserGroupRecord();
    userGroupRecords.setName("name");
    userGroupRecords.setId("id");
    return Optional.of(userGroupRecords);
}
Also used : UserGroupRecord(com.nike.cerberus.record.UserGroupRecord)

Example 4 with UserGroupRecord

use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.

the class UserGroupPermissionServiceTest method testRevokeUserGroupPermissionsWhenGroupRecordIsPresentForGivenName.

@Test
public void testRevokeUserGroupPermissionsWhenGroupRecordIsPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
    userGroupPermissions.add(userGroupPermission);
    Optional<UserGroupRecord> userGroupRecord = getUserGroup();
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
    userGroupPermissionService.revokeUserGroupPermissions("safeBoxId", userGroupPermissions);
    Mockito.verify(userGroupDao).deleteUserGroupPermission("safeBoxId", userGroupRecord.get().getId());
}
Also used : UserGroupRecord(com.nike.cerberus.record.UserGroupRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 5 with UserGroupRecord

use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.

the class UserGroupPermissionServiceTest method testRevokeUserGroupPermissionWhenGroupRecordIsPresentForGivenName.

@Test
public void testRevokeUserGroupPermissionWhenGroupRecordIsPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Optional<UserGroupRecord> userGroupRecord = getUserGroup();
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
    userGroupPermissionService.revokeUserGroupPermission("safeBoxId", userGroupPermission);
    Mockito.verify(userGroupDao).deleteUserGroupPermission("safeBoxId", userGroupRecord.get().getId());
}
Also used : UserGroupRecord(com.nike.cerberus.record.UserGroupRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Aggregations

UserGroupRecord (com.nike.cerberus.record.UserGroupRecord)11 UserGroupPermission (com.nike.cerberus.domain.UserGroupPermission)8 UserGroupPermissionRecord (com.nike.cerberus.record.UserGroupPermissionRecord)8 Test (org.junit.Test)7 Role (com.nike.cerberus.domain.Role)3 Transactional (org.springframework.transaction.annotation.Transactional)2