use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class Requester method update.
/**
* Request to update a specified resource at a specified endpoint.
*
* @param location Endpoint destination of this request. May not be null.
* @param resourceId Resource ID to update. May not be null.
* @param payload Payload of the updated resource. May not be null.
* @param context Context of this request.
* @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
* @throws ResourceException If any exception occurred during processing.
*/
public JsonValue update(String location, String resourceId, JsonValue payload, Context context) throws ResourceException {
Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
Reject.ifTrue(StringUtils.isEmpty(resourceId), "The resourceId to update may not be null or empty.");
Reject.ifNull(payload, "The payload object to create must not be null.");
final Router rootRouter = router.get();
final UpdateRequest updateRequest = Requests.newUpdateRequest(location, resourceId, payload);
return rootRouter.handleUpdate(context, updateRequest).getOrThrowUninterruptibly().getContent();
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldFailIfNoScriptIsSuppliedOnUpdate.
@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoScriptIsSuppliedOnUpdate() throws ResourceException {
// given
String resourceId = "1234567890";
JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_LANGUAGE, "JAVASCRIPT"), field(SCRIPT_CONTEXT, "POLICY_CONDITION")));
UpdateRequest updateRequest = mock(UpdateRequest.class);
when(updateRequest.getContent()).thenReturn(requestJson);
// when
scriptResource.updateInstance(context, resourceId, updateRequest).getOrThrowUninterruptibly();
// then - exception
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldFailIfNoContextIsSuppliedOnUpdate.
@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoContextIsSuppliedOnUpdate() throws ResourceException {
// given
String resourceId = "1234567890";
JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_TEXT, "var a = 123;var b = 456;"), field(SCRIPT_LANGUAGE, "JAVASCRIPT")));
UpdateRequest updateRequest = mock(UpdateRequest.class);
when(updateRequest.getContent()).thenReturn(requestJson);
// when
scriptResource.updateInstance(context, resourceId, updateRequest).getOrThrowUninterruptibly();
// then - exception
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldFailIfNoNameIsSuppliedOnUpdate.
@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoNameIsSuppliedOnUpdate() throws ResourceException {
// given
String resourceId = "1234567890";
JsonValue requestJson = json(object(field(SCRIPT_TEXT, encodeScript), field(SCRIPT_LANGUAGE, "JAVASCRIPT"), field(SCRIPT_CONTEXT, "POLICY_CONDITION")));
UpdateRequest updateRequest = mock(UpdateRequest.class);
when(updateRequest.getContent()).thenReturn(requestJson);
// when
scriptResource.updateInstance(context, resourceId, updateRequest).getOrThrowUninterruptibly();
// then - exception
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldUpdatePoliciesInStore.
@Test
public void shouldUpdatePoliciesInStore() throws Exception {
// Given
String id = "testPolicy";
long lastModified = 1234l;
UpdateRequest request = mock(UpdateRequest.class);
JsonValue content = new JsonValue("content");
given(request.getContent()).willReturn(content);
Privilege privilege = mockPrivilege(id, lastModified);
given(mockParser.parsePolicy(id, content)).willReturn(privilege);
given(mockStore.update(id, privilege)).willReturn(privilege);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.updateInstance(mockServerContext, id, request);
// Then
assertThat(promise).succeeded().withId().isNotNull();
}
Aggregations