use of com.sun.identity.entitlement.Entitlement 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 com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldNotPrintPolicyAttributes.
@Test
public void shouldNotPrintPolicyAttributes() throws Exception {
// Given
Privilege policy = new StubPrivilege();
policy.setEntitlement(new Entitlement());
policy.getEntitlement().setAttributes(Collections.singletonMap("one", CollectionUtils.asSet("two")));
// When
JsonValue result = parser.printPolicy(policy);
// Then
// Attributes should not appear on the policy entitlement
assertThat(result.get("attributes").asMapOfList(String.class)).isNullOrEmpty();
}
use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintPolicyResourceSet.
@Test
public void shouldPrintPolicyResourceSet() throws Exception {
// Given
Privilege policy = new StubPrivilege();
Set<String> included = CollectionUtils.asSet("one", "two", "three");
Entitlement resources = new Entitlement();
resources.setResourceNames(included);
policy.setEntitlement(resources);
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get("resources").asList()).containsOnly(included.toArray());
}
use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintPolicyActionValues.
@Test
public void shouldPrintPolicyActionValues() throws Exception {
// Given
Privilege policy = new StubPrivilege();
policy.setEntitlement(new Entitlement());
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("one", true);
actionValues.put("two", false);
policy.getEntitlement().setActionValues(actionValues);
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get("actionValues").asMap(Boolean.class)).isEqualTo(actionValues);
}
use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldNotPrintPolicyAdvice.
@Test
public void shouldNotPrintPolicyAdvice() throws Exception {
// Given
Privilege policy = new StubPrivilege();
policy.setEntitlement(new Entitlement());
policy.getEntitlement().setAdvices(Collections.singletonMap("one", CollectionUtils.asSet("two")));
// When
JsonValue result = parser.printPolicy(policy);
// Then
// "Advice" should not appear on the policy entitlement
assertThat(result.get("advice").asMapOfList(String.class)).isNullOrEmpty();
}
Aggregations