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());
}
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();
}
}
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();
}
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);
}
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);
}
Aggregations