### Question:
CacheImageRest extends AbstractRest { @GET @Produces(MediaType.APPLICATION_XML) public Response getCacheImagesForApplication(@PathParam("application_name") String applicationName) { logger.info("GET request to paht: /applications/" + applicationName + "/cache-images"); Application application = applicationDAO.getByName(applicationName); List<Image> images = imageDAO.getCacheImagesForApplication(application); String xml = XMLBuilder.getCollectionOfCacheImagesXML(images, applicationName); return buildResponse(Status.OK, xml); }  @GET @Produces(MediaType.APPLICATION_XML) Response getCacheImagesForApplication(@PathParam("application_name") String applicationName); @DELETE @Path("{image_id}") Response deleteCacheImage(@PathParam("application_name") String applicationName, @PathParam("image_id") String imageId);  }### Answer:
@Test public void getImagesTest() throws Exception { ImageDAO imageDAO = mock(ImageDAO.class); ApplicationDAO applicationDAO = mock(ApplicationDAO.class); CacheImageRest cacheImageRest = new CacheImageRest(); cacheImageRest.applicationDAO = applicationDAO; cacheImageRest.imageDAO = imageDAO; Application application = new Application(); application.setName("applicationName"); when(applicationDAO.getByName("applicationName")).thenReturn(application); Image image1 = new Image(); image1.setApplication(application); image1.setDemo(true); image1.setId(1); image1.setOvfHref("ovf-href-1"); image1.setOvfId("ovf-id1"); image1.setProviderImageId("uuid1"); Image image2 = new Image(); image2.setApplication(application); image2.setDemo(true); image2.setId(2); image2.setOvfHref("ovf-href-2"); image2.setOvfId("ovf-id2"); image2.setProviderImageId("uuid2"); List<Image> images = new ArrayList<Image>(); images.add(image1); images.add(image2); when(imageDAO.getCacheImagesForApplication(application)).thenReturn(images); Response response = cacheImageRest.getCacheImagesForApplication("applicationName"); assertEquals(200, response.getStatus()); String xml = (String) response.getEntity(); JAXBContext jaxbContext = JAXBContext.newInstance(Collection.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Collection collection = (Collection) jaxbUnmarshaller.unmarshal(new StringReader(xml)); assertEquals("/applications/applicationName/cache-images", collection.getHref()); assertEquals(0, collection.getItems().getOffset()); assertEquals(2, collection.getItems().getTotal()); assertEquals(2, collection.getItems().getImages().size()); image1 = collection.getItems().getImages().get(0); assertEquals("/applications/applicationName/cache-images/1", image1.getHref()); assertEquals(1, image1.getId()); assertEquals("ovf-href-1", image1.getOvfHref()); assertEquals("ovf-id1", image1.getOvfId()); assertEquals("uuid1", image1.getProviderImageId()); image2 = collection.getItems().getImages().get(1); assertEquals("/applications/applicationName/cache-images/2", image2.getHref()); assertEquals(2, image2.getId()); assertEquals("ovf-href-2", image2.getOvfHref()); assertEquals("ovf-id2", image2.getOvfId()); assertEquals("uuid2", image2.getProviderImageId()); }