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