Search in sources :

Example 31 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class UmaPolicyResourceTest method shouldSuccessfullyQueryPolicies.

@Test
public void shouldSuccessfullyQueryPolicies() {
    //Given
    Context context = mock(Context.class);
    QueryRequest request = Requests.newQueryRequest("/policies");
    QueryResourceHandler handler = mock(QueryResourceHandler.class);
    given(handler.handleResource(any(ResourceResponse.class))).willReturn(true);
    QueryResponse queryResult = newQueryResponse();
    Collection<UmaPolicy> umaPolicies = new HashSet<UmaPolicy>();
    UmaPolicy policy1 = mock(UmaPolicy.class);
    UmaPolicy policy2 = mock(UmaPolicy.class);
    umaPolicies.add(policy1);
    umaPolicies.add(policy2);
    Promise<Pair<QueryResponse, Collection<UmaPolicy>>, ResourceException> promise = Promises.newResultPromise(Pair.of(queryResult, umaPolicies));
    given(policyService.queryPolicies(context, request)).willReturn(promise);
    //When
    policyResource.queryCollection(context, request, handler);
    //Then
    verify(handler, times(2)).handleResource(Matchers.<ResourceResponse>anyObject());
}
Also used : Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) ResourceResponse(org.forgerock.json.resource.ResourceResponse) Responses.newQueryResponse(org.forgerock.json.resource.Responses.newQueryResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) HashSet(java.util.HashSet) Pair(org.forgerock.util.Pair) Test(org.testng.annotations.Test)

Example 32 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class UmaPolicyResourceTest method shouldSuccessfullyDeletePolicy.

@Test
@SuppressWarnings("unchecked")
public void shouldSuccessfullyDeletePolicy() {
    //Given
    Context context = mock(Context.class);
    DeleteRequest request = Requests.newDeleteRequest("/policies");
    Promise<Void, ResourceException> promise = Promises.newResultPromise(null);
    given(policyService.deletePolicy(context, "RESOURCE_SET_UID")).willReturn(promise);
    //When
    Promise<ResourceResponse, ResourceException> result = policyResource.deleteInstance(context, "RESOURCE_SET_UID", request);
    //Then
    assertThat(result).succeeded().withId().isEqualTo("RESOURCE_SET_UID");
    assertThat(result).succeeded().withRevision().isEqualTo("0");
    assertThat(result).succeeded().withContent().isEmpty();
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test)

Example 33 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class UmaPolicyResourceTest method shouldHandledFailedUpdatePolicy.

@Test
@SuppressWarnings("unchecked")
public void shouldHandledFailedUpdatePolicy() {
    //Given
    Context context = mock(Context.class);
    UpdateRequest request = Requests.newUpdateRequest("/policies", json(object()));
    ResourceException resourceException = mock(ResourceException.class);
    Promise<UmaPolicy, ResourceException> promise = Promises.newExceptionPromise(resourceException);
    given(policyService.updatePolicy(context, "RESOURCE_SET_UID", request.getContent())).willReturn(promise);
    //When
    Promise<ResourceResponse, ResourceException> result = policyResource.updateInstance(context, "RESOURCE_SET_UID", request);
    //Then
    assertThat(result).failedWithResourceException().isEqualTo(resourceException);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) ResourceException(org.forgerock.json.resource.ResourceException) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) Test(org.testng.annotations.Test)

Example 34 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class UmaPolicyResourceTest method shouldHandledFailedCreatePolicy.

@Test
@SuppressWarnings("unchecked")
public void shouldHandledFailedCreatePolicy() {
    //Given
    Context context = mock(Context.class);
    CreateRequest request = Requests.newCreateRequest("/policies", json(object()));
    ResourceException resourceException = mock(ResourceException.class);
    Promise<UmaPolicy, ResourceException> promise = Promises.newExceptionPromise(resourceException);
    given(policyService.createPolicy(context, request.getContent())).willReturn(promise);
    //When
    Promise<ResourceResponse, ResourceException> result = policyResource.createInstance(context, request);
    //Then
    assertThat(result).failedWithResourceException().isEqualTo(resourceException);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) ResourceException(org.forgerock.json.resource.ResourceException) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) Test(org.testng.annotations.Test)

Example 35 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class UmaPolicyResourceTest method shouldThrowNotSupportedExceptionForActionInstance.

@Test
@SuppressWarnings("unchecked")
public void shouldThrowNotSupportedExceptionForActionInstance() {
    //Given
    Context context = mock(Context.class);
    ActionRequest request = Requests.newActionRequest("/policies", "ACTION_ID");
    //When
    Promise<ActionResponse, ResourceException> result = policyResource.actionInstance(context, "RESOURCE_SET_ID", request);
    //Then
    assertThat(result).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