Search in sources :

Example 11 with DeleteRequest

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

the class PolicyResourceDelegateTest method shouldHandleFailureToDeleteFailedCreationOfPolicies.

@Test(expectedExceptions = ResourceException.class)
public void shouldHandleFailureToDeleteFailedCreationOfPolicies() 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 createException = mock(ResourceException.class);
    ResourceException deleteException = mock(ResourceException.class);
    Promise<ResourceResponse, ResourceException> createPolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
    Promise<ResourceResponse, ResourceException> createPolicyTwoPromise = Promises.newExceptionPromise(createException);
    Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newExceptionPromise(deleteException);
    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");
        assertThat(e).isEqualTo(deleteException);
        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)

Example 12 with DeleteRequest

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

the class PolicyResourceDelegateTest method shouldDeletePolicies.

@Test
public void shouldDeletePolicies() throws ResourceException {
    //Given
    Context context = mock(Context.class);
    List<ResourceResponse> policies = new ArrayList<ResourceResponse>();
    ResourceResponse policyOne = newResourceResponse("ID_1", "REVISION_1", json(object()));
    ResourceResponse policyTwo = newResourceResponse("ID_2", "REVISION_2", json(object()));
    policies.add(policyOne);
    policies.add(policyTwo);
    Set<String> policyIds = new HashSet<String>();
    policyIds.add("ID_1");
    policyIds.add("ID_2");
    Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newResultPromise(policyOne);
    Promise<ResourceResponse, ResourceException> deletePolicyTwoPromise = Promises.newResultPromise(policyTwo);
    given(policyResource.handleDelete(eq(context), Matchers.<DeleteRequest>anyObject())).willReturn(deletePolicyOnePromise).willReturn(deletePolicyTwoPromise);
    //When
    List<ResourceResponse> deletedPolicies = delegate.deletePolicies(context, policyIds).getOrThrowUninterruptibly();
    //Then
    assertThat(deletedPolicies).isEqualTo(policies);
}
Also used : Context(org.forgerock.services.context.Context) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ArrayList(java.util.ArrayList) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 13 with DeleteRequest

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

the class ResourceSetResourceTest method deleteShouldNotBeSupported.

@Test
public void deleteShouldNotBeSupported() {
    //Given
    Context context = mock(Context.class);
    DeleteRequest request = mock(DeleteRequest.class);
    //When
    Promise<ResourceResponse, ResourceException> promise = resource.deleteInstance(context, "RESOURCE_SET_UID", request);
    //Then
    assertThat(promise).failedWithException().isInstanceOf(NotSupportedException.class);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test)

Example 14 with DeleteRequest

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

the class UmaPolicyResourceTest method shouldSuccessfullyDeletePolicy.

@Test
@SuppressWarnings("unchecked")
public void shouldSuccessfullyDeletePolicy() {
    //Given
    Context context = mock(Context.class);
    DeleteRequest request = Requests.newDeleteRequest("/policies");
    Promise<Void, ResourceException> promise = Promises.newResultPromise(null);
    given(policyService.deletePolicy(context, "RESOURCE_SET_UID")).willReturn(promise);
    //When
    Promise<ResourceResponse, ResourceException> result = policyResource.deleteInstance(context, "RESOURCE_SET_UID", request);
    //Then
    assertThat(result).succeeded().withId().isEqualTo("RESOURCE_SET_UID");
    assertThat(result).succeeded().withRevision().isEqualTo("0");
    assertThat(result).succeeded().withContent().isEmpty();
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test)

Example 15 with DeleteRequest

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

the class OathDevicesResourceTest method shouldDeleteTrustedDevice.

/**
     * Tests the OathDeveResources deleteInstance() method.
     * 
     * @throws ResourceException
     * @throws SSOException
     * @throws ExecutionException
     * @throws InterruptedException
     */
@Test
public void shouldDeleteTrustedDevice() throws ResourceException, SSOException, InterruptedException, ExecutionException {
    // GIVEN
    DeleteRequest request = Requests.newDeleteRequest("UUID_2");
    List<JsonValue> devices = new ArrayList<JsonValue>();
    devices.add(json(object(field("uuid", "UUID_1"), field("name", "NAME_1"))));
    devices.add(json(object(field("uuid", "UUID_2"), field("name", "NAME_2"))));
    given(dao.getDeviceProfiles(anyString(), anyString())).willReturn(devices);
    // WHEN
    Promise<ResourceResponse, ResourceException> actual = resource.deleteInstance(ctx(), request.getResourcePath(), request);
    // THEN
    assertThat(actual).succeeded();
    ArgumentCaptor<List> devicesCaptor = ArgumentCaptor.forClass(List.class);
    verify(dao).saveDeviceProfiles(anyString(), anyString(), devicesCaptor.capture());
    assertThat(devicesCaptor.getValue()).hasSize(1);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) ArrayList(java.util.ArrayList) List(java.util.List) DeleteRequest(org.forgerock.json.resource.DeleteRequest) 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