use of org.forgerock.json.resource.ResourceResponse 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.json.resource.ResourceResponse 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.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldThrowInternalIfApplicationClassCannotBeInstantiated.
@Test(expectedExceptions = InternalServerErrorException.class)
public void shouldThrowInternalIfApplicationClassCannotBeInstantiated() throws ResourceException {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
realmContext.setSubRealm("/", "/");
CreateRequest mockCreateRequest = mock(CreateRequest.class);
Subject subject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(subject);
applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {
@Override
protected ApplicationWrapper createApplicationWrapper(JsonValue jsonValue, Subject mySubject) throws EntitlementException {
throw new EntitlementException(6);
}
};
//when
Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(realmContext, mockCreateRequest);
//then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldNotUpdateInstanceIfApplicationNotFound.
@Test(expectedExceptions = NotFoundException.class)
public void shouldNotUpdateInstanceIfApplicationNotFound() 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 = new Subject();
JsonValue content = mock(JsonValue.class);
Application mockApplication = mock(Application.class);
given(subjectContext.getCallerSubject()).willReturn(subject);
given(request.getContent()).willReturn(content);
given(applicationManagerWrapper.getApplication(subject, "REALM", resourceId)).willReturn(null);
given(applicationWrapper.getApplication()).willReturn(mockApplication);
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
//Then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldReturnNullIfSubjectNullOnCreate.
@Test(expectedExceptions = BadRequestException.class)
public void shouldReturnNullIfSubjectNullOnCreate() throws ResourceException {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
realmContext.setSubRealm("REALM", "REALM");
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
CreateRequest mockCreateRequest = mock(CreateRequest.class);
given(mockSSOTokenContext.getCallerSubject()).willReturn(null);
//when
Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(mockServerContext, mockCreateRequest);
//then
result.getOrThrowUninterruptibly();
}
Aggregations