use of org.wso2.charon.core.exceptions.CharonException in project charon by wso2.
the class GroupResourceManagerTest method testDeleteGroupCharonExceptionOnly.
@Test
public void testDeleteGroupCharonExceptionOnly() throws NotFoundException, NotImplementedException, BadRequestException, CharonException, InternalErrorException {
Group group = getNewGroup();
String id = group.getId();
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT)).thenReturn(SCIM2_GROUP_ENDPOINT + "/" + GROUP_ID);
doThrow(new CharonException()).when(userManager).deleteGroup(id);
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(CharonException.class))).thenReturn(getEncodeSCIMExceptionObject(new CharonException()));
SCIMResponse scimResponse = groupResourceManager.delete(id, userManager);
Assert.assertEquals(scimResponse.getResponseStatus(), ResponseCodeConstants.CODE_INTERNAL_ERROR);
}
use of org.wso2.charon.core.exceptions.CharonException in project charon by wso2.
the class GroupResourceManagerTest method testUpdateGroupWithPUTUpdatedGroupResourceIsNull.
@Test(dataProvider = "dataForTestUpdateGroupWithPUTUpdatedGroupResourceIsNull")
public void testUpdateGroupWithPUTUpdatedGroupResourceIsNull(String id, String scimObjectString, String attributes, String excludeAttributes, Object scimOldGroupObject) throws NotImplementedException, BadRequestException, NotFoundException, CharonException {
Group groupOld = (Group) scimOldGroupObject;
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT)).thenReturn(SCIM2_GROUP_ENDPOINT + "/" + GROUP_ID);
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(InternalErrorException.class))).thenReturn(getEncodeSCIMExceptionObject(new InternalErrorException()));
Mockito.when(userManager.getGroup(id, ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(groupOld);
Mockito.when(userManager.updateGroup(any(Group.class), any(Group.class), anyMap())).thenReturn(null);
SCIMResponse scimResponse = groupResourceManager.updateWithPUT(id, scimObjectString, userManager, attributes, excludeAttributes);
Assert.assertEquals(scimResponse.getResponseStatus(), ResponseCodeConstants.CODE_INTERNAL_ERROR);
}
use of org.wso2.charon.core.exceptions.CharonException in project charon by wso2.
the class GroupResourceManagerTest method testDeleteGroupFails.
@Test(dataProvider = "dataForTestDeleteGroupFails")
public void testDeleteGroupFails(String id, int expectedScimResponseStatus) throws NotFoundException, NotImplementedException, BadRequestException, CharonException {
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT)).thenReturn(SCIM2_GROUP_ENDPOINT + "/" + GROUP_ID);
if (expectedScimResponseStatus == ResponseCodeConstants.CODE_INTERNAL_ERROR) {
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(InternalErrorException.class))).thenReturn(getEncodeSCIMExceptionObject(new InternalErrorException()));
SCIMResponse scimResponse = groupResourceManager.delete(id, null);
Assert.assertEquals(scimResponse.getResponseStatus(), expectedScimResponseStatus);
} else {
doThrow(new NotFoundException()).when(userManager).deleteGroup(id);
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(NotFoundException.class))).thenReturn(getEncodeSCIMExceptionObject(new NotFoundException()));
SCIMResponse scimResponse = groupResourceManager.delete(id, userManager);
Assert.assertEquals(scimResponse.getResponseStatus(), expectedScimResponseStatus);
}
}
use of org.wso2.charon.core.exceptions.CharonException in project charon by wso2.
the class GroupResourceManagerTest method testCreateGroupCharonException.
@Test(dataProvider = "dataForTestCreateGroupCharonException")
public void testCreateGroupCharonException(String scimObjectString, String attributes, String excludeAttributes) throws ConflictException, NotImplementedException, BadRequestException, CharonException {
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT)).thenReturn(SCIM2_GROUP_ENDPOINT);
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(CharonException.class))).thenReturn(getEncodeSCIMExceptionObject(new CharonException()));
Mockito.when(userManager.createGroup(any(Group.class), anyMap())).thenThrow(CharonException.class);
SCIMResponse scimResponse = groupResourceManager.create(scimObjectString, userManager, attributes, excludeAttributes);
Assert.assertEquals(scimResponse.getResponseStatus(), ResponseCodeConstants.CODE_INTERNAL_ERROR);
}
use of org.wso2.charon.core.exceptions.CharonException in project charon by wso2.
the class GroupResourceManagerTest method testGetUserCharonException.
@Test(dataProvider = "dataForGetGroupExceptions")
public void testGetUserCharonException(String id, String attributes, String excludeAttributes) throws CharonException, NotImplementedException, BadRequestException, NotFoundException {
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT)).thenReturn(SCIM2_GROUP_ENDPOINT);
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(CharonException.class))).thenReturn(getEncodeSCIMExceptionObject(new CharonException()));
Mockito.when(userManager.getGroup(id, requiredAttributes)).thenThrow(CharonException.class);
SCIMResponse scimResponse = groupResourceManager.get(id, userManager, attributes, excludeAttributes);
Assert.assertEquals(scimResponse.getResponseStatus(), ResponseCodeConstants.CODE_INTERNAL_ERROR);
}
Aggregations