use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldHandleUnknownAction.
@Test
public void shouldHandleUnknownAction() {
// Given...
given(request.getAction()).willReturn("unknownAction");
// When...
Context context = buildContextStructure("/abc");
policyResource.actionCollection(context, request);
// Then...
verify(request).getAction();
//verify(jsonHandler).handleError(isA(NotSupportedException.class));
verifyNoMoreInteractions(request, subjectContext, requestFactory, policyRequest, factory, evaluator, parser);
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class PolicyRequestFactoryTest method shouldRetrieveBatchRequest.
@Test
public void shouldRetrieveBatchRequest() throws EntitlementException {
// When...
given(subjectContext.getCallerSubject()).willReturn(restSubject);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("resources", Arrays.asList("/resource/a", "/resource/b"));
given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
// Given...
Context context = buildContextStructure("/abc");
PolicyRequest request = factory.buildRequest(PolicyAction.EVALUATE, context, actionRequest);
// Then...
assertThat(request).isNotNull();
assertThat(request.getRealm()).isEqualTo("/abc");
assertThat(request).isInstanceOfAny(BatchPolicyRequest.class);
BatchPolicyRequest batchRequest = (BatchPolicyRequest) request;
assertThat(batchRequest.getResources()).containsOnly("/resource/a", "/resource/b");
verify(subjectContext).getCallerSubject();
verify(actionRequest, times(2)).getContent();
verifyNoMoreInteractions(subjectContext, actionRequest);
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class PolicyRequestTest method shouldDefaultToApplication.
@Test
public void shouldDefaultToApplication() throws EntitlementException {
// Given...
given(subjectContext.getCallerSubject()).willReturn(restSubject);
Map<String, Object> properties = new HashMap<String, Object>();
given(actionRequest.getContent()).willReturn(json(properties));
// When...
Context context = buildContextStructure("/abc");
PolicyRequest request = getRequest(context, actionRequest);
// Then...
assertThat(request).isNotNull();
assertThat(request.getApplication()).isEqualTo("iPlanetAMWebAgentService");
verify(subjectContext).getCallerSubject();
verify(actionRequest).getContent();
verifyNoMoreInteractions(subjectContext, actionRequest);
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method testSuccessfulJsonificationAndReadAndNamePropertyRemoved.
@Test
public void testSuccessfulJsonificationAndReadAndNamePropertyRemoved() throws JsonMappingException, ExecutionException, InterruptedException {
//given
SubjectContext mockSubjectContext = mock(SubjectContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
ReadRequest mockRequest = mock(ReadRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, TEST_CONDITION_WITH_NAME, mockRequest);
//then
Map resultMap = result.get().getContent().asMap();
assertThat(resultMap.containsKey("title")).isTrue();
assertThat(resultMap.containsKey("config")).isTrue();
assertThat(resultMap.containsKey("logical")).isTrue();
assertThat(resultMap.get("title")).isEqualTo(TEST_CONDITION_WITH_NAME);
assertThat(resultMap.get("logical")).isEqualTo(false);
assertThat(resultMap.get("config")).isInstanceOf(JsonSchema.class);
JsonSchema resultSchema = (JsonSchema) resultMap.get("config");
assertThat(resultSchema.toString().equals("{\"type\":\"object\",\"properties\":{}}")).isTrue();
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method testSuccessfulJsonificationAndLogicalIsCorrect.
@Test
public void testSuccessfulJsonificationAndLogicalIsCorrect() throws JsonMappingException, ExecutionException, InterruptedException {
//given
SubjectContext mockSubjectContext = mock(SubjectContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
ReadRequest mockRequest = mock(ReadRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, TEST_LOGICAL_CONDITION, mockRequest);
//then
Map resultMap = result.get().getContent().asMap();
assertThat(resultMap.containsKey("logical")).isTrue();
assertThat(resultMap.get("logical")).isEqualTo(true);
}
Aggregations