Search in sources :

Example 31 with IdentityRoleManagementException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method testListRolesWithPOSTInvalidLimit.

@Test(dataProvider = "dataProviderForListRolesWithPOSTInvalidLimit")
public void testListRolesWithPOSTInvalidLimit(String nodeType, Integer count) throws IdentityRoleManagementException {
    Node rootNode = generateNodeBasedOnNodeType(nodeType, "name");
    when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
        Integer countArg = invocationOnMock.getArgumentAt(0, Integer.class);
        if (countArg != null && countArg < 0) {
            String errorMessage = "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " + count;
            throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
        }
        return null;
    });
    when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
        Integer countArg = invocationOnMock.getArgumentAt(1, Integer.class);
        if (countArg != null && countArg < 0) {
            String errorMessage = "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " + count;
            throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
        }
        return null;
    });
    SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
    assertThrows(CharonException.class, () -> roleManager.listRolesWithPost(getDummySearchRequest(rootNode, 2, count, null, null)));
}
Also used : OperationNode(org.wso2.charon3.core.utils.codeutils.OperationNode) ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) Node(org.wso2.charon3.core.utils.codeutils.Node) Matchers.anyString(org.mockito.Matchers.anyString) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 32 with IdentityRoleManagementException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method testListRolesWithGETInvalidOffset.

@Test(dataProvider = "dataProviderForListRolesWithGETInvalidOffset")
public void testListRolesWithGETInvalidOffset(String nodeType, Integer startIndex) throws IdentityRoleManagementException {
    Node rootNode = generateNodeBasedOnNodeType(nodeType, null);
    when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
        Integer startIndexArg = invocationOnMock.getArgumentAt(1, Integer.class);
        if (startIndexArg != null && startIndexArg < 0) {
            String errorMessage = "Invalid offset requested. Offset value should be greater " + "than or equal to zero. offset: " + startIndexArg;
            throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
        }
        return null;
    });
    when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
        Integer startIndexArg = invocationOnMock.getArgumentAt(2, Integer.class);
        if (startIndexArg != null && startIndexArg < 0) {
            String errorMessage = "Invalid offset requested. offset value should be greater than or " + "equal to zero. offset: " + startIndexArg;
            throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
        }
        return null;
    });
    SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
    assertThrows(CharonException.class, () -> roleManager.listRolesWithGET(rootNode, startIndex, 2, null, null));
}
Also used : OperationNode(org.wso2.charon3.core.utils.codeutils.OperationNode) ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) Node(org.wso2.charon3.core.utils.codeutils.Node) Matchers.anyString(org.mockito.Matchers.anyString) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 33 with IdentityRoleManagementException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method testCreateRoleAddRoleExistingRoleName.

@Test
public void testCreateRoleAddRoleExistingRoleName() throws BadRequestException, CharonException, IdentityRoleManagementException {
    Role role = getDummyRole(SAMPLE_VALID_ROLE_ID2, SAMPLE_EXISTING_ROLE_NAME);
    when(mockRoleManagementService.addRole(anyString(), anyListOf(String.class), anyListOf(String.class), anyListOf(String.class), anyString())).thenThrow(new IdentityRoleManagementException(ROLE_ALREADY_EXISTS.getCode(), "Role already exist for the role name: " + SAMPLE_EXISTING_ROLE_NAME));
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
    assertThrows(ConflictException.class, () -> scimRoleManager.createRole(role));
}
Also used : Role(org.wso2.charon3.core.objects.Role) Matchers.anyString(org.mockito.Matchers.anyString) IdentityRoleManagementException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 34 with IdentityRoleManagementException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method testListRolesWithPOSTPositive.

@Test(dataProvider = "dataProviderForListRolesWithPOSTPositive")
public void testListRolesWithPOSTPositive(String nodeType, String operation) throws CharonException, IdentityRoleManagementException, NotImplementedException, BadRequestException {
    Node rootNode = generateNodeBasedOnNodeType(nodeType, "name", operation);
    List<RoleBasicInfo> roleList = getDummyRoleBasicInfoList();
    when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> roleList);
    when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> roleList);
    SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
    roleManager.listRolesWithPost(getDummySearchRequest(rootNode, 2, 3, null, null));
    assertTrue(true, "listRolesWIthPost run successfully");
}
Also used : OperationNode(org.wso2.charon3.core.utils.codeutils.OperationNode) ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) Node(org.wso2.charon3.core.utils.codeutils.Node) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 35 with IdentityRoleManagementException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method testGetRoleNotFound.

@Test(dataProvider = "dataProviderForGetRoleNotFound")
public void testGetRoleNotFound(String roleId, String tenantDomain) throws IdentityRoleManagementException {
    when(mockRoleManagementService.getRole(roleId, tenantDomain)).thenThrow(new IdentityRoleManagementClientException(ROLE_NOT_FOUND.getCode(), String.format("A role doesn't exist with id: %s in the tenantDomain: %s", roleId, tenantDomain)));
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    assertThrows(NotFoundException.class, () -> scimRoleManager.getRole(roleId, null));
}
Also used : IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)29 IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)23 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Test (org.testng.annotations.Test)20 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)20 Connection (java.sql.Connection)19 SQLException (java.sql.SQLException)19 Matchers.anyString (org.mockito.Matchers.anyString)14 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)14 Role (org.wso2.charon3.core.objects.Role)13 ResultSet (java.sql.ResultSet)12 RoleManagementEventPublisherProxy (org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy)11 ArrayList (java.util.ArrayList)9 CharonException (org.wso2.charon3.core.exceptions.CharonException)8 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)8 Node (org.wso2.charon3.core.utils.codeutils.Node)8 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)8 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)6