use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest 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.UserNamespaceAuthorizationCreateRequest in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testCreateUserNamespaceAuthorizationLowerCaseParameters.
@Test
public void testCreateUserNamespaceAuthorizationLowerCaseParameters() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Create and persist the relative database entities.
namespaceDaoTestHelper.createNamespaceEntity(key.getNamespace());
// Create a user namespace authorization using lowercase input parameters.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(new UserNamespaceAuthorizationKey(key.getUserId().toLowerCase(), key.getNamespace().toLowerCase()), SUPPORTED_NAMESPACE_PERMISSIONS));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(resultUserNamespaceAuthorization.getId(), new UserNamespaceAuthorizationKey(key.getUserId().toLowerCase(), key.getNamespace()), SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testCreateUserNamespaceAuthorization.
// Unit tests for createUserNamespaceAuthorization().
@Test
public void testCreateUserNamespaceAuthorization() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Create and persist the relative database entities.
namespaceDaoTestHelper.createNamespaceEntity(key.getNamespace());
// Create a user namespace authorization.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(key, SUPPORTED_NAMESPACE_PERMISSIONS));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(resultUserNamespaceAuthorization.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testCreateUserNamespaceAuthorizationTrimParameters.
@Test
public void testCreateUserNamespaceAuthorizationTrimParameters() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Create and persist the relative database entities.
namespaceDaoTestHelper.createNamespaceEntity(key.getNamespace());
// Create a user namespace authorization using input parameters with leading and trailing empty spaces.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(new UserNamespaceAuthorizationKey(addWhitespace(key.getUserId()), addWhitespace(key.getNamespace())), SUPPORTED_NAMESPACE_PERMISSIONS));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(resultUserNamespaceAuthorization.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
}
use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest 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());
}
}
Aggregations