use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method deleteInstanceShouldHandleFailedDeleteApplication.
@Test(expectedExceptions = NotFoundException.class)
public void deleteInstanceShouldHandleFailedDeleteApplication() 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);
doThrow(EntitlementException.class).when(applicationManagerWrapper).deleteApplication(any(Subject.class), anyString(), eq(resourceId));
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.deleteInstance(context, resourceId, request);
//Then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method updateInstanceShouldReturnForbiddenWhenUpdatingFailsDueToNotAuthorized.
@Test(expectedExceptions = ForbiddenException.class)
public void updateInstanceShouldReturnForbiddenWhenUpdatingFailsDueToNotAuthorized() 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(326)).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 shouldUpdateInstance.
@Test
public void shouldUpdateInstance() 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 application = mock(Application.class);
Application newApplication = mock(Application.class);
JsonValue response = mock(JsonValue.class);
given(subjectContext.getCallerSubject()).willReturn(subject);
given(request.getContent()).willReturn(content);
given(applicationManagerWrapper.getApplication(subject, "/REALM", resourceId)).willReturn(application);
given(applicationWrapper.getName()).willReturn("APP_NAME");
given(applicationWrapper.getApplication()).willReturn(newApplication);
given(newApplication.getLastModifiedDate()).willReturn(1000L);
given(applicationWrapper.toJsonValue()).willReturn(response);
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
//Then
verify(applicationManagerWrapper).updateApplication(application, applicationWrapper.getApplication(), subject, "/REALM");
ResourceResponse resource = result.getOrThrowUninterruptibly();
assertEquals(resource.getId(), "APP_NAME");
assertEquals(resource.getRevision(), "1000");
assertEquals(resource.getContent(), response);
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldReturnBadRequestIfCannotReturnResource.
@Test(expectedExceptions = BadRequestException.class)
public void shouldReturnBadRequestIfCannotReturnResource() throws EntitlementException, ResourceException {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
realmContext.setSubRealm("/", "/");
CreateRequest mockCreateRequest = mock(CreateRequest.class);
Subject subject = null;
given(mockSSOTokenContext.getCallerSubject()).willReturn(subject);
doThrow(new EntitlementException(1)).when(applicationWrapper).toJsonValue();
//when
Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(realmContext, mockCreateRequest);
//then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.openam.rest.RealmContext 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();
}
Aggregations