use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testDeleteUserNamespaceAuthorizationNoExists.
@Test
public void testDeleteUserNamespaceAuthorizationNoExists() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Try to delete a user namespace authorization when it does not exist.
try {
userNamespaceAuthorizationService.deleteUserNamespaceAuthorization(key);
fail("Should throw an ObjectNotFoundException when user namespace authorization does not exist.");
} catch (ObjectNotFoundException e) {
assertEquals(String.format("User namespace authorization with user id \"%s\" and namespace \"%s\" doesn't exist.", key.getUserId(), key.getNamespace()), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testGetUserNamespaceAuthorizationsByUserId.
// Unit tests for getUserNamespaceAuthorizationsByUserId().
@Test
public void testGetUserNamespaceAuthorizationsByUserId() throws Exception {
// 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.
for (UserNamespaceAuthorizationKey key : keys) {
userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS);
}
// Get user namespace authorizations for the specified user id.
UserNamespaceAuthorizations resultUserNamespaceAuthorizations = userNamespaceAuthorizationService.getUserNamespaceAuthorizationsByUserId(USER_ID);
// Validate the returned object.
assertEquals(new UserNamespaceAuthorizations(Arrays.asList(new UserNamespaceAuthorization(resultUserNamespaceAuthorizations.getUserNamespaceAuthorizations().get(0).getId(), keys.get(3), SUPPORTED_NAMESPACE_PERMISSIONS), new UserNamespaceAuthorization(resultUserNamespaceAuthorizations.getUserNamespaceAuthorizations().get(1).getId(), keys.get(2), SUPPORTED_NAMESPACE_PERMISSIONS))), resultUserNamespaceAuthorizations);
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testCreateUserNamespaceAuthorizationMissingRequiredParameters.
@Test
public void testCreateUserNamespaceAuthorizationMissingRequiredParameters() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Try to create a user namespace authorization when user namespace authorization key is not specified.
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(null, SUPPORTED_NAMESPACE_PERMISSIONS));
fail("Should throw an IllegalArgumentException when user namespace authorization key is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A user namespace authorization key must be specified.", e.getMessage());
}
// Try to create a user namespace authorization when user id is not specified.
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(new UserNamespaceAuthorizationKey(BLANK_TEXT, NAMESPACE), SUPPORTED_NAMESPACE_PERMISSIONS));
fail("Should throw an IllegalArgumentException when user id is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A user id must be specified.", e.getMessage());
}
// Try to create a user namespace authorization when namespace is not specified.
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(new UserNamespaceAuthorizationKey(USER_ID, BLANK_TEXT), SUPPORTED_NAMESPACE_PERMISSIONS));
fail("Should throw an IllegalArgumentException when namespace is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
// Try to create a user namespace authorization when permissions are not specified (passed as null).
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(key, null));
fail("Should throw an IllegalArgumentException when permissions are not specified.");
} catch (IllegalArgumentException e) {
assertEquals("Namespace permissions must be specified.", e.getMessage());
}
// Try to create a user namespace authorization when permissions are not specified (passed as an empty list).
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(key, Arrays.asList()));
fail("Should throw an IllegalArgumentException when permissions are not specified.");
} catch (IllegalArgumentException e) {
assertEquals("Namespace permissions must be specified.", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testDeleteUserNamespaceAuthorizationTrimParameters.
@Test
public void testDeleteUserNamespaceAuthorizationTrimParameters() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Create and persist the relative database entities.
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS);
// Validate that this user namespace authorization exists.
assertNotNull(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(key));
// Delete a user namespace authorization using input parameters with leading and trailing empty spaces.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.deleteUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(addWhitespace(key.getUserId()), addWhitespace(key.getNamespace())));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
// Ensure that this user namespace authorization is no longer there.
assertNull(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(key));
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorizationDuplicatePermissions.
@Test
public void testUpdateUserNamespaceAuthorizationDuplicatePermissions() {
// Try to update a user namespace authorization using duplicate permission values.
UserNamespaceAuthorizationUpdateRequest request = new UserNamespaceAuthorizationUpdateRequest(Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.READ));
try {
userNamespaceAuthorizationService.updateUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE), request);
fail("Should throw an IllegalArgumentException when using duplicate permission values.");
} catch (IllegalArgumentException e) {
assertEquals(String.format("Duplicate namespace permission \"%s\" is found.", NamespacePermissionEnum.READ.value()), e.getMessage());
}
}
Aggregations