use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class TreePolicyRequestTest method shouldRejectEmptyResources.
@Test(expectedExceptions = EntitlementException.class)
public void shouldRejectEmptyResources() throws EntitlementException {
// Given...
Map<String, Object> properties = new HashMap<String, Object>();
given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
given(subjectContext.getCallerSubject()).willReturn(restSubject);
// When...
Context context = buildContextStructure("/abc");
TreePolicyRequest.getTreePolicyRequest(context, actionRequest, tokenManager);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SubjectTypesResourceTest method testSuccessfulJsonificationAndQuery.
@Test
public void testSuccessfulJsonificationAndQuery() throws Exception {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
given(mockRequest.getPageSize()).willReturn(2);
given(mockHandler.handleResource(any(ResourceResponse.class))).willReturn(true);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<QueryResponse, ResourceException> promise = testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
assertThat(promise).succeeded();
verify(mockHandler, times(2)).handleResource(any(ResourceResponse.class));
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class BatchPolicyRequestTest method shouldRejectNullResources.
@Test(expectedExceptions = EntitlementException.class)
public void shouldRejectNullResources() throws EntitlementException {
// When...
Map<String, Object> properties = new HashMap<String, Object>();
given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
given(subjectContext.getCallerSubject()).willReturn(restSubject);
// Given...
Context context = buildContextStructure("/abc");
BatchPolicyRequest.getBatchPolicyRequest(context, actionRequest, tokenManager);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PolicyRequestTest method shouldRejectInvalidRestSubject.
@Test(expectedExceptions = EntitlementException.class)
public void shouldRejectInvalidRestSubject() throws EntitlementException {
// Given...
given(subjectContext.getCallerSubject()).willReturn(null);
// When...
Context context = buildContextStructure("/abc");
getRequest(context, actionRequest);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PolicyRequestTest method shouldAllowJsonSubject.
@Test
public void shouldAllowJsonSubject() throws Exception {
// Given
final String subjectName = "test";
given(subjectContext.getCallerSubject()).willReturn(restSubject);
final JsonValue jwt = getJsonSubject(subjectName);
given(actionRequest.getContent()).willReturn(json(object(field("subject", object(field("claims", jwt.asMap()))))));
// When
Context context = buildContextStructure("/abc");
PolicyRequest request = getRequest(context, actionRequest);
// Then
Subject policySubject = request.getPolicySubject();
Set<JwtPrincipal> jwtPrincipals = policySubject.getPrincipals(JwtPrincipal.class);
assertThat(jwtPrincipals).hasSize(1);
assertThat(jwtPrincipals).contains(new JwtPrincipal(jwt));
}
Aggregations