Search in sources :

Example 96 with Group

use of org.wso2.charon.core.objects.Group in project charon by wso2.

the class GroupResourceManagerTest method getNewGroup.

private Group getNewGroup() throws BadRequestException, CharonException, InternalErrorException {
    SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
    JSONDecoder decoder = new JSONDecoder();
    return decoder.decodeResource(NEW_GROUP_SCIM_OBJECT_STRING, schema, new Group());
}
Also used : JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) Group(org.wso2.charon3.core.objects.Group) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema)

Example 97 with Group

use of org.wso2.charon.core.objects.Group in project charon by wso2.

the class GroupResourceManagerTest method dataToTestDeleteGroupFails.

@DataProvider(name = "dataForTestDeleteGroupFails")
public Object[][] dataToTestDeleteGroupFails() throws BadRequestException, CharonException, InternalErrorException {
    Group group = getNewGroup();
    String id = group.getId();
    return new Object[][] { { id, ResponseCodeConstants.CODE_INTERNAL_ERROR }, { id, ResponseCodeConstants.CODE_RESOURCE_NOT_FOUND } };
}
Also used : Group(org.wso2.charon3.core.objects.Group) JSONObject(org.json.JSONObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataProvider(org.testng.annotations.DataProvider)

Example 98 with Group

use of org.wso2.charon.core.objects.Group in project charon by wso2.

the class GroupResourceManagerTest method testUpdateGroupWithPUTProvidedUserManagerHandlerIsNull.

@Test(dataProvider = "dataForTestUpdateGroupWithPUTProvidedUserManagerHandlerIsNull")
public void testUpdateGroupWithPUTProvidedUserManagerHandlerIsNull(String id, String scimObjectString, String attributes, String excludeAttributes, Object scimNewGroupObject, Object scimOldGroupObject) throws BadRequestException, CharonException, NotImplementedException, NotFoundException {
    Group groupNew = (Group) scimNewGroupObject;
    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);
    Group validatedGroup = (Group) ServerSideValidator.validateUpdatedSCIMObject(groupOld, groupNew, schema);
    Mockito.when(userManager.updateGroup(any(Group.class), any(Group.class), anyMap())).thenReturn(validatedGroup);
    SCIMResponse scimResponse = groupResourceManager.updateWithPUT(id, scimObjectString, null, 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 99 with Group

use of org.wso2.charon.core.objects.Group in project charon by wso2.

the class GroupResourceManagerTest method testUpdateGroupWithPUTNoUserExistsWithTheGivenUserName.

@Test(dataProvider = "dataForTestUpdateGroupWithPUTNotFoundException")
public void testUpdateGroupWithPUTNoUserExistsWithTheGivenUserName(String id, String scimObjectString, String attributes, String excludeAttributes, Object scimNewGroupObject, Object scimOldGroupObject) throws BadRequestException, CharonException, NotImplementedException, NotFoundException {
    Group groupNew = (Group) scimNewGroupObject;
    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(NotFoundException.class))).thenReturn(getEncodeSCIMExceptionObject(new NotFoundException()));
    Mockito.when(userManager.getGroup(id, ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(null);
    Group validatedGroup = (Group) ServerSideValidator.validateUpdatedSCIMObject(groupOld, groupNew, schema);
    Mockito.when(userManager.updateGroup(any(Group.class), any(Group.class), anyMap())).thenReturn(validatedGroup);
    SCIMResponse scimResponse = groupResourceManager.updateWithPUT(id, scimObjectString, userManager, attributes, excludeAttributes);
    Assert.assertEquals(scimResponse.getResponseStatus(), ResponseCodeConstants.CODE_RESOURCE_NOT_FOUND);
}
Also used : Group(org.wso2.charon3.core.objects.Group) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Example 100 with Group

use of org.wso2.charon.core.objects.Group in project charon by wso2.

the class GroupResourceManagerTest method dataToTestUpdateGroupWithPUTSuccess.

@DataProvider(name = "dataForTestUpdateGroupWithPUTSuccess")
public Object[][] dataToTestUpdateGroupWithPUTSuccess() throws BadRequestException, CharonException, InternalErrorException {
    SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
    JSONDecoder decoder = new JSONDecoder();
    Group groupOld = decoder.decodeResource(NEW_GROUP_SCIM_OBJECT_STRING, schema, new Group());
    String id = groupOld.getId();
    Group groupNew = decoder.decodeResource(NEW_GROUP_SCIM_OBJECT_STRING_UPDATED, schema, new Group());
    return new Object[][] { { id, NEW_GROUP_SCIM_OBJECT_STRING_UPDATED, "id", null, groupNew, groupOld } };
}
Also used : JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) Group(org.wso2.charon3.core.objects.Group) JSONObject(org.json.JSONObject) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataProvider(org.testng.annotations.DataProvider)

Aggregations

Test (org.testng.annotations.Test)155 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)99 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)94 Event (org.wso2.siddhi.core.event.Event)89 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)80 Group (org.wso2.charon3.core.objects.Group)57 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)53 CharonException (org.wso2.charon3.core.exceptions.CharonException)43 HashMap (java.util.HashMap)38 Connection (java.sql.Connection)34 SQLException (java.sql.SQLException)34 ArrayList (java.util.ArrayList)34 IdentitySCIMException (org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)34 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)33 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)32 PreparedStatement (java.sql.PreparedStatement)29 ResultSet (java.sql.ResultSet)29 Operation (io.swagger.v3.oas.annotations.Operation)27 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)27 Response (javax.ws.rs.core.Response)27