Search in sources :

Example 1 with UserNamespaceAuthorizationKey

use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.

the class UserNamespaceAuthorizationDaoTest method testGetUserNamespaceAuthorizationsByUserId.

@Test
public void testGetUserNamespaceAuthorizationsByUserId() {
    // Create user namespace authorization keys. The keys are listed out of order to validate the order by logic.
    List<UserNamespaceAuthorizationKey> keys = Arrays.asList(new UserNamespaceAuthorizationKey(USER_ID_2, NAMESPACE_2), new UserNamespaceAuthorizationKey(USER_ID_2, NAMESPACE), new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE_2), new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE));
    // Create and persist the relative database entities.
    List<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntities = new ArrayList<>();
    for (UserNamespaceAuthorizationKey key : keys) {
        userNamespaceAuthorizationEntities.add(userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS));
    }
    // Get user namespace authorizations by user id.
    assertEquals(Arrays.asList(userNamespaceAuthorizationEntities.get(3), userNamespaceAuthorizationEntities.get(2)), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(USER_ID));
    // Test case insensitivity of the user id input parameter.
    assertEquals(Arrays.asList(userNamespaceAuthorizationEntities.get(3), userNamespaceAuthorizationEntities.get(2)), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(USER_ID.toUpperCase()));
    assertEquals(Arrays.asList(userNamespaceAuthorizationEntities.get(3), userNamespaceAuthorizationEntities.get(2)), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(USER_ID.toLowerCase()));
    // Try to retrieve user namespace authorization using a non-existing user id.
    assertEquals(new ArrayList<>(), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(USER_ID_3));
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) ArrayList(java.util.ArrayList) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) Test(org.junit.Test)

Example 2 with UserNamespaceAuthorizationKey

use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.

the class UserNamespaceAuthorizationServiceImpl method createUserNamespaceAuthorizationFromEntity.

/**
 * Creates the user namespace authorization from the persisted entity.
 *
 * @param userNamespaceAuthorizationEntity the user namespace authorization entity
 *
 * @return the user namespace authorization
 */
private UserNamespaceAuthorization createUserNamespaceAuthorizationFromEntity(UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity) {
    UserNamespaceAuthorization userNamespaceAuthorization = new UserNamespaceAuthorization();
    userNamespaceAuthorization.setId(userNamespaceAuthorizationEntity.getId());
    UserNamespaceAuthorizationKey userNamespaceAuthorizationKey = new UserNamespaceAuthorizationKey();
    userNamespaceAuthorization.setUserNamespaceAuthorizationKey(userNamespaceAuthorizationKey);
    userNamespaceAuthorizationKey.setUserId(userNamespaceAuthorizationEntity.getUserId());
    userNamespaceAuthorizationKey.setNamespace(userNamespaceAuthorizationEntity.getNamespace().getCode());
    userNamespaceAuthorization.setNamespacePermissions(userNamespaceAuthorizationHelper.getNamespacePermissions(userNamespaceAuthorizationEntity));
    return userNamespaceAuthorization;
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization)

Example 3 with UserNamespaceAuthorizationKey

use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.

the class UserNamespaceAuthorizationRestControllerTest method testDeleteUserNamespaceAuthorization.

@Test
public void testDeleteUserNamespaceAuthorization() {
    // Create a user namespace authorization key
    UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
    UserNamespaceAuthorization userNamespaceAuthorization = new UserNamespaceAuthorization(ID, key, SUPPORTED_NAMESPACE_PERMISSIONS);
    when(userNamespaceAuthorizationService.deleteUserNamespaceAuthorization(key)).thenReturn(userNamespaceAuthorization);
    // Delete this user namespace authorization.
    UserNamespaceAuthorization deletedUserNamespaceAuthorization = userNamespaceAuthorizationRestController.deleteUserNamespaceAuthorization(key.getUserId(), key.getNamespace());
    // Verify the external calls.
    verify(userNamespaceAuthorizationService).deleteUserNamespaceAuthorization(key);
    verifyNoMoreInteractions(userNamespaceAuthorizationService);
    // Validate the returned object.
    assertEquals(userNamespaceAuthorization, deletedUserNamespaceAuthorization);
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 4 with UserNamespaceAuthorizationKey

use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.

the class UserNamespaceAuthorizationRestControllerTest method testCreateUserNamespaceAuthorization.

@Test
public void testCreateUserNamespaceAuthorization() {
    // Create a user namespace authorization key.
    UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
    UserNamespaceAuthorizationCreateRequest request = new UserNamespaceAuthorizationCreateRequest(key, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE, NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT));
    UserNamespaceAuthorization userNamespaceAuthorization = new UserNamespaceAuthorization(ID, key, SUPPORTED_NAMESPACE_PERMISSIONS);
    // Mock calls to external method.
    when(userNamespaceAuthorizationService.createUserNamespaceAuthorization(request)).thenReturn(userNamespaceAuthorization);
    UserNamespaceAuthorization response = userNamespaceAuthorizationRestController.createUserNamespaceAuthorization(request);
    // Verify the external calls.
    verify(userNamespaceAuthorizationService).createUserNamespaceAuthorization(request);
    verifyNoMoreInteractions(userNamespaceAuthorizationService);
    // Validate the returned object.
    assertEquals(userNamespaceAuthorization, response);
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationCreateRequest(org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 5 with UserNamespaceAuthorizationKey

use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.

the class UserNamespaceAuthorizationRestControllerTest method testGetUserNamespaceAuthorization.

@Test
public void testGetUserNamespaceAuthorization() {
    // Create a user namespace authorization key
    UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
    UserNamespaceAuthorization userNamespaceAuthorization = new UserNamespaceAuthorization(ID, key, SUPPORTED_NAMESPACE_PERMISSIONS);
    when(userNamespaceAuthorizationService.getUserNamespaceAuthorization(key)).thenReturn(userNamespaceAuthorization);
    // Get a user namespace authorization.
    UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationRestController.getUserNamespaceAuthorization(key.getUserId(), key.getNamespace());
    // Verify the external calls.
    verify(userNamespaceAuthorizationService).getUserNamespaceAuthorization(key);
    verifyNoMoreInteractions(userNamespaceAuthorizationService);
    // Validate the returned object.
    assertEquals(userNamespaceAuthorization, resultUserNamespaceAuthorization);
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Aggregations

UserNamespaceAuthorizationKey (org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey)44 Test (org.junit.Test)42 UserNamespaceAuthorization (org.finra.herd.model.api.xml.UserNamespaceAuthorization)29 UserNamespaceAuthorizationEntity (org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity)22 UserNamespaceAuthorizationCreateRequest (org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest)9 UserNamespaceAuthorizationUpdateRequest (org.finra.herd.model.api.xml.UserNamespaceAuthorizationUpdateRequest)8 UserNamespaceAuthorizations (org.finra.herd.model.api.xml.UserNamespaceAuthorizations)8 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)4 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)4 ArrayList (java.util.ArrayList)3 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)2 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1