Search in sources :

Example 26 with UserNamespaceAuthorizationKey

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);
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) UserNamespaceAuthorizationUpdateRequest(org.finra.herd.model.api.xml.UserNamespaceAuthorizationUpdateRequest) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 27 with UserNamespaceAuthorizationKey

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

Example 28 with UserNamespaceAuthorizationKey

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());
    }
}
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 29 with UserNamespaceAuthorizationKey

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);
}
Also used : UserNamespaceAuthorizations(org.finra.herd.model.api.xml.UserNamespaceAuthorizations) UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 30 with UserNamespaceAuthorizationKey

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

Aggregations

UserNamespaceAuthorizationKey (org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey)44 Test (org.junit.Test)42 UserNamespaceAuthorization (org.finra.herd.model.api.xml.UserNamespaceAuthorization)29 UserNamespaceAuthorizationEntity (org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity)22 UserNamespaceAuthorizationCreateRequest (org.finra.herd.model.api.xml.UserNamespaceAuthorizationCreateRequest)9 UserNamespaceAuthorizationUpdateRequest (org.finra.herd.model.api.xml.UserNamespaceAuthorizationUpdateRequest)8 UserNamespaceAuthorizations (org.finra.herd.model.api.xml.UserNamespaceAuthorizations)8 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)4 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)4 ArrayList (java.util.ArrayList)3 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)2 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1