### Question:
ServiceAdminResource { public Response registerService(JSONObject serviceInfo) throws WebApplicationException, JSONException { Integer length = serviceInfo.length(); if (length <= 0 || length > 100) { throw new WebApplicationException(Status.FORBIDDEN); } try { Client c = (Client) req.getAttribute("client"); if (!EMIRServer.getServerSecurityProperties().isSslEnabled() && c == null) { c = Client.getAnonymousClient(); } serviceInfo.put(ServiceBasicAttributeNames.SERVICE_OWNER_DN .getAttributeName(), c.getDistinguishedName()); JSONObject res = serviceAdmin.addService(serviceInfo); return Response.ok(res).build(); } catch (ExistingResourceException e) { return Response.status(Status.CONFLICT).entity(serviceInfo).build(); } catch (Exception e) { JSONArray err = new JSONArray(); err.put(ExceptionUtil.toJson(e)); throw new WebApplicationException(Response .status(Status.INTERNAL_SERVER_ERROR).entity(err).build()); } } ServiceAdminResource(); @GET @Produces({ MediaType.APPLICATION_JSON }) JSONObject getServicebyID(@Context UriInfo infos); Response registerService(JSONObject serviceInfo); @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) Response registerServices(JSONArray serviceInfos); @PUT @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) Response updateServices(JSONArray serviceInfos); @DELETE Response deleteService(@Context UriInfo infos);  }### Answer:
@Test @FunctionalTest(id="ServiceRegistrationTest", description="Test registration of a service record") public void testRegisterService() throws JSONException, InterruptedException { EMIRClient cr = new EMIRClient(BaseURI + "/serviceadmin"); ClientResponse res = cr.getClientResource() .accept(MediaType.APPLICATION_JSON_TYPE) .post(ClientResponse.class, TestValueConstants.getSingleJSONArrayWithMandatoryAttributes()); JSONArray resArr = res.getEntity(JSONArray.class); assertNotNull(resArr); EMIRClient cr1 = new EMIRClient(BaseURI + "/services"); JSONArray jo = cr1.getClientResource().queryParam(ServiceBasicAttributeNames.SERVICE_ENDPOINT_ID.getAttributeName(), "1").accept(MediaType.APPLICATION_JSON_TYPE).get(JSONArray.class); assertEquals("1", jo.getJSONObject(0).get(ServiceBasicAttributeNames.SERVICE_ENDPOINT_ID .getAttributeName())); System.out.println(jo); JSONArray j = new JSONArray(); JSONObject j1 = TestValueConstants.getJSONWithMandatoryAttributes(); j1.put(ServiceBasicAttributeNames.SERVICE_ENDPOINT_ID.getAttributeName(), "2"); j.put(j1); System.out.println(j); ClientResponse cRes = cr.getClientResource() .accept(MediaType.APPLICATION_JSON_TYPE) .post(ClientResponse.class, j); if (cRes.getStatus() == Status.OK.getStatusCode()) { JSONArray resJo = cRes.getEntity(JSONArray.class); System.out.println("insert response: "+resJo); assertTrue(resJo.getJSONObject(0).getString(ServiceBasicAttributeNames.SERVICE_ENDPOINT_ID.getAttributeName()).equalsIgnoreCase("2")); JSONArray res1 = cr1.getClientResource().queryParam(ServiceBasicAttributeNames.SERVICE_ENDPOINT_ID.getAttributeName(), "2").accept(MediaType.APPLICATION_JSON_TYPE).get(JSONArray.class); assertEquals("2", res1.getJSONObject(0).get(ServiceBasicAttributeNames.SERVICE_ENDPOINT_ID .getAttributeName())); System.out.println(res1); } else { if(Status.fromStatusCode(cRes.getStatus()).compareTo(Status.CONFLICT) == 0) fail(); } }