use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RequesterTest method emptyLocationBreaksQuery.
//
// test query()
//
@Test(expectedExceptions = IllegalArgumentException.class)
public void emptyLocationBreaksQuery() throws ResourceException {
// given
String location = "";
String queryId = "queryId";
Context fakeContext = mock(Context.class);
// when
requester.query(location, queryId, fakeContext);
// then -- matched by expectedExceptions
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RequesterTest method nullLocationBreaksDelete.
@Test(expectedExceptions = IllegalArgumentException.class)
public void nullLocationBreaksDelete() throws ResourceException {
// given
String location = null;
String resourceId = "resourceId";
Context fakeContext = mock(Context.class);
// when
requester.delete(location, resourceId, fakeContext);
// then -- matched by expectedExceptions
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class ScriptExceptionMappingHandlerTest method shouldTranslateMessageToAcceptLanguage.
@Test
public void shouldTranslateMessageToAcceptLanguage() throws Exception {
// given
final Context serverContext = getHttpServerContext("te");
for (ScriptErrorCode errorCode : ScriptErrorCode.values()) {
// when
ResourceException re = mappingHandler.handleError(serverContext, null, new ScriptException(errorCode));
// then
assertNotNull(re);
// assertEquals("Test message", re.getMessage()); //TODO dont get this...
}
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class BatchResourceTest method shouldRejectNonBatchActions.
@Test
public void shouldRejectNonBatchActions() {
//given
Context mockContext = Mockito.mock(Context.class);
ActionRequest mockRequest = mock(ActionRequest.class);
given(mockRequest.getAction()).willReturn("false");
@SuppressWarnings("unchecked") ExceptionHandler<ResourceException> handler = mock(ExceptionHandler.class);
//when
Promise<ActionResponse, ResourceException> result = batchResource.actionCollection(mockContext, mockRequest);
result.thenOnException(handler);
//then
verify(handler, times(1)).handleException(any(ResourceException.class));
verifyNoMoreInteractions(handler);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class UmaPolicyResourceTest method shouldSuccessfullyCreatePolicy.
@Test
@SuppressWarnings("unchecked")
public void shouldSuccessfullyCreatePolicy() {
//Given
Context context = mock(Context.class);
CreateRequest request = Requests.newCreateRequest("/policies", json(object()));
UmaPolicy policy = mock(UmaPolicy.class);
Promise<UmaPolicy, ResourceException> promise = Promises.newResultPromise(policy);
given(policy.getId()).willReturn("ID");
given(policy.getRevision()).willReturn("REVISION");
given(policyService.createPolicy(context, request.getContent())).willReturn(promise);
//When
Promise<ResourceResponse, ResourceException> result = policyResource.createInstance(context, request);
//Then
assertThat(result).succeeded().withId().isEqualTo("ID");
assertThat(result).succeeded().withRevision().isEqualTo("REVISION");
assertThat(result).succeeded().withContent().isEmpty();
}
Aggregations