use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldPassScriptValidation.
@Test
@SuppressWarnings("unchecked")
public void shouldPassScriptValidation() throws ResourceException {
// given
ActionRequest request = prepareActionRequestForValidate("var a = 123;var b = 456;", "JAVASCRIPT", "validate");
// when
ActionResponse response = scriptResource.actionCollection(context, request).getOrThrowUninterruptibly();
// then
assertThat(response.getJsonContent().get("success").asBoolean()).isEqualTo(true);
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldFailScriptValidationWithOneError.
@Test
@SuppressWarnings("unchecked")
public void shouldFailScriptValidationWithOneError() throws ResourceException {
// given
ActionRequest request = prepareActionRequestForValidate("var a = 123;var b = 456; =VALIDATION SHOULD FAIL=", "JAVASCRIPT", "validate");
// when
ActionResponse response = scriptResource.actionCollection(context, request).getOrThrowUninterruptibly();
// then
assertThat(response.getJsonContent().get("success").asBoolean()).isEqualTo(false);
assertThat(response.getJsonContent().get("errors").get("line")).isNotNull();
assertThat(response.getJsonContent().get("errors").get("column")).isNotNull();
assertThat(response.getJsonContent().get("errors").get("message")).isNotNull();
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class BatchResourceTest method shouldRejectNullScriptId.
@Test
public void shouldRejectNullScriptId() {
//given
Context mockContext = mock(Context.class);
ActionRequest action = newActionRequest("batch", "batch");
action.setContent(JsonValueBuilder.toJsonValue("{ \"notScriptId\" : \"blah\" }"));
@SuppressWarnings("unchecked") ExceptionHandler<ResourceException> handler = mock(ExceptionHandler.class);
//when
Promise<ActionResponse, ResourceException> promise = batchResource.actionCollection(mockContext, action);
promise.thenOnException(handler);
//then
verify(handler, times(1)).handleException(any(ResourceException.class));
verifyNoMoreInteractions(handler);
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class PolicyV1FilterTest method forwardOnAction.
/**
* Verify that action requests are forwarded on.
*/
@Test
public void forwardOnAction() throws Exception {
// Given
ActionRequest actionRequest = mock(ActionRequest.class);
// When
Promise<ActionResponse, ResourceException> promise = filter.filterAction(context, actionRequest, requestHandler);
// Then
assertThat(promise).succeeded();
assertThat(promise.get().getJsonContent().contains("ttl")).isFalse();
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class OathDevicesResourceTest method shouldFailOnUnknownAction.
@Test
public void shouldFailOnUnknownAction() throws ResourceException, SSOException {
// given
ActionRequest request = Requests.newActionRequest("instanceId", "fake");
// when
Promise<ActionResponse, ResourceException> promise = resource.actionCollection(ctx(), request);
// then
assertThat(promise).failedWithResourceException().withCode(ResourceException.NOT_SUPPORTED);
}
Aggregations