@Test public void getProvidersTest() throws Exception { ProviderAPI providerAPI = new ProviderAPI(); providerAPI.providerDAO = providerDAO; Response response = providerAPI.getProviders(); assertEquals(200, response.getStatus()); String providersXML = (String) response.getEntity(); JAXBContext jaxbContext = JAXBContext.newInstance(Collection.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Collection collection = (Collection) jaxbUnmarshaller.unmarshal(new StringReader(providersXML)); assertEquals("/", collection.getHref()); assertEquals(1, collection.getLinks().size()); assertEquals("self", collection.getLinks().get(0).getRel()); assertEquals(CONTENT_TYPE_XML, collection.getLinks().get(0).getType()); assertEquals("/", collection.getLinks().get(0).getHref()); assertEquals(0, collection.getItems().getOffset()); assertEquals(2, collection.getItems().getTotal()); assertEquals("Provider 1", collection.getItems().getProviders().get(0).getName()); assertEquals("http: assertEquals(2, collection.getItems().getProviders().get(0).getLinks().size()); assertEquals("Provider 2", collection.getItems().getProviders().get(1).getName()); assertEquals("http: assertEquals(2, collection.getItems().getProviders().get(1).getLinks().size()); assertEquals("self", collection.getItems().getProviders().get(0).getLinks().get(1).getRel()); assertEquals(CONTENT_TYPE_XML, collection.getItems().getProviders().get(0).getLinks().get(1).getType()); assertEquals("parent", collection.getItems().getProviders().get(0).getLinks().get(0).getRel()); assertEquals(CONTENT_TYPE_XML, collection.getItems().getProviders().get(0).getLinks().get(0).getType()); assertEquals("/", collection.getItems().getProviders().get(0).getLinks().get(0).getHref()); assertEquals("self", collection.getItems().getProviders().get(1).getLinks().get(1).getRel()); assertEquals(CONTENT_TYPE_XML, collection.getItems().getProviders().get(0).getLinks().get(1).getType()); assertEquals("parent", collection.getItems().getProviders().get(1).getLinks().get(0).getRel()); assertEquals(CONTENT_TYPE_XML, collection.getItems().getProviders().get(1).getLinks().get(0).getType()); assertEquals("/", collection.getItems().getProviders().get(1).getLinks().get(0).getHref()); }
@GET @Path("/") @Produces(CONTENT_TYPE_XML + ";qs=1") public Response getProviders() { logger.info("GET / [XML]"); String xmlRepresentation = Converter.getRootCollectionXML(getProvidersFromDB()); logger.debug("RESPONSE: " + xmlRepresentation); return buildResponse(Status.OK, xmlRepresentation); }
ProviderAPI extends RestAbstract { @GET @Path("/") @Produces(CONTENT_TYPE_XML + ";qs=1") public Response getProviders() { logger.info("GET / [XML]"); String xmlRepresentation = Converter.getRootCollectionXML(getProvidersFromDB()); logger.debug("RESPONSE: " + xmlRepresentation); return buildResponse(Status.OK, xmlRepresentation); } }
ProviderAPI extends RestAbstract { @GET @Path("/") @Produces(CONTENT_TYPE_XML + ";qs=1") public Response getProviders() { logger.info("GET / [XML]"); String xmlRepresentation = Converter.getRootCollectionXML(getProvidersFromDB()); logger.debug("RESPONSE: " + xmlRepresentation); return buildResponse(Status.OK, xmlRepresentation); }  }
ProviderAPI extends RestAbstract { @GET @Path("/") @Produces(CONTENT_TYPE_XML + ";qs=1") public Response getProviders() { logger.info("GET / [XML]"); String xmlRepresentation = Converter.getRootCollectionXML(getProvidersFromDB()); logger.debug("RESPONSE: " + xmlRepresentation); return buildResponse(Status.OK, xmlRepresentation); }  @GET @Path("/") @Produces(CONTENT_TYPE_XML + ";qs=1") Response getProviders(); @GET @Path("/") @Produces(CONTENT_TYPE_JSON + ";qs=.5") Response getProvidersJSON(); @GET @Path("/{id}") @Produces(CONTENT_TYPE_XML + ";qs=1") Response getProvider(@PathParam("id") int id); @GET @Path("/{id}") @Produces(CONTENT_TYPE_JSON + ";qs=.5") Response getProviderJSON(@PathParam("id") int id); @POST @Path("/") @Consumes(CONTENT_TYPE_XML) @Produces(CONTENT_TYPE_XML) Response postProvider(String payload); @DELETE @Path("/{id}") Response deleteProvider(@PathParam("id") int id); @PUT @Path("/{id}") @Consumes(CONTENT_TYPE_XML) @Produces(CONTENT_TYPE_XML) Response putProvider(@PathParam("id") int id, String payload); }
ProviderAPI extends RestAbstract { @GET @Path("/") @Produces(CONTENT_TYPE_XML + ";qs=1") public Response getProviders() { logger.info("GET / [XML]"); String xmlRepresentation = Converter.getRootCollectionXML(getProvidersFromDB()); logger.debug("RESPONSE: " + xmlRepresentation); return buildResponse(Status.OK, xmlRepresentation); }  @GET @Path("/") @Produces(CONTENT_TYPE_XML + ";qs=1") Response getProviders(); @GET @Path("/") @Produces(CONTENT_TYPE_JSON + ";qs=.5") Response getProvidersJSON(); @GET @Path("/{id}") @Produces(CONTENT_TYPE_XML + ";qs=1") Response getProvider(@PathParam("id") int id); @GET @Path("/{id}") @Produces(CONTENT_TYPE_JSON + ";qs=.5") Response getProviderJSON(@PathParam("id") int id); @POST @Path("/") @Consumes(CONTENT_TYPE_XML) @Produces(CONTENT_TYPE_XML) Response postProvider(String payload); @DELETE @Path("/{id}") Response deleteProvider(@PathParam("id") int id); @PUT @Path("/{id}") @Consumes(CONTENT_TYPE_XML) @Produces(CONTENT_TYPE_XML) Response putProvider(@PathParam("id") int id, String payload);  }