Search in sources :

Example 16 with IamRole

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

the class NamespaceIamRoleAuthorizationServiceTest method updateNamespaceIamRoleAuthorizationAssertInputsTrimmed.

@Test
public void updateNamespaceIamRoleAuthorizationAssertInputsTrimmed() {
    String expectedNamespace = " namespace ";
    List<IamRole> iamRoles = new ArrayList<>();
    IamRole iamRole1 = new IamRole(" iamRoleName1 ", " iamRoleDescription1 ");
    iamRoles.add(iamRole1);
    IamRole iamRole2 = new IamRole(" iamRoleName2 ", " ");
    iamRoles.add(iamRole2);
    NamespaceIamRoleAuthorizationUpdateRequest expectedNamespaceIamRoleAuthorizationUpdateRequest = new NamespaceIamRoleAuthorizationUpdateRequest(iamRoles);
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities);
    NamespaceIamRoleAuthorization result = namespaceIamRoleAuthorizationServiceImpl.updateNamespaceIamRoleAuthorization(expectedNamespace, expectedNamespaceIamRoleAuthorizationUpdateRequest);
    assertNotNull(result);
    assertEquals(expectedNamespaceEntity.getCode(), result.getNamespace());
    assertNotNull(result.getIamRoles());
    assertEquals(2, result.getIamRoles().size());
    {
        IamRole iamRole = result.getIamRoles().get(0);
        assertNotNull(iamRole);
        assertEquals(iamRole1.getIamRoleName().trim(), iamRole.getIamRoleName());
        assertEquals(iamRole1.getIamRoleDescription().trim(), iamRole.getIamRoleDescription());
    }
    {
        IamRole iamRole = result.getIamRoles().get(1);
        assertNotNull(iamRole);
        assertEquals(iamRole2.getIamRoleName().trim(), iamRole.getIamRoleName());
        assertEquals(null, iamRole.getIamRoleDescription());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedNamespace.trim());
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verify(namespaceIamRoleAuthorizationDao).delete(namespaceIamRoleAuthorizationEntity);
    verify(namespaceIamRoleAuthorizationDao).saveAndRefresh(namespaceIamRoleAuthorizationEntityEq(expectedNamespaceEntity.getCode(), iamRole1.getIamRoleName().trim(), iamRole1.getIamRoleDescription().trim()));
    verify(namespaceIamRoleAuthorizationDao).saveAndRefresh(namespaceIamRoleAuthorizationEntityEq(expectedNamespaceEntity.getCode(), iamRole2.getIamRoleName().trim(), null));
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) IamRole(org.finra.herd.model.api.xml.IamRole) ArrayList(java.util.ArrayList) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) NamespaceIamRoleAuthorizationUpdateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationUpdateRequest) Test(org.junit.Test)

Example 17 with IamRole

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

the class NamespaceIamRoleAuthorizationServiceTest method getNamespaceIamRoleAuthorizationAssertDependenciesCalledAndResultExpected.

@Test
public void getNamespaceIamRoleAuthorizationAssertDependenciesCalledAndResultExpected() {
    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);
    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 18 with IamRole

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

the class NamespaceIamRoleAuthorizationServiceTest method deleteNamespaceIamRoleAuthorizationAssertInputsAreTrimmed.

@Test
public void deleteNamespaceIamRoleAuthorizationAssertInputsAreTrimmed() {
    String expectedNamespace = " namespace ";
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    List<NamespaceIamRoleAuthorizationEntity> expectedNamespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(expectedNamespaceIamRoleAuthorizationEntities);
    NamespaceIamRoleAuthorization result = namespaceIamRoleAuthorizationServiceImpl.deleteNamespaceIamRoleAuthorization(expectedNamespace);
    assertNotNull(result);
    assertEquals(expectedNamespaceEntity.getCode(), result.getNamespace());
    assertNotNull(result.getIamRoles());
    assertEquals(2, result.getIamRoles().size());
    {
        IamRole iamRole = result.getIamRoles().get(0);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), iamRole.getIamRoleDescription());
    }
    {
        IamRole iamRole = result.getIamRoles().get(1);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), iamRole.getIamRoleDescription());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedNamespace.trim());
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verify(namespaceIamRoleAuthorizationDao).delete(namespaceIamRoleAuthorizationEntity1);
    verify(namespaceIamRoleAuthorizationDao).delete(namespaceIamRoleAuthorizationEntity2);
    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 19 with IamRole

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

the class NamespaceIamRoleAuthorizationServiceTest method deleteNamespaceIamRoleAuthorizationAssertCallsDependenciesAndResultExpected.

@Test
public void deleteNamespaceIamRoleAuthorizationAssertCallsDependenciesAndResultExpected() {
    String expectedNamespace = "namespace";
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    List<NamespaceIamRoleAuthorizationEntity> expectedNamespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(expectedNamespaceIamRoleAuthorizationEntities);
    NamespaceIamRoleAuthorization result = namespaceIamRoleAuthorizationServiceImpl.deleteNamespaceIamRoleAuthorization(expectedNamespace);
    assertNotNull(result);
    assertEquals(expectedNamespaceEntity.getCode(), result.getNamespace());
    assertNotNull(result.getIamRoles());
    assertEquals(2, result.getIamRoles().size());
    {
        IamRole iamRole = result.getIamRoles().get(0);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), iamRole.getIamRoleDescription());
    }
    {
        IamRole iamRole = result.getIamRoles().get(1);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), iamRole.getIamRoleDescription());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedNamespace);
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verify(namespaceIamRoleAuthorizationDao).delete(namespaceIamRoleAuthorizationEntity1);
    verify(namespaceIamRoleAuthorizationDao).delete(namespaceIamRoleAuthorizationEntity2);
    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 20 with IamRole

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

the class NamespaceIamRoleAuthorizationServiceImpl method getNamespaceIamRoleAuthorizations.

@Override
public NamespaceIamRoleAuthorizations getNamespaceIamRoleAuthorizations() {
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(null);
    Map<String, NamespaceIamRoleAuthorization> map = new LinkedHashMap<>();
    for (NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity : namespaceIamRoleAuthorizationEntities) {
        String namespace = namespaceIamRoleAuthorizationEntity.getNamespace().getCode();
        NamespaceIamRoleAuthorization namespaceIamRoleAuthorization = map.get(namespace);
        if (namespaceIamRoleAuthorization == null) {
            map.put(namespace, namespaceIamRoleAuthorization = new NamespaceIamRoleAuthorization(namespace, new ArrayList<>()));
        }
        namespaceIamRoleAuthorization.getIamRoles().add(new IamRole(namespaceIamRoleAuthorizationEntity.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getDescription()));
    }
    return new NamespaceIamRoleAuthorizations(new ArrayList<>(map.values()));
}
Also used : NamespaceIamRoleAuthorizations(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizations) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

IamRole (org.finra.herd.model.api.xml.IamRole)22 Test (org.junit.Test)16 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)15 NamespaceIamRoleAuthorization (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization)14 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)13 ArrayList (java.util.ArrayList)10 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)7 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)7 NamespaceIamRoleAuthorizationCreateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest)6 NamespaceIamRoleAuthorizationUpdateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationUpdateRequest)5 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 NamespaceIamRoleAuthorizations (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizations)2 LinkedHashMap (java.util.LinkedHashMap)1