Search in sources :

Example 26 with DeleteRequest

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

the class AuditFilterTest method shouldReturnNullForDeleteSuccess.

@Test
public void shouldReturnNullForDeleteSuccess() {
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    JsonValue filterResponse = auditFilter.getDeleteSuccessDetail(deleteRequest, resourceResponse);
    assertThat(filterResponse).isEqualTo(null);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test)

Example 27 with DeleteRequest

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

the class ScriptResourceTest method shouldDeleteScriptConfigurationWithoutError.

@Test
public void shouldDeleteScriptConfigurationWithoutError() throws Exception {
    // given
    String resourceId = "1234567890";
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    // when
    ResourceResponse response = scriptResource.deleteInstance(context, resourceId, deleteRequest).getOrThrowUninterruptibly();
    // then
    assertNotNull(response);
    assertEquals(response.getId(), resourceId);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) Matchers.anyString(org.mockito.Matchers.anyString) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test)

Example 28 with DeleteRequest

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

the class UmaPolicyApplicationListener method deletePolicies.

private void deletePolicies(String realm, String resourceServerId) {
    RealmContext realmContext = new RealmContext(new RootContext());
    realmContext.setDnsAlias("/", realm);
    final Context context = new AdminSubjectContext(logger, sessionCache, realmContext);
    QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.equalTo(new JsonPointer("applicationName"), resourceServerId));
    final List<ResourceResponse> resources = new ArrayList<>();
    policyResource.handleQuery(context, request, new QueryResourceHandler() {

        @Override
        public boolean handleResource(ResourceResponse resource) {
            resources.add(resource);
            return true;
        }
    }).thenAsync(new AsyncFunction<QueryResponse, List<ResourceResponse>, ResourceException>() {

        @Override
        public Promise<List<ResourceResponse>, ResourceException> apply(QueryResponse response) {
            List<Promise<ResourceResponse, ResourceException>> promises = new ArrayList<>();
            for (ResourceResponse policy : resources) {
                DeleteRequest deleteRequest = Requests.newDeleteRequest("", policy.getId());
                promises.add(policyResource.handleDelete(context, deleteRequest));
            }
            Promise<List<ResourceResponse>, ResourceException> when = Promises.when(promises);
            return when;
        }
    }).thenOnException(new ExceptionHandler<ResourceException>() {

        @Override
        public void handleException(ResourceException error) {
            logger.error(error.getReason());
        }
    });
}
Also used : RootContext(org.forgerock.services.context.RootContext) RealmContext(org.forgerock.openam.rest.RealmContext) AdminSubjectContext(org.forgerock.openam.rest.resource.AdminSubjectContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) QueryRequest(org.forgerock.json.resource.QueryRequest) AdminSubjectContext(org.forgerock.openam.rest.resource.AdminSubjectContext) ArrayList(java.util.ArrayList) JsonPointer(org.forgerock.json.JsonPointer) AsyncFunction(org.forgerock.util.AsyncFunction) RootContext(org.forgerock.services.context.RootContext) Promise(org.forgerock.util.promise.Promise) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) List(java.util.List) ArrayList(java.util.ArrayList) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) DenyOverride(com.sun.identity.entitlement.DenyOverride) DeleteRequest(org.forgerock.json.resource.DeleteRequest)

Example 29 with DeleteRequest

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

the class PolicyResourceDelegateTest method shouldHandleFailureToDeletePolicies.

@Test(expectedExceptions = ResourceException.class)
public void shouldHandleFailureToDeletePolicies() throws ResourceException {
    //Given
    Context context = mock(Context.class);
    ResourceResponse policyOne = newResourceResponse("ID_1", "REVISION_1", json(object()));
    Set<String> policyIds = new HashSet<String>();
    policyIds.add("ID_1");
    policyIds.add("ID_2");
    ResourceException exception = mock(ResourceException.class);
    Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newResultPromise(policyOne);
    Promise<ResourceResponse, ResourceException> deletePolicyTwoPromise = Promises.newExceptionPromise(exception);
    given(policyResource.handleDelete(eq(context), Matchers.<DeleteRequest>anyObject())).willReturn(deletePolicyOnePromise).willReturn(deletePolicyTwoPromise);
    //When
    delegate.deletePolicies(context, policyIds).getOrThrowUninterruptibly();
//Then
//Expected ResourceException
}
Also used : Context(org.forgerock.services.context.Context) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) 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)

Example 30 with DeleteRequest

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

the class PolicyResourceDelegateTest method shouldHandleFailureToCreatePoliciesByDeletingCreatedPolicies.

@Test(expectedExceptions = ResourceException.class)
public void shouldHandleFailureToCreatePoliciesByDeletingCreatedPolicies() throws ResourceException {
    //Given
    //Given
    Context context = mock(Context.class);
    Set<JsonValue> policies = new HashSet<JsonValue>();
    JsonValue policyOne = json(object(field("name", "POLICY_ONE")));
    JsonValue policyTwo = json(object(field("name", "POLICY_TWO")));
    policies.add(policyOne);
    policies.add(policyTwo);
    ResourceResponse createdPolicyOne = newResourceResponse("ID_1", "REVISION_1", json(object()));
    ResourceException exception = mock(ResourceException.class);
    Promise<ResourceResponse, ResourceException> createPolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
    Promise<ResourceResponse, ResourceException> createPolicyTwoPromise = Promises.newExceptionPromise(exception);
    Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
    given(policyResource.handleCreate(eq(context), Matchers.<CreateRequest>anyObject())).willReturn(createPolicyOnePromise).willReturn(createPolicyTwoPromise);
    given(policyResource.handleDelete(eq(context), Matchers.<DeleteRequest>anyObject())).willReturn(deletePolicyOnePromise);
    //When
    try {
        delegate.createPolicies(context, policies).getOrThrowUninterruptibly();
    } catch (ResourceException e) {
        //Then
        ArgumentCaptor<DeleteRequest> requestCaptor = ArgumentCaptor.forClass(DeleteRequest.class);
        verify(policyResource).handleDelete(eq(context), requestCaptor.capture());
        assertThat(requestCaptor.getValue().getResourcePathObject().leaf()).isEqualTo("ID_1");
        throw e;
    }
}
Also used : Context(org.forgerock.services.context.Context) ArgumentCaptor(org.mockito.ArgumentCaptor) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) 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