Search in sources :

Example 21 with DeleteRequest

use of org.forgerock.json.resource.DeleteRequest in project OpenAM by OpenRock.

the class ResourceTypesResourceTest method shouldDeleteResourceTypes.

@Test
public void shouldDeleteResourceTypes() throws Exception {
    //Given
    ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
    DeleteRequest mockDeleteRequest = mock(DeleteRequest.class);
    doCallRealMethod().when(resourceTypeService).deleteResourceType(any(Subject.class), anyString(), anyString());
    //when
    Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.deleteInstance(mockServerContext, createdResource.getId(), mockDeleteRequest);
    //then
    assertThat(promise).succeeded().withId().isEqualTo(createdResource.getId());
    assertThat(promise).succeeded().withContent().isObject().containsOnly();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 22 with DeleteRequest

use of org.forgerock.json.resource.DeleteRequest in project OpenAM by OpenRock.

the class ResourceTypesResourceTest method deleteShouldHandleServiceException.

@Test
public void deleteShouldHandleServiceException() throws Exception {
    //Given
    ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    Throwable t = new EntitlementException(EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS);
    doThrow(t).when(resourceTypeService).deleteResourceType(any(Subject.class), anyString(), anyString());
    //when
    Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.deleteInstance(mockServerContext, createdResource.getId(), deleteRequest);
    //then
    assertResourcePromiseFailedWithCodes(promise, ResourceException.CONFLICT, EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 23 with DeleteRequest

use of org.forgerock.json.resource.DeleteRequest in project OpenAM by OpenRock.

the class ClientResourceTest method shouldDeleteIdentity.

@Test
public void shouldDeleteIdentity() throws SSOException, IdRepoException, ResourceException {
    //Given
    String resourceId = "client";
    DeleteRequest request = mock(DeleteRequest.class);
    //setup mockManager
    Map<String, String> responseVal = new HashMap<>();
    responseVal.put("success", "true");
    JsonValue response = new JsonValue(responseVal);
    ResourceResponse expectedResource = newResourceResponse("results", "1", response);
    // When
    Promise<ResourceResponse, ResourceException> deletePromise = resource.deleteInstance(null, resourceId, request);
    // Then
    assertThat(deletePromise).succeeded().withObject().isEqualTo(expectedResource);
}
Also used : Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Mockito.anyString(org.mockito.Mockito.anyString) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 24 with DeleteRequest

use of org.forgerock.json.resource.DeleteRequest in project OpenAM by OpenRock.

the class RealmContextFilter method filterDelete.

@Override
public Promise<ResourceResponse, ResourceException> filterDelete(Context context, DeleteRequest request, RequestHandler next) {
    try {
        Context newContext = evaluate(context, request);
        DeleteRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfDeleteRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
        return next.handleDelete(evaluate(context, request), evaluatedRequest);
    } catch (ResourceException e) {
        return newExceptionPromise(e);
    }
}
Also used : UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) HttpContext(org.forgerock.json.resource.http.HttpContext) UriRouterContext(org.forgerock.http.routing.UriRouterContext) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest)

Example 25 with DeleteRequest

use of org.forgerock.json.resource.DeleteRequest in project OpenAM by OpenRock.

the class PrivilegeAuthzModuleTest method crestDeleteIsAllowed.

@Test
public void crestDeleteIsAllowed() throws SSOException, DelegationException {
    // Given...
    final Set<String> actions = new HashSet<>(Arrays.asList("MODIFY"));
    final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS, DUMB_FUNC);
    given(factory.newInstance("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS)).willReturn(permission);
    given(subjectContext.getCallerSSOToken()).willReturn(token);
    given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(true);
    JsonValue jsonValue = json(object(field("someKey", "someValue")));
    Promise<ResourceResponse, ResourceException> promise = Promises.newResultPromise(Responses.newResourceResponse("1", "1.0", jsonValue));
    given(provider.deleteInstance(isA(Context.class), eq("123"), isA(DeleteRequest.class))).willReturn(promise);
    // When...
    final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
    final Router router = new Router();
    router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
    final RealmContext context = new RealmContext(subjectContext);
    context.setSubRealm("abc", "abc");
    final DeleteRequest request = Requests.newDeleteRequest("/policies/123");
    Promise<ResourceResponse, ResourceException> result = router.handleDelete(context, request);
    // Then...
    assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) FilterChain(org.forgerock.json.resource.FilterChain) JsonValue(org.forgerock.json.JsonValue) Router(org.forgerock.json.resource.Router) Matchers.anyString(org.mockito.Matchers.anyString) DelegationPermission(com.sun.identity.delegation.DelegationPermission) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

DeleteRequest (org.forgerock.json.resource.DeleteRequest)32 Test (org.testng.annotations.Test)27 ResourceResponse (org.forgerock.json.resource.ResourceResponse)24 ResourceException (org.forgerock.json.resource.ResourceException)23 Context (org.forgerock.services.context.Context)15 JsonValue (org.forgerock.json.JsonValue)9 RealmContext (org.forgerock.openam.rest.RealmContext)7 ArrayList (java.util.ArrayList)6 Subject (javax.security.auth.Subject)6 Matchers.anyString (org.mockito.Matchers.anyString)6 HashSet (java.util.HashSet)5 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)5 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)4 ClientContext (org.forgerock.services.context.ClientContext)4 EntitlementException (com.sun.identity.entitlement.EntitlementException)3 List (java.util.List)3 CreateRequest (org.forgerock.json.resource.CreateRequest)3 Connection (org.forgerock.json.resource.Connection)2 QueryRequest (org.forgerock.json.resource.QueryRequest)2 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)2