use of org.forgerock.openam.rest.RealmContext 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.RealmContext 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.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldReturnNotFoundDeleteInstance.
@Test(expectedExceptions = NotFoundException.class)
public void shouldReturnNotFoundDeleteInstance() throws EntitlementException, ResourceException {
//Given
SSOTokenContext subjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(subjectContext);
realmContext.setSubRealm("REALM", "REALM");
Context context = ClientContext.newInternalClientContext(realmContext);
String resourceId = "RESOURCE_ID";
DeleteRequest request = mock(DeleteRequest.class);
Subject subject = new Subject();
given(subjectContext.getCallerSubject()).willReturn(subject);
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.deleteInstance(context, resourceId, request);
//Then
verify(applicationManagerWrapper, never()).deleteApplication(subject, "REALM", resourceId);
result.getOrThrowUninterruptibly();
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldDeleteInstance.
@Test
public void shouldDeleteInstance() throws EntitlementException, ResourceException {
//Given
SSOTokenContext subjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(subjectContext);
realmContext.setSubRealm("REALM", "REALM");
Context context = ClientContext.newInternalClientContext(realmContext);
String resourceId = "iPlanetAMWebAgentService";
DeleteRequest request = mock(DeleteRequest.class);
Subject subject = new Subject();
Application mockApplication = mock(Application.class);
given(subjectContext.getCallerSubject()).willReturn(subject);
given(applicationManagerWrapper.getApplication(any(Subject.class), anyString(), anyString())).willReturn(mockApplication);
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.deleteInstance(context, resourceId, request);
//Then
verify(applicationManagerWrapper).deleteApplication(subject, "/REALM", resourceId);
ResourceResponse resource = result.getOrThrowUninterruptibly();
assertEquals(resource.getId(), resourceId);
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldUseSubjectFromContextOnRead.
@Test
public void shouldUseSubjectFromContextOnRead() throws EntitlementException {
// Given
String resourceID = "ferret";
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
realmContext.setSubRealm("badger", "badger");
Context serverContext = ClientContext.newInternalClientContext(realmContext);
Subject subject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(subject);
Application mockApplication = mock(Application.class);
given(applicationManagerWrapper.getApplication(any(Subject.class), anyString(), anyString())).willReturn(mockApplication);
// When
applicationsResource.readInstance(serverContext, resourceID, null);
// Then
verify(applicationManagerWrapper).getApplication(eq(subject), anyString(), anyString());
}
Aggregations