use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method testSuccessfulJsonificationAndLogicalIsCorrect.
@Test
public void testSuccessfulJsonificationAndLogicalIsCorrect() throws JsonMappingException, ExecutionException, InterruptedException {
//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_LOGICAL_CONDITION, mockRequest);
//then
Map resultMap = result.get().getContent().asMap();
assertThat(resultMap.containsKey("logical")).isTrue();
assertThat(resultMap.get("logical")).isEqualTo(true);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class DecisionCombinersResourceTest 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.json.resource.ResourceException in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldCreateApplication.
@Test
public void shouldCreateApplication() throws ExecutionException, ResourceException {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
realmContext.setSubRealm("/", "/");
CreateRequest mockCreateRequest = mock(CreateRequest.class);
Subject mockSubject = new Subject();
Application mockApplication = mock(Application.class);
applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {
@Override
protected ApplicationWrapper createApplicationWrapper(JsonValue jsonValue, Subject mySubject) throws EntitlementException {
return applicationWrapper;
}
@Override
protected ApplicationWrapper createApplicationWrapper(Application application, ApplicationTypeManagerWrapper type) {
return applicationWrapper;
}
};
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
given(applicationWrapper.getApplication()).willReturn(mockApplication);
given(mockApplication.getName()).willReturn("newApplication");
//when
Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(realmContext, mockCreateRequest);
//then
assertThat(result.getOrThrowUninterruptibly()).isNotNull();
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldThrowBadRequestIfApplicationWrapperCannotBeCreated.
@Test(expectedExceptions = BadRequestException.class)
public void shouldThrowBadRequestIfApplicationWrapperCannotBeCreated() 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);
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(317);
}
};
//when
Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(mockServerContext, mockCreateRequest);
//then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class EntitlementsExceptionMappingHandlerTest method shouldMapKnownErrorsAsConfigured.
@Test
public void shouldMapKnownErrorsAsConfigured() {
// Given
EntitlementsExceptionMappingHandler errorHandler = new EntitlementsExceptionMappingHandler(Collections.singletonMap(ERROR_CODE, ResourceException.NOT_FOUND));
EntitlementException error = exception(ERROR_CODE, ERROR_MESSAGE);
// When
ResourceException result = errorHandler.handleError(error);
// Then
assertThat(result).isInstanceOf(NotFoundException.class).hasMessage(ERROR_MESSAGE);
}
Aggregations