Search in sources :

Example 31 with ResourceException

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());
}
Also used : SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 32 with ResourceException

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");
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) Token(org.forgerock.openam.cts.api.tokens.Token) ResourceException(org.forgerock.json.resource.ResourceException) Matchers.anyString(org.mockito.Matchers.anyString) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 33 with ResourceException

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);
}
Also used : JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 34 with ResourceException

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);
}
Also used : JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 35 with ResourceException

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);
}
Also used : ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Aggregations

ResourceException (org.forgerock.json.resource.ResourceException)323 Test (org.testng.annotations.Test)233 ResourceResponse (org.forgerock.json.resource.ResourceResponse)179 JsonValue (org.forgerock.json.JsonValue)145 Context (org.forgerock.services.context.Context)145 RealmContext (org.forgerock.openam.rest.RealmContext)110 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)71 Subject (javax.security.auth.Subject)58 ClientContext (org.forgerock.services.context.ClientContext)56 NotFoundException (org.forgerock.json.resource.NotFoundException)47 BadRequestException (org.forgerock.json.resource.BadRequestException)44 QueryResponse (org.forgerock.json.resource.QueryResponse)43 HashSet (java.util.HashSet)42 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)42 CreateRequest (org.forgerock.json.resource.CreateRequest)40 SSOException (com.iplanet.sso.SSOException)38 ActionResponse (org.forgerock.json.resource.ActionResponse)37 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)37 Matchers.anyString (org.mockito.Matchers.anyString)37 ArrayList (java.util.ArrayList)35