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)));
}
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));
}
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));
}
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");
}
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));
}
Aggregations