コード例 #1
0
  @Test
  public void readTest() throws Exception {
    ItemEntityGenerator response = new ItemEntityGenerator();
    response.addItem("title", "torrentUrl", Long.MAX_VALUE, 1, 1000);

    stubFor(
        get(urlEqualTo("/?type=search&search=title"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/xml")
                    .withBody(response.toString())));

    dao.setClient(client);
    dao.setMediaType(MediaType.APPLICATION_XML_TYPE);
    dao.setBaseUri(new URI("http://localhost:8089"));

    List<FeedResult> results = dao.read("title");
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals("title", results.get(0).getTitle());
    Assert.assertEquals("torrentUrl", results.get(0).getTorrentURL());
    Assert.assertEquals(Long.MAX_VALUE, results.get(0).getContentLength());
    Assert.assertEquals(1, results.get(0).getSeeders());
    Assert.assertEquals(1000, results.get(0).getLeechers());
  }
コード例 #2
0
  @Test(expected = FeedException.class)
  public void readWebAppExceptionTest() throws Exception {

    stubFor(
        get(urlEqualTo("/?type=search&search=title"))
            .willReturn(aResponse().withStatus(500).withHeader("Content-Type", "application/xml")));

    dao.setMediaType(MediaType.APPLICATION_XML_TYPE);
    dao.setBaseUri(new URI("http://localhost:8089"));
    dao.setClient(client);

    dao.read("title");
    Assert.fail();
  }