Search in sources :

Example 1 with NamespaceIamRoleAuthorizationCreateRequest

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

the class NamespaceIamRoleAuthorizationRestControllerTest method createNamespaceIamRoleAuthorizationAssertCallsService.

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

Example 2 with NamespaceIamRoleAuthorizationCreateRequest

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

the class NamespaceIamRoleAuthorizationServiceTest method createNamespaceIamRoleAuthorizationAssertErrorWhenNamespaceIsBlank.

@Test
public void createNamespaceIamRoleAuthorizationAssertErrorWhenNamespaceIsBlank() {
    IamRole expectedIamRole1 = new IamRole("iamRoleName1", "iamRoleDescription1");
    IamRole expectedIamRole2 = new IamRole("iamRoleName2", " ");
    List<IamRole> expectedIamRoles = Arrays.asList(expectedIamRole1, expectedIamRole2);
    NamespaceIamRoleAuthorizationCreateRequest expectedRequest = new NamespaceIamRoleAuthorizationCreateRequest(" ", expectedIamRoles);
    try {
        namespaceIamRoleAuthorizationServiceImpl.createNamespaceIamRoleAuthorization(expectedRequest);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("Namespace must be specified", e.getMessage());
    }
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceIamRoleAuthorizationCreateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest) IamRole(org.finra.herd.model.api.xml.IamRole) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 3 with NamespaceIamRoleAuthorizationCreateRequest

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

the class NamespaceIamRoleAuthorizationServiceTest method createNamespaceIamRoleAuthorizationAssertErrorWhenRoleNameIsBlank.

@Test
public void createNamespaceIamRoleAuthorizationAssertErrorWhenRoleNameIsBlank() {
    IamRole expectedIamRole1 = new IamRole("iamRoleName1", "iamRoleDescription1");
    IamRole expectedIamRole2 = new IamRole(" ", "iamRoleDescription2");
    List<IamRole> expectedIamRoles = Arrays.asList(expectedIamRole1, expectedIamRole2);
    NamespaceIamRoleAuthorizationCreateRequest expectedRequest = new NamespaceIamRoleAuthorizationCreateRequest("namespace", expectedIamRoles);
    try {
        namespaceIamRoleAuthorizationServiceImpl.createNamespaceIamRoleAuthorization(expectedRequest);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("IAM role name must be specified", e.getMessage());
    }
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceIamRoleAuthorizationCreateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest) IamRole(org.finra.herd.model.api.xml.IamRole) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 4 with NamespaceIamRoleAuthorizationCreateRequest

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

the class NamespaceIamRoleAuthorizationServiceTest method createNamespaceIamRoleAuthorizationAssertErrorWhenIamRolesEmpty.

@Test
public void createNamespaceIamRoleAuthorizationAssertErrorWhenIamRolesEmpty() {
    List<IamRole> expectedIamRoles = Arrays.asList();
    NamespaceIamRoleAuthorizationCreateRequest expectedRequest = new NamespaceIamRoleAuthorizationCreateRequest("namespace", expectedIamRoles);
    try {
        namespaceIamRoleAuthorizationServiceImpl.createNamespaceIamRoleAuthorization(expectedRequest);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("At least 1 IAM roles must be specified", e.getMessage());
    }
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceIamRoleAuthorizationCreateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest) IamRole(org.finra.herd.model.api.xml.IamRole) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 5 with NamespaceIamRoleAuthorizationCreateRequest

use of org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest 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);
}
Also used : NamespaceIamRoleAuthorizationCreateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) 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