Search in sources :

Example 6 with NamespaceIamRoleAuthorizationCreateRequest

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

the class NamespaceIamRoleAuthorizationServiceTest method createNamespaceIamRoleAuthorizationAssertInputsTrimmed.

@Test
public void createNamespaceIamRoleAuthorizationAssertInputsTrimmed() {
    IamRole expectedIamRole1 = new IamRole(" iamRoleName1 ", " iamRoleDescription1 ");
    IamRole expectedIamRole2 = new IamRole(" iamRoleName2 ", " ");
    List<IamRole> expectedIamRoles = Arrays.asList(expectedIamRole1, expectedIamRole2);
    NamespaceIamRoleAuthorizationCreateRequest expectedRequest = new NamespaceIamRoleAuthorizationCreateRequest(" namespace ", expectedIamRoles);
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(Collections.emptyList());
    NamespaceIamRoleAuthorization response = namespaceIamRoleAuthorizationServiceImpl.createNamespaceIamRoleAuthorization(expectedRequest);
    assertNotNull(response);
    assertEquals(expectedNamespaceEntity.getCode(), response.getNamespace());
    assertNotNull(response.getIamRoles());
    assertEquals(expectedIamRoles.size(), response.getIamRoles().size());
    {
        IamRole iamRole = response.getIamRoles().get(0);
        assertNotNull(iamRole);
        assertEquals(expectedIamRole1.getIamRoleName().trim(), iamRole.getIamRoleName());
        assertEquals(expectedIamRole1.getIamRoleDescription().trim(), iamRole.getIamRoleDescription());
    }
    {
        IamRole iamRole = response.getIamRoles().get(1);
        assertNotNull(iamRole);
        assertEquals(expectedIamRole2.getIamRoleName().trim(), iamRole.getIamRoleName());
        assertEquals(null, iamRole.getIamRoleDescription());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedRequest.getNamespace().trim());
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verify(namespaceIamRoleAuthorizationDao).saveAndRefresh(namespaceIamRoleAuthorizationEntityEq(expectedNamespaceEntity.getCode(), expectedIamRole1.getIamRoleName().trim(), expectedIamRole1.getIamRoleDescription().trim()));
    verify(namespaceIamRoleAuthorizationDao).saveAndRefresh(namespaceIamRoleAuthorizationEntityEq(expectedNamespaceEntity.getCode(), expectedIamRole2.getIamRoleName().trim(), null));
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceIamRoleAuthorizationCreateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) IamRole(org.finra.herd.model.api.xml.IamRole) Test(org.junit.Test)

Example 7 with NamespaceIamRoleAuthorizationCreateRequest

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

the class NamespaceIamRoleAuthorizationServiceTest method createNamespaceIamRoleAuthorizationAssertDependenciesCalledAndResultExpected.

@Test
public void createNamespaceIamRoleAuthorizationAssertDependenciesCalledAndResultExpected() {
    IamRole expectedIamRole1 = new IamRole("iamRoleName1", "iamRoleDescription1");
    IamRole expectedIamRole2 = new IamRole("iamRoleName2", " ");
    List<IamRole> expectedIamRoles = Arrays.asList(expectedIamRole1, expectedIamRole2);
    NamespaceIamRoleAuthorizationCreateRequest expectedRequest = new NamespaceIamRoleAuthorizationCreateRequest("namespace", expectedIamRoles);
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(Collections.emptyList());
    NamespaceIamRoleAuthorization response = namespaceIamRoleAuthorizationServiceImpl.createNamespaceIamRoleAuthorization(expectedRequest);
    assertNotNull(response);
    assertEquals(expectedNamespaceEntity.getCode(), response.getNamespace());
    assertNotNull(response.getIamRoles());
    assertEquals(expectedIamRoles.size(), response.getIamRoles().size());
    {
        IamRole iamRole = response.getIamRoles().get(0);
        assertNotNull(iamRole);
        assertEquals(expectedIamRole1.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(expectedIamRole1.getIamRoleDescription(), iamRole.getIamRoleDescription());
    }
    {
        IamRole iamRole = response.getIamRoles().get(1);
        assertNotNull(iamRole);
        assertEquals(expectedIamRole2.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(null, iamRole.getIamRoleDescription());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedRequest.getNamespace());
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verify(namespaceIamRoleAuthorizationDao).saveAndRefresh(namespaceIamRoleAuthorizationEntityEq(expectedNamespaceEntity.getCode(), expectedIamRole1.getIamRoleName(), expectedIamRole1.getIamRoleDescription()));
    verify(namespaceIamRoleAuthorizationDao).saveAndRefresh(namespaceIamRoleAuthorizationEntityEq(expectedNamespaceEntity.getCode(), expectedIamRole2.getIamRoleName(), null));
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceIamRoleAuthorizationCreateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) IamRole(org.finra.herd.model.api.xml.IamRole) Test(org.junit.Test)

Aggregations

NamespaceIamRoleAuthorizationCreateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest)7 Test (org.junit.Test)7 IamRole (org.finra.herd.model.api.xml.IamRole)6 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)4 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)4 NamespaceIamRoleAuthorization (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization)3 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)3 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)1