Search in sources :

Example 26 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 testCreateRoleExistingRole.

@Test(dataProvider = "dataProviderForCreateRoleExistingRole")
public void testCreateRoleExistingRole(String roleId, String roleDisplayName) throws IdentityRoleManagementException, BadRequestException, CharonException {
    Role role = getDummyRole(roleId, roleDisplayName);
    when(mockRoleManagementService.isExistingRole(anyString(), anyString())).thenReturn(true);
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN2);
    assertThrows(ConflictException.class, () -> scimRoleManager.createRole(role));
}
Also used : Role(org.wso2.charon3.core.objects.Role) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 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 testListRolesWithGETInvalidLimit.

@Test(dataProvider = "dataProviderForListRolesWithGETInvalidLimit")
public void testListRolesWithGETInvalidLimit(String nodeType, Integer count) throws IdentityRoleManagementException {
    Node rootNode = generateNodeBasedOnNodeType(nodeType, null);
    when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
        Integer countArg = invocationOnMock.getArgumentAt(0, Integer.class);
        if (countArg != null && countArg < 0) {
            String errorMessage = String.format("Invalid limit requested. Limit value should be " + "greater than or equal to zero. limit: %s", 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 = String.format("Invalid limit requested. Limit value should be " + "greater than or equal to zero. limit: %s", count);
            throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
        }
        return null;
    });
    SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
    assertThrows(CharonException.class, () -> roleManager.listRolesWithGET(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 28 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 testUpdateRoleUpdateGroupListOfRoleThrowingErrors.

@Test(dataProvider = "dataProviderForUpdateRoleUpdateGroupListOfRoleThrowingErrors", expectedExceptions = { BadRequestException.class, CharonException.class })
public void testUpdateRoleUpdateGroupListOfRoleThrowingErrors(String roleId, String oldRoleName, String newRoleName, String tenantDomain, String type, String sError) throws IdentityRoleManagementException, BadRequestException, CharonException, ConflictException, NotFoundException {
    RoleBasicInfo roleBasicInfo = new RoleBasicInfo(roleId, newRoleName);
    Role[] oldAndNewRoles = getOldAndNewRoleDummies(roleId, oldRoleName, newRoleName, type);
    when(mockRoleManagementService.updateRoleName(anyString(), anyString(), anyString())).thenReturn(roleBasicInfo);
    when(mockRoleManagementService.updateGroupListOfRole(anyString(), anyListOf(String.class), anyListOf(String.class), anyString())).thenAnswer(invocationOnMock -> {
        String roleIdArg = invocationOnMock.getArgumentAt(0, String.class);
        String tenantDomainArg = invocationOnMock.getArgumentAt(3, String.class);
        if (INVALID_ROLE_IDS.contains(roleIdArg)) {
            String errorMessage = "Invalid scenario. Multiple roles found for the given role name: " + roleIdArg + " and tenantDomain: " + tenantDomain;
            throw new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), errorMessage);
        }
        Throwable unExpectedErrors = unExpectedErrorThrower(tenantDomainArg, sError, "Error while updating users to the role: %s in the tenantDomain: %s", roleIdArg);
        if (unExpectedErrors != null)
            throw unExpectedErrors;
        return roleBasicInfo;
    });
    when(mockRoleManagementService.updateUserListOfRole(eq(roleId), anyListOf(String.class), anyListOf(String.class), anyString())).thenReturn(roleBasicInfo);
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    scimRoleManager.updateRole(oldAndNewRoles[0], oldAndNewRoles[1]);
}
Also used : Role(org.wso2.charon3.core.objects.Role) Matchers.anyString(org.mockito.Matchers.anyString) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 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 testListRolesWithPOSTUnExpectedServerError.

@Test(dataProvider = "dataProviderForListRolesWithPOSTUnExpectedServerError")
public void testListRolesWithPOSTUnExpectedServerError(String nodeType, String tenantDomain, String sError) throws IdentityRoleManagementException {
    Node rootNode = generateNodeBasedOnNodeType(nodeType, "name");
    when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenThrow(unExpectedErrorThrower(tenantDomain, sError, "Error while listing roles in tenantDomain: "));
    when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString())).thenThrow(unExpectedErrorThrower(tenantDomain, sError, "Error while listing roles in tenantDomain: "));
    SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    assertThrows(CharonException.class, () -> roleManager.listRolesWithPost(getDummySearchRequest(rootNode, 2, 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) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 30 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 testUpdateRoleUpdateUserListOfRoleThrowingErrors.

@Test(dataProvider = "dataProviderForUpdateRoleUpdateUserListOfRoleThrowingErrors", expectedExceptions = { BadRequestException.class, CharonException.class })
public void testUpdateRoleUpdateUserListOfRoleThrowingErrors(String roleId, String oldRoleName, String newRoleName, String tenantDomain, String type, String sError) throws IdentityRoleManagementException, BadRequestException, CharonException, ConflictException, NotFoundException {
    RoleBasicInfo roleBasicInfo = new RoleBasicInfo(roleId, newRoleName);
    Role[] oldAndNewRoles = getOldAndNewRoleDummies(roleId, oldRoleName, newRoleName, type);
    when(mockRoleManagementService.updateRoleName(anyString(), anyString(), anyString())).thenReturn(roleBasicInfo);
    when(mockRoleManagementService.updateUserListOfRole(anyString(), anyListOf(String.class), anyListOf(String.class), anyString())).thenAnswer(invocationOnMock -> {
        String roleIdArg = invocationOnMock.getArgumentAt(0, String.class);
        String tenantDomainArg = invocationOnMock.getArgumentAt(3, String.class);
        if (INVALID_ROLE_IDS.contains(roleIdArg)) {
            String errorMessage = "Invalid scenario. Multiple roles found for the given role name: " + roleIdArg + " and tenantDomain: " + tenantDomain;
            throw new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), errorMessage);
        }
        Throwable unExpectedErrors = unExpectedErrorThrower(tenantDomainArg, sError, "Error while updating users to the role: %s in the tenantDomain: %s", roleIdArg);
        if (unExpectedErrors != null)
            throw unExpectedErrors;
        return roleBasicInfo;
    });
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    scimRoleManager.updateRole(oldAndNewRoles[0], oldAndNewRoles[1]);
}
Also used : Role(org.wso2.charon3.core.objects.Role) Matchers.anyString(org.mockito.Matchers.anyString) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) 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