Search in sources :

Example 6 with UserNamespaceAuthorizationUpdateRequest

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

the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorizationMissingRequiredParameters.

@Test
public void testUpdateUserNamespaceAuthorizationMissingRequiredParameters() {
    // Create a user namespace authorization key.
    UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
    // Try to update a user namespace authorization when user namespace authorization key is not specified.
    try {
        userNamespaceAuthorizationService.updateUserNamespaceAuthorization(null, new UserNamespaceAuthorizationUpdateRequest(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 update a user namespace authorization when user id is not specified.
    try {
        userNamespaceAuthorizationService.updateUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(BLANK_TEXT, NAMESPACE), new UserNamespaceAuthorizationUpdateRequest(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 update a user namespace authorization when namespace is not specified.
    try {
        userNamespaceAuthorizationService.updateUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(USER_ID, BLANK_TEXT), new UserNamespaceAuthorizationUpdateRequest(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 update a user namespace authorization when permissions are not specified (passed as null).
    try {
        userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(null));
        fail("Should throw an IllegalArgumentException when permissions are not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("Namespace permissions must be specified.", e.getMessage());
    }
    // Try to update a user namespace authorization when permissions are not specified (passed as an empty list).
    try {
        userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(new ArrayList<>()));
        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) ArrayList(java.util.ArrayList) UserNamespaceAuthorizationUpdateRequest(org.finra.herd.model.api.xml.UserNamespaceAuthorizationUpdateRequest) Test(org.junit.Test)

Example 7 with UserNamespaceAuthorizationUpdateRequest

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

the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorizationTrimParameters.

@Test
public void testUpdateUserNamespaceAuthorizationTrimParameters() {
    // 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 input parameters with leading and trailing empty spaces.
    UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(addWhitespace(key.getUserId()), addWhitespace(key.getNamespace())), 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 8 with UserNamespaceAuthorizationUpdateRequest

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

the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorization.

// Unit tests for updateUserNamespaceAuthorization().
@Test
public void testUpdateUserNamespaceAuthorization() {
    // 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.
    UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(Arrays.asList(NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT)));
    // Validate the returned object.
    assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, Arrays.asList(NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT)), resultUserNamespaceAuthorization);
    // Revert the update. This is done for the branch unit test coverage.
    resultUserNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE)));
    // Validate the returned object.
    assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE)), 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)

Aggregations

UserNamespaceAuthorizationKey (org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey)8 UserNamespaceAuthorizationUpdateRequest (org.finra.herd.model.api.xml.UserNamespaceAuthorizationUpdateRequest)8 Test (org.junit.Test)8 UserNamespaceAuthorization (org.finra.herd.model.api.xml.UserNamespaceAuthorization)5 UserNamespaceAuthorizationEntity (org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity)4 ArrayList (java.util.ArrayList)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1