### Question:
CachesResource { @GET public Caches getCaches() { LOG.info("GET Caches"); String[] cacheNames = MANAGER.getCacheNames(); List<Cache> cacheList = new ArrayList<Cache>(); for (String cacheName : cacheNames) { Ehcache ehcache = MANAGER.getCache(cacheName); URI cacheUri = uriInfo.getAbsolutePathBuilder().path(cacheName).build().normalize(); Cache cache = new Cache(cacheName, cacheUri.toString(), ehcache.toString(), new Statistics(ehcache.getStatistics()), ehcache.getCacheConfiguration()); cacheList.add(cache); } return new Caches(cacheList); }  @Path("{cache}") CacheResource getCacheResource(@PathParam("cache") String cache); @GET Caches getCaches();  }### Answer:
@Test public void testCacheNames() throws Exception { HttpURLConnection result = HttpUtil.get("http: assertEquals(200, result.getResponseCode()); JAXBContext jaxbContext = new JAXBContextResolver().getContext(Caches.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Caches caches = (Caches) unmarshaller.unmarshal(result.getInputStream()); List<net.sf.ehcache.server.jaxb.Cache> cacheList = caches.getCaches(); for (net.sf.ehcache.server.jaxb.Cache cache : cacheList) { assertNotNull(cache.getName()); } }
@Test public void testGetCaches() throws Exception { HttpURLConnection result = HttpUtil.get("http: assertEquals(200, result.getResponseCode()); DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = documentBuilder.parse(result.getInputStream()); XPath xpath = XPathFactory.newInstance().newXPath(); String cacheCount = xpath.evaluate("count( assertTrue(Integer.parseInt(cacheCount) >= 6); }
@Test public void testGetCachesJaxb() throws Exception { HttpURLConnection result = HttpUtil.get("http: assertEquals(200, result.getResponseCode()); JAXBContext jaxbContext = new JAXBContextResolver().getContext(Caches.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Caches caches = (Caches) unmarshaller.unmarshal(result.getInputStream()); assertTrue(caches.getCaches().size() >= 6); }
@Test public void testCacheNames() throws Exception, IOException, ParserConfigurationException, SAXException { HttpURLConnection result = HttpUtil.get("http: assertEquals(200, result.getResponseCode()); JAXBContext jaxbContext = new JAXBContextResolver().getContext(Caches.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Caches caches = (Caches) unmarshaller.unmarshal(result.getInputStream()); List<net.sf.ehcache.server.jaxb.Cache> cacheList = caches.getCaches(); for (net.sf.ehcache.server.jaxb.Cache cache : cacheList) { assertNotNull(cache.getName()); } }
@Test public void testGetCaches() throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { HttpURLConnection result = HttpUtil.get("http: assertEquals(200, result.getResponseCode()); DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = documentBuilder.parse(result.getInputStream()); XPath xpath = XPathFactory.newInstance().newXPath(); String cacheCount = xpath.evaluate("count( assertTrue(Integer.parseInt(cacheCount) >= 6); }
@Test public void testGetCachesJaxb() throws Exception, SAXException, XPathExpressionException, JAXBException { HttpURLConnection result = HttpUtil.get("http: assertEquals(200, result.getResponseCode()); JAXBContext jaxbContext = new JAXBContextResolver().getContext(Caches.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Caches caches = (Caches) unmarshaller.unmarshal(result.getInputStream()); assertTrue(caches.getCaches().size() >= 6); }