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

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

    ObjectMapper mapper = new ObjectMapper();
    Chapters chapters = mapper.readValue(content, Chapters.class);

    assertEquals(new Integer(50), chapters.getSize());
    assertEquals(MAX_ELEMENTS_BY_QUERY, chapters.getChapters().size());
  }
コード例 #2
0
  @Test
  public void testGetChaptersAsXml() throws JAXBException {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(AppHelper.getServiceUrl("chapters"));

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

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

    assertEquals(new Integer(50), chapters.getSize());
    assertEquals(MAX_ELEMENTS_BY_QUERY, chapters.getChapters().size());
  }
コード例 #3
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());
  }
コード例 #4
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());
  }