use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationHelperTest method checkPermissionsAssertRoleNameIsCaseInsensitive.
@Test
public void checkPermissionsAssertRoleNameIsCaseInsensitive() {
NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
String iamRoleName1 = "iamRoleName1";
String iamRoleName2 = "iamRoleName2";
Collection<String> requestedIamRoleNames = Arrays.asList(StringUtils.capitalize(iamRoleName1), StringUtils.capitalize(iamRoleName2));
List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>();
NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
namespaceIamRoleAuthorizationEntity1.setIamRoleName(iamRoleName1);
namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
namespaceIamRoleAuthorizationEntity2.setIamRoleName(iamRoleName2);
namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities);
namespaceIamRoleAuthorizationHelper.checkPermissions(expectedNamespaceEntity, requestedIamRoleNames);
verify(configurationHelper).getBooleanProperty(ConfigurationValue.NAMESPACE_IAM_ROLE_AUTHORIZATION_ENABLED);
verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
verifyNoMoreInteractions(configurationHelper, namespaceIamRoleAuthorizationDao);
}
use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationDaoTest method getNamespaceIamRoleAuthorizationsAssertOrderByRoleName.
@Test
public void getNamespaceIamRoleAuthorizationsAssertOrderByRoleName() {
NamespaceEntity namespaceEntity1 = namespaceDaoTestHelper.createNamespaceEntity();
NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
namespaceIamRoleAuthorizationEntity1.setNamespace(namespaceEntity1);
namespaceIamRoleAuthorizationEntity1.setIamRoleName("Z");
namespaceIamRoleAuthorizationEntity1.setDescription("description1");
namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity1);
NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
namespaceIamRoleAuthorizationEntity2.setNamespace(namespaceEntity1);
namespaceIamRoleAuthorizationEntity2.setIamRoleName("A");
namespaceIamRoleAuthorizationEntity2.setDescription("description2");
namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity2);
{
List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizations = namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity1);
assertNotNull(namespaceIamRoleAuthorizations);
assertEquals(2, namespaceIamRoleAuthorizations.size());
{
NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(0);
assertNotNull(namespaceIamRoleAuthorizationEntity);
assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
assertEquals(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
}
{
NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(1);
assertNotNull(namespaceIamRoleAuthorizationEntity);
assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
}
}
}
use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationDaoImpl method getNamespaceIamRoleAuthorizations.
@Override
public List<NamespaceIamRoleAuthorizationEntity> getNamespaceIamRoleAuthorizations(NamespaceEntity namespaceEntity) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<NamespaceIamRoleAuthorizationEntity> query = criteriaBuilder.createQuery(NamespaceIamRoleAuthorizationEntity.class);
Root<NamespaceIamRoleAuthorizationEntity> root = query.from(NamespaceIamRoleAuthorizationEntity.class);
Join<NamespaceIamRoleAuthorizationEntity, NamespaceEntity> namespaceJoin = root.join(NamespaceIamRoleAuthorizationEntity_.namespace);
if (namespaceEntity != null) {
query.where(criteriaBuilder.equal(root.get(NamespaceIamRoleAuthorizationEntity_.namespace), namespaceEntity));
}
query.orderBy(criteriaBuilder.asc(namespaceJoin.get(NamespaceEntity_.code)), criteriaBuilder.asc(root.get(NamespaceIamRoleAuthorizationEntity_.iamRoleName)));
return entityManager.createQuery(query).getResultList();
}
use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceTest method createNamespaceIamRoleAuthorizationAssertErrorWhenAuthorizationAlreadyExist.
@Test
public void createNamespaceIamRoleAuthorizationAssertErrorWhenAuthorizationAlreadyExist() {
IamRole expectedIamRole1 = new IamRole("iamRoleName1", "iamRoleDescription1");
IamRole expectedIamRole2 = new IamRole("iamRoleName2", "iamRoleDescription2");
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(Arrays.asList(new NamespaceIamRoleAuthorizationEntity()));
try {
namespaceIamRoleAuthorizationServiceImpl.createNamespaceIamRoleAuthorization(expectedRequest);
fail();
} catch (Exception e) {
assertEquals(AlreadyExistsException.class, e.getClass());
assertEquals(String.format("Namespace IAM role authorizations with namespace \"%s\" already exist", expectedNamespaceEntity.getCode()), e.getMessage());
}
verify(namespaceDaoHelper).getNamespaceEntity(expectedRequest.getNamespace());
verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity 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);
}
Aggregations