Search in sources :

Example 16 with UserNamespaceAuthorizationKey

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

the class UserNamespaceAuthorizationServiceTest method testDeleteUserNamespaceAuthorizationNoExists.

@Test
public void testDeleteUserNamespaceAuthorizationNoExists() {
    // Create a user namespace authorization key.
    UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
    // Try to delete a user namespace authorization when it does not exist.
    try {
        userNamespaceAuthorizationService.deleteUserNamespaceAuthorization(key);
        fail("Should throw an ObjectNotFoundException when user namespace authorization does not exist.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("User namespace authorization with user id \"%s\" and namespace \"%s\" doesn't exist.", key.getUserId(), key.getNamespace()), e.getMessage());
    }
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Example 17 with UserNamespaceAuthorizationKey

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

the class UserNamespaceAuthorizationServiceTest method testGetUserNamespaceAuthorizationsByUserId.

// Unit tests for getUserNamespaceAuthorizationsByUserId().
@Test
public void testGetUserNamespaceAuthorizationsByUserId() throws Exception {
    // Create user namespace authorization keys. The keys are listed out of order to validate the order by logic.
    List<UserNamespaceAuthorizationKey> keys = Arrays.asList(new UserNamespaceAuthorizationKey(USER_ID_2, NAMESPACE_2), new UserNamespaceAuthorizationKey(USER_ID_2, NAMESPACE), new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE_2), new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE));
    // Create and persist the relative database entities.
    for (UserNamespaceAuthorizationKey key : keys) {
        userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS);
    }
    // Get user namespace authorizations for the specified user id.
    UserNamespaceAuthorizations resultUserNamespaceAuthorizations = userNamespaceAuthorizationService.getUserNamespaceAuthorizationsByUserId(USER_ID);
    // Validate the returned object.
    assertEquals(new UserNamespaceAuthorizations(Arrays.asList(new UserNamespaceAuthorization(resultUserNamespaceAuthorizations.getUserNamespaceAuthorizations().get(0).getId(), keys.get(3), SUPPORTED_NAMESPACE_PERMISSIONS), new UserNamespaceAuthorization(resultUserNamespaceAuthorizations.getUserNamespaceAuthorizations().get(1).getId(), keys.get(2), SUPPORTED_NAMESPACE_PERMISSIONS))), resultUserNamespaceAuthorizations);
}
Also used : UserNamespaceAuthorizations(org.finra.herd.model.api.xml.UserNamespaceAuthorizations) UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 18 with UserNamespaceAuthorizationKey

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

Example 19 with UserNamespaceAuthorizationKey

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

the class UserNamespaceAuthorizationServiceTest method testDeleteUserNamespaceAuthorizationTrimParameters.

@Test
public void testDeleteUserNamespaceAuthorizationTrimParameters() {
    // 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);
    // Validate that this user namespace authorization exists.
    assertNotNull(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(key));
    // Delete a user namespace authorization using input parameters with leading and trailing empty spaces.
    UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.deleteUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(addWhitespace(key.getUserId()), addWhitespace(key.getNamespace())));
    // Validate the returned object.
    assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
    // Ensure that this user namespace authorization is no longer there.
    assertNull(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(key));
}
Also used : 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 20 with UserNamespaceAuthorizationKey

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

the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorizationDuplicatePermissions.

@Test
public void testUpdateUserNamespaceAuthorizationDuplicatePermissions() {
    // Try to update a user namespace authorization using duplicate permission values.
    UserNamespaceAuthorizationUpdateRequest request = new UserNamespaceAuthorizationUpdateRequest(Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.READ));
    try {
        userNamespaceAuthorizationService.updateUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE), 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) UserNamespaceAuthorizationUpdateRequest(org.finra.herd.model.api.xml.UserNamespaceAuthorizationUpdateRequest) 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