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