### Question:
ServiceCollectionResource { @POST @Produces({MediaType.APPLICATION_JSON}) @Consumes(MediaType.APPLICATION_JSON) public Response richQueryForJSON(JSONObject queryDocument, @Context UriInfo ui) throws WebApplicationException, JSONException { MultivaluedMap<String, String> queryParams = ui.getQueryParameters(); Set<String> s = queryParams.keySet(); Map<String, Object> m = new HashMap<String, Object>(); for (Iterator<String> iterator = s.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); m.put(key, queryParams.getFirst(key)); } JSONArray jArr = null; try { jArr = col.queryForJSON(queryDocument, m); } catch (Exception e) { Log.logException("Error in doing query for services in JSON format", e, logger); JSONArray err = new JSONArray(); err.put(ExceptionUtil.toJson(e)); throw new WebApplicationException(e,Response.status(Status.INTERNAL_SERVER_ERROR).entity(err).build()); } if (jArr.length() == 0) { return Response.ok(jArr).status(Status.NO_CONTENT).build(); } return Response.ok(jArr).build(); } ServiceCollectionResource(); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/urls") Response getServiceEndPoints(); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/types") Response getServiceTypes(); @GET @Produces(MediaType.APPLICATION_JSON) Response queryWithParamsForJSON(@Context UriInfo ui); @GET @Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML }) Response queryWithParamsForXML(@Context UriInfo ui); @POST @Produces({MediaType.APPLICATION_JSON}) @Consumes(MediaType.APPLICATION_JSON) Response richQueryForJSON(JSONObject queryDocument, @Context UriInfo ui); @POST @Produces(MediaType.APPLICATION_XML) @Consumes(MediaType.APPLICATION_JSON) Response richQueryForXML(JSONObject queryDocument, @Context UriInfo ui); @Deprecated @GET @Path("/query.xml") @Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML }) Response queryXml(@Context UriInfo ui); @Deprecated @GET @Path("/pagedquery") @Produces(MediaType.APPLICATION_JSON) Response pagedQuery(@Context UriInfo ui); @Deprecated @GET @Path("/pagedquery") @Produces(MediaType.APPLICATION_XML) Response pagedQueryGlue2(@Context UriInfo ui);  }### Answer:
@Test @FunctionalTest(id = "ServiceEndpointRecordsQueryForJSONTest", description = "Test queries defined in JSON format for the service endpoint records in JSON format") public void testRichQueryForJSON() throws JSONException { EMIRClient cr = new EMIRClient(BaseURI); JSONObject orQueryDocument = new JSONObject(); JSONObject p1 = new JSONObject(); p1.put(ServiceBasicAttributeNames.SERVICE_TYPE.getAttributeName(), "jms"); JSONObject p2 = new JSONObject(); p2.put(ServiceBasicAttributeNames.SERVICE_ENDPOINT_HEALTH_STATE .getAttributeName(), "ok"); JSONArray j = new JSONArray(); j.put(p1); j.put(p2); orQueryDocument.put("$or", j); assertEquals(100, cr.richQueryForJSON(orQueryDocument).length()-1); JSONObject jo = new JSONObject(); jo.put("$ne", "ok"); JSONObject ne = new JSONObject(); ne.put(ServiceBasicAttributeNames.SERVICE_ENDPOINT_HEALTH_STATE .getAttributeName(), jo); assertEquals(50, cr.richQueryForJSON(ne).length()); }