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));
}
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;
}
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);
}
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);
}
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);
}
Aggregations