use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testCreateUserNamespaceAuthorizationInvalidParameters.
@Test
public void testCreateUserNamespaceAuthorizationInvalidParameters() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
UserNamespaceAuthorizationCreateRequest request;
// Try to create a user namespace authorization when user id contains a forward slash character.
request = new UserNamespaceAuthorizationCreateRequest(new UserNamespaceAuthorizationKey(addSlash(key.getUserId()), key.getNamespace()), Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE, NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT));
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(request);
fail("Should throw an IllegalArgumentException when user id contains a forward slash character.");
} catch (IllegalArgumentException e) {
assertEquals("User id can not contain a forward slash character.", e.getMessage());
}
// Try to create a user namespace authorization using non-existing namespace.
request = new UserNamespaceAuthorizationCreateRequest(new UserNamespaceAuthorizationKey(key.getUserId(), "I_DO_NOT_EXIST"), Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE, NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT));
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(request);
fail("Should throw an ObjectNotFoundException when using non-existing user namespace authorization namespace.");
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Namespace \"%s\" doesn't exist.", request.getUserNamespaceAuthorizationKey().getNamespace()), e.getMessage());
}
// Try to create a user namespace authorization when namespace contains a forward slash character.
request = new UserNamespaceAuthorizationCreateRequest(new UserNamespaceAuthorizationKey(key.getUserId(), addSlash(key.getNamespace())), Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE, NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT));
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(request);
fail("Should throw an IllegalArgumentException when namespace contains a forward slash character.");
} catch (IllegalArgumentException e) {
assertEquals("Namespace can not contain a forward slash character.", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorizationTrimParameters.
@Test
public void testUpdateUserNamespaceAuthorizationTrimParameters() {
// 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, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE));
// Update a user namespace authorization using input parameters with leading and trailing empty spaces.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(addWhitespace(key.getUserId()), addWhitespace(key.getNamespace())), new UserNamespaceAuthorizationUpdateRequest(SUPPORTED_NAMESPACE_PERMISSIONS));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorization.
// Unit tests for updateUserNamespaceAuthorization().
@Test
public void testUpdateUserNamespaceAuthorization() {
// 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, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE));
// Update a user namespace authorization.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(Arrays.asList(NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT)));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, Arrays.asList(NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT)), resultUserNamespaceAuthorization);
// Revert the update. This is done for the branch unit test coverage.
resultUserNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE)));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE)), resultUserNamespaceAuthorization);
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceImpl method createUserNamespaceAuthorization.
@NamespacePermission(fields = "#request?.userNamespaceAuthorizationKey?.namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public UserNamespaceAuthorization createUserNamespaceAuthorization(UserNamespaceAuthorizationCreateRequest request) {
// Validate and trim the request parameters.
validateUserNamespaceAuthorizationCreateRequest(request);
// Get the user namespace authorization key.
UserNamespaceAuthorizationKey key = request.getUserNamespaceAuthorizationKey();
// Ensure a user namespace authorization with the specified name doesn't already exist for the specified namespace.
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(key);
if (userNamespaceAuthorizationEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create user namespace authorization with user id \"%s\" and namespace \"%s\" because it already exists.", key.getUserId(), key.getNamespace()));
}
// Retrieve and ensure that namespace exists with the specified user namespace authorization namespace code.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(key.getNamespace());
// Create and persist a new user namespace authorization entity from the request information.
userNamespaceAuthorizationEntity = createUserNamespaceAuthorizationEntity(key.getUserId(), namespaceEntity, request.getNamespacePermissions());
// Create and return the user namespace authorization object from the persisted entity.
return createUserNamespaceAuthorizationFromEntity(userNamespaceAuthorizationEntity);
}
Aggregations