Search in sources :

Example 96 with CharonException

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);
}
Also used : Group(org.wso2.charon3.core.objects.Group) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CharonException(org.wso2.charon3.core.exceptions.CharonException) AbstractCharonException(org.wso2.charon3.core.exceptions.AbstractCharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Example 97 with CharonException

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);
}
Also used : Group(org.wso2.charon3.core.objects.Group) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Example 98 with CharonException

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);
    }
}
Also used : NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Example 99 with CharonException

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);
}
Also used : Group(org.wso2.charon3.core.objects.Group) CharonException(org.wso2.charon3.core.exceptions.CharonException) AbstractCharonException(org.wso2.charon3.core.exceptions.AbstractCharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Example 100 with CharonException

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);
}
Also used : SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CharonException(org.wso2.charon3.core.exceptions.CharonException) AbstractCharonException(org.wso2.charon3.core.exceptions.AbstractCharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Aggregations

CharonException (org.wso2.charon3.core.exceptions.CharonException)153 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)137 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)120 User (org.wso2.charon3.core.objects.User)114 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)109 Test (org.testng.annotations.Test)106 JSONObject (org.json.JSONObject)88 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)80 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)73 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)63 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)59 HashMap (java.util.HashMap)55 Group (org.wso2.charon3.core.objects.Group)55 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)52 DataProvider (org.testng.annotations.DataProvider)51 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)49 Attribute (org.wso2.charon3.core.attributes.Attribute)46 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)46 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)42 ArrayList (java.util.ArrayList)37