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;
}
}
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);
}
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);
}
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();
}
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);
}
Aggregations