use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldNotUpdateInstanceWhenSubjectIsNull.
@Test(expectedExceptions = BadRequestException.class)
public void shouldNotUpdateInstanceWhenSubjectIsNull() 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";
UpdateRequest request = mock(UpdateRequest.class);
Subject subject = null;
given(subjectContext.getCallerSubject()).willReturn(subject);
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
//Then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method updateInstanceShouldReturnConflictWhenUpdatingFailsDueToNeedToDeletePolicies.
@Test(expectedExceptions = ConflictException.class)
public void updateInstanceShouldReturnConflictWhenUpdatingFailsDueToNeedToDeletePolicies() 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";
UpdateRequest request = mock(UpdateRequest.class);
Subject subject = new Subject();
JsonValue content = mock(JsonValue.class);
Application mockApplication = mock(Application.class);
given(subjectContext.getCallerSubject()).willReturn(subject);
given(request.getContent()).willReturn(content);
given(applicationWrapper.getApplication()).willReturn(mockApplication);
given(applicationManagerWrapper.getApplication(subject, "/REALM", resourceId)).willReturn(mockApplication);
doThrow(new EntitlementException(404)).when(applicationManagerWrapper).updateApplication(any(Application.class), any(Application.class), any(Subject.class), anyString());
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
//Then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldUseResourceIDForFetchingApplicationOnRead.
@Test
public void shouldUseResourceIDForFetchingApplicationOnRead() throws EntitlementException {
// Given
String resourceID = "iPlanetAMWebAgentService";
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(any(Subject.class), anyString(), eq(resourceID));
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldUseRealmFromContextSubjectOnRead.
@Test
public void shouldUseRealmFromContextSubjectOnRead() throws EntitlementException {
// Given
String resourceID = "ferret";
String realmID = "/badger";
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
realmContext.setSubRealm(realmID, realmID);
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(any(Subject.class), eq(realmID), anyString());
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldHandleApplicationFindFailure.
@Test(expectedExceptions = NotFoundException.class)
public void shouldHandleApplicationFindFailure() throws EntitlementException, ResourceException {
// Given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
realmContext.setSubRealm("abc", "abc");
Context serverContext = ClientContext.newInternalClientContext(realmContext);
// Set the page size to be three starting from the second item.
QueryRequest request = mock(QueryRequest.class);
given(request.getPageSize()).willReturn(3);
given(request.getPagedResultsOffset()).willReturn(1);
QueryResourceHandler handler = mock(QueryResourceHandler.class);
given(handler.handleResource(any(ResourceResponse.class))).willReturn(true);
Subject subject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
EntitlementException exception = new EntitlementException(EntitlementException.APP_RETRIEVAL_ERROR);
given(applicationManagerWrapper.search(eq(subject), eq("/abc"), any(Set.class))).willThrow(exception);
// When
Promise<QueryResponse, ResourceException> result = applicationsResource.queryCollection(serverContext, request, handler);
// Then
result.getOrThrowUninterruptibly();
}
Aggregations