Search in sources :

Example 6 with UserNamespaceAuthorizationCreateRequest

use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest 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());
    }
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationCreateRequest(org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest) Test(org.junit.Test)

Example 7 with UserNamespaceAuthorizationCreateRequest

use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest 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());
    }
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationCreateRequest(org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 8 with UserNamespaceAuthorizationCreateRequest

use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest in project herd by FINRAOS.

the class UserNamespaceAuthorizationServiceTest method testCreateUserNamespaceAuthorizationUpperCaseParameters.

@Test
public void testCreateUserNamespaceAuthorizationUpperCaseParameters() {
    // 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 uppercase input parameters.
    UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.createUserNamespaceAuthorization(new UserNamespaceAuthorizationCreateRequest(new UserNamespaceAuthorizationKey(key.getUserId().toUpperCase(), key.getNamespace().toUpperCase()), SUPPORTED_NAMESPACE_PERMISSIONS));
    // Validate the returned object.
    assertEquals(new UserNamespaceAuthorization(resultUserNamespaceAuthorization.getId(), new UserNamespaceAuthorizationKey(key.getUserId().toUpperCase(), key.getNamespace()), SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationCreateRequest(org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 9 with UserNamespaceAuthorizationCreateRequest

use of org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest 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());
    }
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationCreateRequest(org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Aggregations

UserNamespaceAuthorizationCreateRequest (org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest)9 UserNamespaceAuthorizationKey (org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey)9 Test (org.junit.Test)9 UserNamespaceAuthorization (org.finra.herd.model.api.xml.UserNamespaceAuthorization)5 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1