use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method shouldUpdateResourceTypeName.
@Test
public void shouldUpdateResourceTypeName() throws Exception {
//given
ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
JsonValue v = createdResource.getContent();
v.remove("name");
v.add("name", "modifiedName");
UpdateRequest updateRequest = mock(UpdateRequest.class);
given(updateRequest.getContent()).willReturn(v);
doCallRealMethod().when(resourceTypeService).updateResourceType(any(Subject.class), anyString(), any(ResourceType.class));
//when
Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.updateInstance(mockServerContext, createdResource.getId(), updateRequest);
//then
assertThat(promise).succeeded().withContent().stringAt("name").isEqualTo("modifiedName");
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method updateShouldFailWhenJsonInvalid.
@Test
public void updateShouldFailWhenJsonInvalid() throws Exception {
//given
ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
// modify value created to contain invalid Json resource type
JsonValue modifiedValue = createdResource.getContent();
modifiedValue.remove("name");
modifiedValue.add("x-y", "z");
UpdateRequest updateRequest = mock(UpdateRequest.class);
given(updateRequest.getContent()).willReturn(modifiedValue);
doCallRealMethod().when(resourceTypeService).updateResourceType(any(Subject.class), anyString(), any(ResourceType.class));
//when
Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.updateInstance(mockServerContext, createdResource.getId(), updateRequest);
//then
assertResourcePromiseFailedWithCodes(promise, ResourceException.BAD_REQUEST, EntitlementException.INVALID_CLASS);
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method shouldUpdateResourceTypes.
@Test
public void shouldUpdateResourceTypes() throws Exception {
//given
ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
UpdateRequest updateRequest = mock(UpdateRequest.class);
given(updateRequest.getContent()).willReturn(createdResource.getContent());
doCallRealMethod().when(resourceTypeService).updateResourceType(any(Subject.class), anyString(), any(ResourceType.class));
//when
Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.updateInstance(mockServerContext, createdResource.getId(), updateRequest);
//then
assertThat(promise).succeeded();
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class PrivilegeAuthzModuleTest method crestUpdateIsAllowed.
@Test
public void crestUpdateIsAllowed() 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.updateInstance(isA(Context.class), eq("123"), isA(UpdateRequest.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 UpdateRequest request = Requests.newUpdateRequest("/policies/123", JsonValue.json(new Object()));
Promise<ResourceResponse, ResourceException> result = router.handleUpdate(context, request);
// Then...
assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class AuditFilterTest method shouldAuditFailureForExceptions.
@Test
public void shouldAuditFailureForExceptions() throws Exception {
Promise<ResourceResponse, ResourceException> myPromise = new NotFoundException("message").asPromise();
given(filterChain.handleUpdate(any(Context.class), any(UpdateRequest.class))).willReturn(myPromise);
given(auditorFactory.create(context, updateRequest)).willReturn(auditor);
AuditFilter auditFilter = new AuditFilter(debug, auditorFactory);
auditFilter.filterUpdate(context, updateRequest, filterChain);
verify(auditor).auditAccessFailure(404, "message");
}
Aggregations