use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorizationUpperCaseParameters.
@Test
public void testUpdateUserNamespaceAuthorizationUpperCaseParameters() {
// 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 uppercase input parameters.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(key.getUserId().toUpperCase(), key.getNamespace().toUpperCase()), 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 testCreateUserNamespaceAuthorizationDuplicatePermissions.
@Test
public void testCreateUserNamespaceAuthorizationDuplicatePermissions() {
// Try to create a user namespace authorization using duplicate permission values.
UserNamespaceAuthorizationCreateRequest request = new UserNamespaceAuthorizationCreateRequest(new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE), Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.READ));
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(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());
}
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testCreateUserNamespaceAuthorizationAlreadyExists.
@Test
public void testCreateUserNamespaceAuthorizationAlreadyExists() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Create and persist the relative database entities.
userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS);
// Try to create a user namespace authorization when it already exists.
try {
userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(key, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE, NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT)));
fail("Should throw an AlreadyExistsException when user namespace authorization already exists.");
} catch (AlreadyExistsException e) {
assertEquals(String.format("Unable to create user namespace authorization with user id \"%s\" and namespace \"%s\" because it already exists.", key.getUserId(), key.getNamespace()), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testGetUserNamespaceAuthorizationsByUserIdUpperCaseParameters.
@Test
public void testGetUserNamespaceAuthorizationsByUserIdUpperCaseParameters() throws Exception {
// 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);
// Get user namespace authorizations for the specified user id using uppercase user id value.
UserNamespaceAuthorizations resultUserNamespaceAuthorizations = userNamespaceAuthorizationService.getUserNamespaceAuthorizationsByUserId(key.getUserId().toUpperCase());
// Validate the returned object.
assertEquals(new UserNamespaceAuthorizations(Arrays.asList(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS))), resultUserNamespaceAuthorizations);
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testGetUserNamespaceAuthorizationMissingRequiredParameters.
@Test
public void testGetUserNamespaceAuthorizationMissingRequiredParameters() {
// Try to get a user namespace authorization when user namespace authorization key is not specified.
try {
userNamespaceAuthorizationService.getUserNamespaceAuthorization(null);
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 get a user namespace authorization when user id is not specified.
try {
userNamespaceAuthorizationService.getUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(BLANK_TEXT, NAMESPACE));
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 get a user namespace authorization when namespace is not specified.
try {
userNamespaceAuthorizationService.getUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(USER_ID, BLANK_TEXT));
fail("Should throw an IllegalArgumentException when namespace is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
}
Aggregations