### Question:
SchemaService extends RestService { private Response getSchema(String name) { Schema schema = repos.getSchema(name); if (schema != null) { try { return Response.ok(schema).build(); } catch (Exception ex) { logger.error("getSchema.error", ex); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } } return Response.status(Response.Status.NOT_FOUND).entity("No Schema found for name: " + name).build(); }  @GET @Produces(MediaType.APPLICATION_JSON) //TEXT_PLAIN) @ApiOperation(value = "getSchemas: return Schema names accessible in the current session") Collection<String> getSchemas(); @GET @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "getSchemaAsJSON: return Schema settings in JSON format") Response getSchemaAsJSON(@PathParam("name") String name); @GET @Path("/{name}") @Produces(MediaType.APPLICATION_XML) @ApiOperation(value = "getSchemaAsXML: return Schema settings in XML format") Response getSchemaAsXML(@PathParam("name") String name);  }### Answer:
@Test public void testSchemasJson() throws Exception { Collection<String> response1 = new ArrayList<>(); response1.add("default"); response1.add("TPoX"); response1.add("XMark"); when(mockPro.getSchemaNames()).thenReturn(response1); Response resp = target("schemas").request(MediaType.APPLICATION_JSON) .cookie(bg_cookie, "client-id") .get(Response.class); assertEquals(200, resp.getStatus()); String body = resp.readEntity(String.class); TreeNode treeNode = jsonFactory.createParser(body).readValueAsTree(); assertTrue(treeNode.isArray()); assertEquals(3, treeNode.size()); assertEquals("\"default\"", treeNode.get(0).toString()); assertEquals("\"TPoX\"", treeNode.get(1).toString()); assertEquals("\"XMark\"", treeNode.get(2).toString()); when(mockPro.getSchema("default")).thenReturn( new Schema(1, new Date(), "admin", "default", "default schema for test and demo purpose", true, null)); body = target("schemas").path("default") .request(MediaType.APPLICATION_JSON) .cookie(bg_cookie, "client-id") .get(String.class); assertNotNull(body); treeNode = jsonFactory.createParser(body).readValueAsTree(); assertEquals("\"admin\"", treeNode.get("createdBy").toString()); when(mockPro.getSchema("TPoX")).thenReturn( new Schema(1, new Date(), "admin", "TPoX", "TPoX: schema for TPoX-related tests", false, null)); body = target("schemas/TPoX").request(MediaType.APPLICATION_JSON) .cookie(bg_cookie, "client-id") .get(String.class); assertNotNull(body); treeNode = jsonFactory.createParser(body).readValueAsTree(); assertEquals("\"admin\"", treeNode.get("createdBy").toString()); when(mockPro.getSchema("XMark")).thenReturn( new Schema(1, new Date(), "admin", "XMark", "XMark benchmark schema", false, null)); body = target("schemas/XMark").request(MediaType.APPLICATION_JSON) .cookie(bg_cookie, "client-id") .get(String.class); assertNotNull(body); treeNode = jsonFactory.createParser(body).readValueAsTree(); assertEquals("\"admin\"", treeNode.get("createdBy").toString()); }