Search in sources :

Example 6 with NamespaceIamRoleAuthorization

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

the class NamespaceIamRoleAuthorizationRestControllerTest method updateNamespaceIamRoleAuthorizationAssertCallsService.

/**
 * Asserts that updateNamespaceIamRoleAuthorization() calls service with correct parameters, and returns whatever the service returns.
 */
@Test
public void updateNamespaceIamRoleAuthorizationAssertCallsService() {
    String expectedNamespace = "namespace";
    NamespaceIamRoleAuthorizationUpdateRequest expectedRequest = new NamespaceIamRoleAuthorizationUpdateRequest();
    NamespaceIamRoleAuthorization expectedResult = new NamespaceIamRoleAuthorization();
    when(namespaceIamRoleAuthorizationService.updateNamespaceIamRoleAuthorization(any(), any())).thenReturn(expectedResult);
    NamespaceIamRoleAuthorization actualResult = namespaceIamRoleAuthorizationRestController.updateNamespaceIamRoleAuthorization(expectedNamespace, expectedRequest);
    verify(namespaceIamRoleAuthorizationService).updateNamespaceIamRoleAuthorization(expectedNamespace, expectedRequest);
    verifyNoMoreInteractions(namespaceIamRoleAuthorizationService);
    assertEquals(expectedResult, actualResult);
}
Also used : NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) NamespaceIamRoleAuthorizationUpdateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationUpdateRequest) Test(org.junit.Test)

Example 7 with NamespaceIamRoleAuthorization

use of org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization 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 8 with NamespaceIamRoleAuthorization

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

the class NamespaceIamRoleAuthorizationServiceTest method getNamespaceIamRoleAuthorizationAssertInputsTrimmed.

@Test
public void getNamespaceIamRoleAuthorizationAssertInputsTrimmed() {
    String expectedNamespace = " namespace ";
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities);
    NamespaceIamRoleAuthorization namespaceIamRoleAuthorization = namespaceIamRoleAuthorizationServiceImpl.getNamespaceIamRoleAuthorization(expectedNamespace);
    assertNotNull(namespaceIamRoleAuthorization);
    assertEquals(expectedNamespaceEntity.getCode(), namespaceIamRoleAuthorization.getNamespace());
    assertNotNull(namespaceIamRoleAuthorization.getIamRoles());
    assertEquals(2, namespaceIamRoleAuthorization.getIamRoles().size());
    {
        IamRole iamRole = namespaceIamRoleAuthorization.getIamRoles().get(0);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), iamRole.getIamRoleDescription());
    }
    {
        IamRole iamRole = namespaceIamRoleAuthorization.getIamRoles().get(1);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), iamRole.getIamRoleDescription());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedNamespace.trim());
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) ArrayList(java.util.ArrayList) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) Test(org.junit.Test)

Example 9 with NamespaceIamRoleAuthorization

use of org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization 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)

Example 10 with NamespaceIamRoleAuthorization

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

the class NamespaceIamRoleAuthorizationServiceTest method getNamespaceIamRoleAuthorizationsAssertCallsDependenciesAndResultExpected.

@Test
public void getNamespaceIamRoleAuthorizationsAssertCallsDependenciesAndResultExpected() {
    NamespaceEntity namespaceEntity1 = new NamespaceEntity();
    namespaceEntity1.setCode("namespace1");
    NamespaceEntity namespaceEntity2 = new NamespaceEntity();
    namespaceEntity2.setCode("namespace2");
    List<NamespaceIamRoleAuthorizationEntity> expectedNamespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity3 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity3.setNamespace(namespaceEntity2);
    namespaceIamRoleAuthorizationEntity3.setIamRoleName("iamRoleName3");
    namespaceIamRoleAuthorizationEntity3.setDescription("description3");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity3);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity4 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity4.setNamespace(namespaceEntity2);
    namespaceIamRoleAuthorizationEntity4.setIamRoleName("iamRoleName4");
    namespaceIamRoleAuthorizationEntity4.setDescription("description4");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity4);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(expectedNamespaceIamRoleAuthorizationEntities);
    NamespaceIamRoleAuthorizations result = namespaceIamRoleAuthorizationServiceImpl.getNamespaceIamRoleAuthorizations();
    assertNotNull(result);
    assertNotNull(result.getNamespaceIamRoleAuthorizations());
    assertEquals(2, result.getNamespaceIamRoleAuthorizations().size());
    {
        NamespaceIamRoleAuthorization namespaceIamRoleAuthorization = result.getNamespaceIamRoleAuthorizations().get(0);
        assertNotNull(namespaceIamRoleAuthorization);
        assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorization.getNamespace());
        assertNotNull(namespaceIamRoleAuthorization.getIamRoles());
        assertEquals(2, namespaceIamRoleAuthorization.getIamRoles().size());
        {
            IamRole iamRole = namespaceIamRoleAuthorization.getIamRoles().get(0);
            assertNotNull(iamRole);
            assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), iamRole.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), iamRole.getIamRoleDescription());
        }
        {
            IamRole iamRole = namespaceIamRoleAuthorization.getIamRoles().get(1);
            assertNotNull(iamRole);
            assertEquals(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), iamRole.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), iamRole.getIamRoleDescription());
        }
    }
    {
        NamespaceIamRoleAuthorization namespaceIamRoleAuthorization = result.getNamespaceIamRoleAuthorizations().get(1);
        assertNotNull(namespaceIamRoleAuthorization);
        assertEquals(namespaceEntity2.getCode(), namespaceIamRoleAuthorization.getNamespace());
        assertNotNull(namespaceIamRoleAuthorization.getIamRoles());
        assertEquals(2, namespaceIamRoleAuthorization.getIamRoles().size());
        {
            IamRole iamRole = namespaceIamRoleAuthorization.getIamRoles().get(0);
            assertNotNull(iamRole);
            assertEquals(namespaceIamRoleAuthorizationEntity3.getIamRoleName(), iamRole.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity3.getDescription(), iamRole.getIamRoleDescription());
        }
        {
            IamRole iamRole = namespaceIamRoleAuthorization.getIamRoles().get(1);
            assertNotNull(iamRole);
            assertEquals(namespaceIamRoleAuthorizationEntity4.getIamRoleName(), iamRole.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity4.getDescription(), iamRole.getIamRoleDescription());
        }
    }
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(null);
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorizations(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizations) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) ArrayList(java.util.ArrayList) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) Test(org.junit.Test)

Aggregations

NamespaceIamRoleAuthorization (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization)18 IamRole (org.finra.herd.model.api.xml.IamRole)14 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)13 Test (org.junit.Test)13 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)12 ArrayList (java.util.ArrayList)7 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 NamespaceIamRoleAuthorizationCreateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest)3 NamespaceIamRoleAuthorizationUpdateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationUpdateRequest)3 NamespaceIamRoleAuthorizations (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizations)2 LinkedHashMap (java.util.LinkedHashMap)1