use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class PrivilegePolicyStoreProviderTest method shouldUseRealmAndSubjectFromContext.
@Test
public void shouldUseRealmAndSubjectFromContext() {
// Given
SubjectContext subjectContext = mock(SubjectContext.class);
Subject subject = new Subject();
String realm = "/test realm";
given(subjectContext.getCallerSubject()).willReturn(subject);
RealmContext context = new RealmContext(subjectContext);
context.setSubRealm(realm, realm);
PrivilegeManager manager = mock(PrivilegeManager.class);
given(mockFactory.get(realm, subject)).willReturn(manager);
// When
PolicyStore store = testProvider.getPolicyStore(context);
// Then
verify(mockFactory).get(realm, subject);
assertThat(store).isNotNull().isInstanceOf(PrivilegePolicyStore.class);
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method shouldThrowErrorWthInvalidCondition.
@Test(expectedExceptions = NotFoundException.class)
public void shouldThrowErrorWthInvalidCondition() throws JsonMappingException, ResourceException {
//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, "invalidCondition", mockRequest);
//then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class DecisionCombinersResourceTest method testSuccessfulJsonificationAndQuery.
@Test
public void testSuccessfulJsonificationAndQuery() throws JsonMappingException {
//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);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
verify(mockHandler, times(1)).handleResource(any(ResourceResponse.class));
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class DecisionCombinersResourceTest method testSuccessfulJsonificationAndReadAndNamePropertyRemoved.
@Test
public void testSuccessfulJsonificationAndReadAndNamePropertyRemoved() throws JsonMappingException, ResourceException {
//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_COMBINER, mockRequest);
//then
Map resultMap = result.getOrThrowUninterruptibly().getContent().asMap();
assertThat(resultMap.containsKey("title")).isTrue();
assertThat(resultMap.get("title")).isEqualTo(TEST_COMBINER);
}
use of org.forgerock.openam.rest.resource.SubjectContext in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method testSuccessfulJsonificationAndQuery.
@Test
public void testSuccessfulJsonificationAndQuery() throws JsonMappingException {
//given
SubjectContext mockSubjectContext = mock(SubjectContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockRequest.getPageSize()).willReturn(2);
given(mockHandler.handleResource(any(ResourceResponse.class))).willReturn(true);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
verify(mockHandler, times(2)).handleResource(any(ResourceResponse.class));
}
Aggregations