Search in sources :

Example 66 with Context

use of org.forgerock.services.context.Context 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 67 with Context

use of org.forgerock.services.context.Context 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 68 with Context

use of org.forgerock.services.context.Context 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 69 with Context

use of org.forgerock.services.context.Context 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 70 with Context

use of org.forgerock.services.context.Context 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

Context (org.forgerock.services.context.Context)250 Test (org.testng.annotations.Test)231 RealmContext (org.forgerock.openam.rest.RealmContext)150 ResourceException (org.forgerock.json.resource.ResourceException)132 ClientContext (org.forgerock.services.context.ClientContext)120 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)101 ResourceResponse (org.forgerock.json.resource.ResourceResponse)82 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)76 RootContext (org.forgerock.services.context.RootContext)62 JsonValue (org.forgerock.json.JsonValue)56 QueryRequest (org.forgerock.json.resource.QueryRequest)54 ReadRequest (org.forgerock.json.resource.ReadRequest)50 AttributesContext (org.forgerock.services.context.AttributesContext)44 ActionRequest (org.forgerock.json.resource.ActionRequest)43 QueryResponse (org.forgerock.json.resource.QueryResponse)43 Subject (javax.security.auth.Subject)42 Matchers.anyString (org.mockito.Matchers.anyString)38 Request (org.forgerock.http.protocol.Request)37 UpdateRequest (org.forgerock.json.resource.UpdateRequest)36 DeleteRequest (org.forgerock.json.resource.DeleteRequest)35