use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationUpdateRequest in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorizationMissingRequiredParameters.
@Test
public void testUpdateUserNamespaceAuthorizationMissingRequiredParameters() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Try to update a user namespace authorization when user namespace authorization key is not specified.
try {
userNamespaceAuthorizationService.updateUserNamespaceAuthorization(null, new UserNamespaceAuthorizationUpdateRequest(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 update a user namespace authorization when user id is not specified.
try {
userNamespaceAuthorizationService.updateUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(BLANK_TEXT, NAMESPACE), new UserNamespaceAuthorizationUpdateRequest(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 update a user namespace authorization when namespace is not specified.
try {
userNamespaceAuthorizationService.updateUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(USER_ID, BLANK_TEXT), new UserNamespaceAuthorizationUpdateRequest(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 update a user namespace authorization when permissions are not specified (passed as null).
try {
userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(null));
fail("Should throw an IllegalArgumentException when permissions are not specified.");
} catch (IllegalArgumentException e) {
assertEquals("Namespace permissions must be specified.", e.getMessage());
}
// Try to update a user namespace authorization when permissions are not specified (passed as an empty list).
try {
userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(new ArrayList<>()));
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.UserNamespaceAuthorizationUpdateRequest 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.UserNamespaceAuthorizationUpdateRequest 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);
}
Aggregations