use of org.forgerock.json.resource.ActionResponse 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.ActionResponse 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.ActionResponse 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.ActionResponse in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldMakeTreeEvaluation.
@Test
public void shouldMakeTreeEvaluation() throws EntitlementException {
// Given...
given(request.getAction()).willReturn("evaluateTree");
Context context = buildContextStructure("/abc");
given(requestFactory.buildRequest(PolicyAction.TREE_EVALUATE, context, request)).willReturn(policyRequest);
given(policyRequest.getRestSubject()).willReturn(restSubject);
given(policyRequest.getApplication()).willReturn("some-application");
given(factory.getEvaluator(restSubject, "some-application")).willReturn(evaluator);
given(policyRequest.getApplication()).willReturn("some-application");
given(policyRequest.getRealm()).willReturn("/abc");
List<Entitlement> decisions = Arrays.asList(new Entitlement());
given(evaluator.routePolicyRequest(policyRequest)).willReturn(decisions);
JsonValue jsonDecision = JsonValue.json(array());
given(parser.printEntitlements(decisions)).willReturn(jsonDecision);
// When...
Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
// Then...
verify(request).getAction();
verify(requestFactory).buildRequest(PolicyAction.TREE_EVALUATE, context, request);
verify(policyRequest).getRestSubject();
verify(policyRequest, times(2)).getApplication();
verify(policyRequest).getRealm();
verify(factory).getEvaluator(restSubject, "some-application");
verify(evaluator).routePolicyRequest(policyRequest);
verify(parser).printEntitlements(decisions);
assertThat(promise).succeeded().withContent().isEqualTo(jsonDecision);
verifyNoMoreInteractions(request, subjectContext, requestFactory, policyRequest, factory, evaluator, parser);
}
use of org.forgerock.json.resource.ActionResponse 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();
}
Aggregations