use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class SubjectAttributesResourceV1Test method shouldPerformQueryForSubjectAttributes.
@Test
public void shouldPerformQueryForSubjectAttributes() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
Set<String> attributes = new HashSet<>();
attributes.add("attr");
attributes.add("attr2");
given(mockSAM.getAvailableSubjectAttributeNames()).willReturn(attributes);
//when
Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
promise.getOrThrowUninterruptibly();
ArgumentCaptor<ResourceResponse> captor = ArgumentCaptor.forClass(ResourceResponse.class);
verify(mockHandler, times(2)).handleResource(captor.capture());
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class SubjectTypesResourceTest method testSuccessfulJsonificationAndLogicalIsCorrect.
@Test
public void testSuccessfulJsonificationAndLogicalIsCorrect() throws JsonMappingException {
//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);
ReadRequest mockRequest = mock(ReadRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, TEST_LOGICAL_CONDITION, mockRequest);
//then
assertThat(promise).succeeded().withContent().hasBoolean("logical");
assertThat(promise).succeeded().withContent().booleanAt("logical").isTrue();
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class PolicyRequestTest method buildContextStructure.
private Context buildContextStructure(final String realm) {
RealmContext realmContext = new RealmContext(subjectContext);
realmContext.setSubRealm(realm, realm);
return ClientContext.newInternalClientContext(realmContext);
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class SubjectAttributesResourceV1Test method shouldErrorWhenAttributeRetrievalFails.
@Test
public void shouldErrorWhenAttributeRetrievalFails() throws EntitlementException {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
given(mockSAM.getAvailableSubjectAttributeNames()).willThrow(new EntitlementException(401));
//when
Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
verify(mockDebug, times(1)).error(anyString());
assertThat(promise).failedWithResourceException().withCode(ResourceException.INTERNAL_ERROR);
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class SubjectAttributesResourceV1Test method shouldReturnNoResultWhenNoAttributes.
@Test
public void shouldReturnNoResultWhenNoAttributes() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
Set<String> attributes = new HashSet<>();
given(mockSAM.getAvailableSubjectAttributeNames()).willReturn(attributes);
//when
Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
promise.getOrThrowUninterruptibly();
ArgumentCaptor<ResourceResponse> captor = ArgumentCaptor.forClass(ResourceResponse.class);
verify(mockHandler, never()).handleResource(captor.capture());
}
Aggregations