Search in sources :

Example 56 with QueryResponse

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

the class UmaPolicyServiceImplTest method shouldHandleFailureToUpdateUnderlyingPolicies.

@Test(expectedExceptions = ResourceException.class)
public void shouldHandleFailureToUpdateUnderlyingPolicies() throws Exception {
    //Given
    Context context = createContext();
    JsonValue policy = createUmaPolicyJson("RESOURCE_SET_ID", "SCOPE_A", "SCOPE_B");
    ResourceException exception = mock(ResourceException.class);
    Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> currentPolicyPromise = newResultPromise(Pair.of((QueryResponse) null, Collections.<ResourceResponse>emptyList()));
    Promise<List<ResourceResponse>, ResourceException> updatePoliciesPromise = newExceptionPromise(exception);
    given(policyResourceDelegate.queryPolicies(eq(context), Matchers.<QueryRequest>anyObject())).willReturn(currentPolicyPromise);
    given(policyResourceDelegate.updatePolicies(eq(context), Matchers.<Set<JsonValue>>anyObject())).willReturn(updatePoliciesPromise);
    //When
    policyService.updatePolicy(context, "RESOURCE_SET_ID", policy).getOrThrowUninterruptibly();
//Then
//Expected ResourceException
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) List(java.util.List) ArrayList(java.util.ArrayList) Pair(org.forgerock.util.Pair) Test(org.testng.annotations.Test)

Example 57 with QueryResponse

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

the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesByUnknownSubjectAndResourceServer.

@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesByUnknownSubjectAndResourceServer() throws Exception {
    //Given
    Context context = createContext();
    QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.and(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "OTHER_SUBJECT"), QueryFilter.equalTo(new JsonPointer("resourceServer"), "CLIENT_ID")));
    mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
    //When
    Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
    //Then
    assertThat(queryResult.getSecond()).hasSize(0);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) QueryResponse(org.forgerock.json.resource.QueryResponse) Collection(java.util.Collection) JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Aggregations

QueryResponse (org.forgerock.json.resource.QueryResponse)57 Test (org.testng.annotations.Test)49 ResourceException (org.forgerock.json.resource.ResourceException)43 QueryRequest (org.forgerock.json.resource.QueryRequest)42 Context (org.forgerock.services.context.Context)42 RealmContext (org.forgerock.openam.rest.RealmContext)37 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)26 ClientContext (org.forgerock.services.context.ClientContext)25 ResourceResponse (org.forgerock.json.resource.ResourceResponse)24 Collection (java.util.Collection)23 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)20 JsonPointer (org.forgerock.json.JsonPointer)19 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)19 Pair (org.forgerock.util.Pair)19 UmaPolicy (org.forgerock.openam.uma.UmaPolicy)16 HashSet (java.util.HashSet)14 JsonValue (org.forgerock.json.JsonValue)13 ArrayList (java.util.ArrayList)12 Subject (javax.security.auth.Subject)12 Responses.newQueryResponse (org.forgerock.json.resource.Responses.newQueryResponse)12