@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()); }
@Test public void baseUriTest() throws Exception { Assert.assertNull(dao.getBaseUri()); URI uri = new URI("http://test.com"); dao.setBaseUri(uri); Assert.assertEquals(uri, dao.getBaseUri()); }
@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(); }
@Test public void encodingTest() { Assert.assertEquals("UTF-8", dao.getEncoding()); dao.setEncoding("ENCODING"); Assert.assertEquals("ENCODING", dao.getEncoding()); }
@Test(expected = RuntimeException.class) public void readUnsupportedEncodingTest() throws Exception { dao.setEncoding("JIBBERISH"); dao.read("TITLE"); }
@Test public void feedSourceTest() throws Exception { Assert.assertNull(dao.getFeedSource()); dao.setFeedSource(FeedSource.EXTRATORRENT); Assert.assertEquals(FeedSource.EXTRATORRENT, dao.getFeedSource()); }
@Test public void mediaTypeTest() throws Exception { Assert.assertNull(dao.getMediaType()); dao.setMediaType(MediaType.APPLICATION_JSON_TYPE); Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, dao.getMediaType()); }