Search in sources :

Example 11 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class QueryByStringFilterConverterTest method shouldThrowQueryException.

@Test
public void shouldThrowQueryException() {
    // given
    QueryFilter<JsonPointer> filter = comparisonFilter(new JsonPointer("param1/param2"), "eq", "*");
    // when
    QueryException exception = null;
    try {
        filter.accept(new QueryByStringFilterConverter(), null);
    } catch (QueryException e) {
        exception = e;
    }
    // then
    assertThat(exception).isNotNull();
    assertThat(exception.getErrorCode()).isEqualTo(QueryException.QueryErrorCode.FILTER_DEPTH_NOT_SUPPORTED.name());
}
Also used : JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Example 12 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class ScriptResource method queryCollection.

@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler resultHandler) {
    final QueryFilter<JsonPointer> filter = request.getQueryFilter();
    try {
        final Set<ScriptConfiguration> configs;
        if (filter == null) {
            configs = serviceFactory.create(getContextSubject(context), getRealm(context)).getAll();
        } else {
            QueryFilter<String> stringQueryFilter = filter.accept(new QueryByStringFilterConverter(), null);
            configs = serviceFactory.create(getContextSubject(context), getRealm(context)).get(stringQueryFilter);
        }
        List<ResourceResponse> results = new ArrayList<>();
        for (ScriptConfiguration configuration : configs) {
            String id = configuration.getId();
            results.add(newResourceResponse(id, null, asJson(configuration)));
        }
        QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
        return QueryResponsePresentation.perform(resultHandler, request, results);
    } catch (ScriptException se) {
        return exceptionMappingHandler.handleError(context, request, se).asPromise();
    }
}
Also used : ScriptException(org.forgerock.openam.scripting.ScriptException) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryByStringFilterConverter(org.forgerock.openam.rest.query.QueryByStringFilterConverter) ArrayList(java.util.ArrayList) ScriptConfiguration(org.forgerock.openam.scripting.service.ScriptConfiguration) JsonPointer(org.forgerock.json.JsonPointer)

Example 13 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class ResourceSetResourceTest method shouldReadResourceSet.

@Test
public void shouldReadResourceSet() throws Exception {
    //Given
    Context context = mock(Context.class);
    ReadRequest request = mock(ReadRequest.class);
    given(request.getFields()).willReturn(Arrays.asList(new JsonPointer("/fred")));
    ResourceSetDescription resourceSet = new ResourceSetDescription();
    resourceSet.setDescription(json(object()));
    Promise<ResourceSetDescription, ResourceException> resourceSetPromise = Promises.newResultPromise(resourceSet);
    given(contextHelper.getRealm(context)).willReturn("REALM");
    given(contextHelper.getUserId(context)).willReturn("RESOURCE_OWNER_ID");
    given(resourceSetService.getResourceSet(context, "REALM", "RESOURCE_SET_ID", "RESOURCE_OWNER_ID", false)).willReturn(resourceSetPromise);
    //When
    Promise<ResourceResponse, ResourceException> readPromise = resource.readInstance(context, "RESOURCE_SET_ID", request);
    //Then
    assertThat(readPromise).succeeded().withObject().isNotNull();
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) JsonPointer(org.forgerock.json.JsonPointer) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 14 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class ResourceSetResourceTest method queryShouldNotBeSupported.

@Test
public void queryShouldNotBeSupported() {
    //Given
    Context context = mock(Context.class);
    QueryRequest request = mock(QueryRequest.class);
    QueryResourceHandler handler = mock(QueryResourceHandler.class);
    given(request.getQueryFilter()).willReturn(QueryFilter.equalTo(new JsonPointer("/fred"), 5));
    //When
    Promise<QueryResponse, ResourceException> promise = resource.queryCollection(context, request, handler);
    //Then
    assertThat(promise).failedWithException().isInstanceOf(NotSupportedException.class);
}
Also used : Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Example 15 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class PolicyGraphTest method makePolicy.

private static ResourceResponse makePolicy(String owner, String subject, boolean active, String... scopes) {
    String policyId = owner + "-" + subject + "-" + active;
    JsonValue policy = json(object(field("_id", policyId), field(PolicyGraph.OWNER_KEY, owner), field(SUBJECT_KEY, object(field(BACKEND_POLICY_SUBJECT_CLAIM_VALUE_KEY, subject))), field(PolicyGraph.ACTIVE_KEY, active)));
    for (String scope : scopes) {
        policy.putPermissive(new JsonPointer(BACKEND_POLICY_ACTION_VALUES_KEY + "/" + scope), true);
    }
    return Responses.newResourceResponse(policyId, String.valueOf(policyId.hashCode()), policy);
}
Also used : JsonValue(org.forgerock.json.JsonValue) Mockito.anyString(org.mockito.Mockito.anyString) JsonPointer(org.forgerock.json.JsonPointer)

Aggregations

JsonPointer (org.forgerock.json.JsonPointer)64 Test (org.testng.annotations.Test)40 QueryRequest (org.forgerock.json.resource.QueryRequest)34 JsonValue (org.forgerock.json.JsonValue)21 QueryResponse (org.forgerock.json.resource.QueryResponse)19 Context (org.forgerock.services.context.Context)18 RealmContext (org.forgerock.openam.rest.RealmContext)17 Collection (java.util.Collection)15 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)13 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)13 ClientContext (org.forgerock.services.context.ClientContext)13 Subject (javax.security.auth.Subject)10 ResourceException (org.forgerock.json.resource.ResourceException)10 ResourceResponse (org.forgerock.json.resource.ResourceResponse)10 ArrayList (java.util.ArrayList)9 BadRequestException (org.forgerock.json.resource.BadRequestException)9 SearchFilter (com.sun.identity.entitlement.util.SearchFilter)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 List (java.util.List)7