コード例 #1
0
  @Test
  public void testGetChapterAsJson() throws JsonParseException, JsonMappingException, IOException {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(AppHelper.getServiceUrl("chapters/1"));

    String content = target.request(MediaType.APPLICATION_JSON).get(String.class);
    client.close();

    ObjectMapper mapper = new ObjectMapper();
    Chapter chapter = mapper.readValue(content, Chapter.class);

    assertEquals(new Integer(1), chapter.getChapterId());
    assertEquals(new Integer(1), chapter.getBookId());
    assertEquals("1", chapter.getNumber());
  }
コード例 #2
0
  @Test
  public void testGetChapterAsXml() throws JAXBException {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(AppHelper.getServiceUrl("chapters/1"));

    String content = target.request(MediaType.APPLICATION_XML).get(String.class);
    client.close();

    Unmarshaller u = JAXBContext.newInstance(Chapters.class).createUnmarshaller();
    Chapter chapter = (Chapter) u.unmarshal(new StringReader(content));

    assertEquals(new Integer(1), chapter.getChapterId());
    assertEquals(new Integer(1), chapter.getBookId());
    assertEquals("1", chapter.getNumber());
  }