use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class CoreTokenResourceAuthzModuleTest method shouldBlockAllAccessIfResourceDisabled.
@Test
public void shouldBlockAllAccessIfResourceDisabled() throws Exception {
//given
CoreTokenResourceAuthzModule testModule = new CoreTokenResourceAuthzModule(mockConfig, mockDebug, false);
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext);
//then
assertFalse(result.get().isAuthorized());
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class CoreTokenResourceTest method shouldReadAndReturnTokenInSerialisedForm.
@Test
public void shouldReadAndReturnTokenInSerialisedForm() throws CoreTokenException {
// Given
String serialisedToken = "{ \"value\": \"some JSON\" }";
given(mockStore.read(anyString())).willReturn(mockToken);
given(mockSerialisation.serialise(any(Token.class))).willReturn(serialisedToken);
// When
Promise<ResourceResponse, ResourceException> promise = resource.readInstance(null, "", mock(ReadRequest.class));
// Then
assertThat(promise).succeeded().withContent().stringAt("value").isEqualTo("some JSON");
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class RecordResourceTest method startRecording.
@Test
public void startRecording() throws IOException, ExecutionException, InterruptedException {
// Given...
JsonValue jsonRecordProperties = JsonValueBuilder.toJsonValue(IOUtils.getFileContentFromClassPath(RecordResourceTest.class, RECORD_DIRECTORY + "startSimpleRecord.json"));
given(request.getAction()).willReturn("start");
given(request.getContent()).willReturn(jsonRecordProperties);
// When...
Promise<ActionResponse, ResourceException> promise = recordResource.actionCollection(serverContext, request);
// Then...
verify(request).getAction();
RecordProperties recordPropertiesInput = RecordProperties.fromJson(jsonRecordProperties);
RecordProperties recordPropertiesOutput = RecordProperties.fromJson(promise.get().getJsonContent().get("record"));
assertThat(recordPropertiesInput).isEqualTo(recordPropertiesOutput);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class RecordResourceTest method stopRecording.
@Test
public void stopRecording() throws IOException, RecordException, ExecutionException, InterruptedException {
JsonValue jsonRecordProperties = JsonValueBuilder.toJsonValue(IOUtils.getFileContentFromClassPath(RecordResourceTest.class, RECORD_DIRECTORY + "startSimpleRecord.json"));
debugRecorder.startRecording(jsonRecordProperties);
// Given...
given(request.getAction()).willReturn("stop");
// When...
Promise<ActionResponse, ResourceException> promise = recordResource.actionCollection(serverContext, request);
// Then...
verify(request).getAction();
RecordProperties recordPropertiesInput = RecordProperties.fromJson(jsonRecordProperties);
RecordProperties recordPropertiesOutput = RecordProperties.fromJson(promise.get().getJsonContent().get("record"));
assertThat(recordPropertiesInput).isEqualTo(recordPropertiesOutput);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class OathDevicesResourceTest method shouldFailOnUnknownActionInstance.
@Test
public void shouldFailOnUnknownActionInstance() throws ResourceException, SSOException {
// given
ActionRequest actionRequest = mock(ActionRequest.class);
// when
Promise<ActionResponse, ResourceException> promise = resource.actionInstance(ctx(), "", actionRequest);
// then
assertThat(promise).failedWithResourceException().withCode(ResourceException.NOT_SUPPORTED);
}
Aggregations