Search in sources :

Example 96 with ResourceException

use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.

the class PendingRequestResourceTest method actionInstanceShouldHandleDenyAction.

@SuppressWarnings("unchecked")
@Test
public void actionInstanceShouldHandleDenyAction() throws Exception {
    //Given
    Context context = mockContext("REALM");
    ActionRequest request = Requests.newActionRequest("", "deny");
    mockPendingRequestsForUser("alice", "REALM", 1);
    //When
    Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
    //Then
    verify(service).denyPendingRequest(anyString(), anyString());
    assertThat(promise).succeeded();
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 97 with ResourceException

use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.

the class PendingRequestResourceTest method shouldReadPendingRequest.

@SuppressWarnings("unchecked")
@Test
public void shouldReadPendingRequest() throws Exception {
    //Given
    Context context = mock(Context.class);
    ReadRequest request = Requests.newReadRequest("");
    String id = mockPendingRequest();
    //When
    Promise<ResourceResponse, ResourceException> promise = resource.readInstance(context, id, request);
    //Then
    assertThat(promise).succeeded();
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) Matchers.anyString(org.mockito.Matchers.anyString) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 98 with ResourceException

use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.

the class PendingRequestResourceTest method actionCollectionShouldHandleApproveAction.

@SuppressWarnings("unchecked")
@Test
public void actionCollectionShouldHandleApproveAction() throws Exception {
    //Given
    Context context = mockContext("REALM");
    ActionRequest request = Requests.newActionRequest("", "approve");
    mockPendingRequestsForUser("alice", "REALM", 2);
    mockPendingRequestApprovalService();
    //When
    Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
    //Then
    verify(service, times(2)).approvePendingRequest(eq(context), anyString(), any(JsonValue.class), anyString());
    assertThat(promise).succeeded();
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) ActionRequest(org.forgerock.json.resource.ActionRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 99 with ResourceException

use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.

the class PendingRequestResourceTest method actionInstanceShouldReturnNotSupportedExceptionForUnsupportedAction.

@SuppressWarnings("unchecked")
@Test
public void actionInstanceShouldReturnNotSupportedExceptionForUnsupportedAction() {
    //Given
    Context context = mock(Context.class);
    ActionRequest request = Requests.newActionRequest("", "other");
    //When
    Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
    //Then
    assertThat(promise).failedWithResourceException().isInstanceOf(NotSupportedException.class);
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 100 with ResourceException

use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.

the class ResourceSetResourceTest method actionCollectionShouldHandleUnsupportedAction.

@Test
public void actionCollectionShouldHandleUnsupportedAction() {
    //Given
    Context context = mock(Context.class);
    ActionRequest request = mock(ActionRequest.class);
    given(request.getAction()).willReturn("UNSUPPORTED_ACTION");
    //When
    Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
    //Then
    assertThat(promise).failedWithException().isInstanceOf(NotSupportedException.class);
}
Also used : Context(org.forgerock.services.context.Context) 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