Search in sources :

Example 21 with UserNamespaceAuthorizationKey

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

the class UserNamespaceAuthorizationServiceTest method testGetUserNamespaceAuthorization.

// Unit tests for getUserNamespaceAuthorization().
@Test
public void testGetUserNamespaceAuthorization() {
    // 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 a user namespace authorization.
    UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.getUserNamespaceAuthorization(key);
    // 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) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 22 with UserNamespaceAuthorizationKey

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

the class UserNamespaceAuthorizationDaoTest method testGetUserNamespaceAuthorizationsByNamespace.

@Test
public void testGetUserNamespaceAuthorizationsByNamespace() {
    // 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.
    List<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntities = new ArrayList<>();
    for (UserNamespaceAuthorizationKey key : keys) {
        userNamespaceAuthorizationEntities.add(userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS));
    }
    // Get user namespace authorizations by namespace.
    assertEquals(Arrays.asList(userNamespaceAuthorizationEntities.get(3), userNamespaceAuthorizationEntities.get(1)), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByNamespace(NAMESPACE));
    // Test case insensitivity of the namespace input parameter.
    assertEquals(Arrays.asList(userNamespaceAuthorizationEntities.get(3), userNamespaceAuthorizationEntities.get(1)), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByNamespace(NAMESPACE.toUpperCase()));
    assertEquals(Arrays.asList(userNamespaceAuthorizationEntities.get(3), userNamespaceAuthorizationEntities.get(1)), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByNamespace(NAMESPACE.toLowerCase()));
    // Try to retrieve user namespace authorization using a non-existing namespace.
    assertEquals(new ArrayList<>(), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByNamespace(NAMESPACE_3));
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) ArrayList(java.util.ArrayList) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) Test(org.junit.Test)

Example 23 with UserNamespaceAuthorizationKey

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

the class UserNamespaceAuthorizationDaoTest method testGetUserNamespaceAuthorizationByKey.

@Test
public void testGetUserNamespaceAuthorizationByKey() {
    // Create and persist the relative database entities.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(USER_ID, namespaceEntity, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE));
    // Get a user namespace authorization.
    assertEquals(userNamespaceAuthorizationEntity, userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE)));
    // Test case insensitivity of user namespace authorization key.
    assertEquals(userNamespaceAuthorizationEntity, userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(new UserNamespaceAuthorizationKey(USER_ID.toUpperCase(), NAMESPACE.toUpperCase())));
    assertEquals(userNamespaceAuthorizationEntity, userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(new UserNamespaceAuthorizationKey(USER_ID.toLowerCase(), NAMESPACE.toLowerCase())));
    // Try to retrieve user namespace authorization using invalid input parameters.
    assertNull(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(new UserNamespaceAuthorizationKey("I_DO_NOT_EXIST", NAMESPACE)));
    assertNull(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(new UserNamespaceAuthorizationKey(USER_ID, "I_DO_NOT_EXIST")));
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) Test(org.junit.Test)

Example 24 with UserNamespaceAuthorizationKey

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

the class UserNamespaceAuthorizationRestControllerTest method testUpdateUserNamespaceAuthorization.

@Test
public void testUpdateUserNamespaceAuthorization() {
    // Create a user namespace authorization key
    UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
    UserNamespaceAuthorization userNamespaceAuthorization = new UserNamespaceAuthorization(ID, key, Arrays.asList(NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT));
    UserNamespaceAuthorizationUpdateRequest request = new UserNamespaceAuthorizationUpdateRequest(Arrays.asList(NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT));
    // Mock calls to external method.
    when(userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, request)).thenReturn(userNamespaceAuthorization);
    // Update a user namespace authorization.
    UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationRestController.updateUserNamespaceAuthorization(key.getUserId(), key.getNamespace(), request);
    // Verify the external calls.
    verify(userNamespaceAuthorizationService).updateUserNamespaceAuthorization(key, request);
    verifyNoMoreInteractions(userNamespaceAuthorizationService);
    // Validate the returned object.
    assertEquals(userNamespaceAuthorization, resultUserNamespaceAuthorization);
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationUpdateRequest(org.finra.herd.model.api.xml.UserNamespaceAuthorizationUpdateRequest) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 25 with UserNamespaceAuthorizationKey

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

the class UserNamespaceAuthorizationServiceTest method testGetUserNamespaceAuthorizationsByNamespace.

// Unit tests for getUserNamespaceAuthorizationsByNamespace().
@Test
public void testGetUserNamespaceAuthorizationsByNamespace() 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 namespace.
    UserNamespaceAuthorizations resultUserNamespaceAuthorizations = userNamespaceAuthorizationService.getUserNamespaceAuthorizationsByNamespace(NAMESPACE);
    // 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(1), 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)

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