Search in sources :

Example 21 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.

the class ExternalApiEndToEndTest method shouldAllowTorrentFileDownload.

@Test
public void shouldAllowTorrentFileDownload() throws Exception {
    replaceIndexers(Arrays.asList(IndexerConfigBuilder.builder().searchModuleType(SearchModuleType.TORZNAB).apiKey("apikey").build()));
    NewznabXmlItem result = RssItemBuilder.builder("result").category("5000").link(getMockServerBaseUrl() + "torrentlink").build();
    NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result), 0, 1);
    mockWebServer.enqueue(new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8"));
    mockWebServer.enqueue(new MockResponse().setBody("torrentcontent").setHeader("Content-Type", "application/xml; charset=utf-8"));
    String body = getStringFromUrl("http://127.0.0.1:5077/torznab/api?apikey=apikey&t=search&q=whatever");
    // Extract link
    Matcher matcher = Pattern.compile("enclosure url=\"([^\"]+)\"").matcher(body);
    assertThat(matcher.find()).isTrue();
    String link = matcher.group(1);
    // Download torrent using link
    String torrentContent = getStringFromUrl(link);
    assertThat(torrentContent).isEqualTo("torrentcontent");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Matcher(java.util.regex.Matcher) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) NzbhydraMockMvcTest(org.nzbhydra.tests.NzbhydraMockMvcTest) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest)

Example 22 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.

the class ExternalApiEndToEndTest method prepareFiveResultsFromOneIndexer.

protected void prepareFiveResultsFromOneIndexer() throws Exception {
    replaceConfig(getClass().getResource("oneIndexer.json"));
    mockWebServer.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            String mockServerBaseUrl = getMockServerBaseUrl();
            if (request.getRequestUrl().toString().contains("t=search")) {
                NewznabXmlItem result1 = RssItemBuilder.builder("result1").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink1").hasNfo(false).grabs(1).size(mbToBytes(1)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").build();
                NewznabXmlItem result2 = RssItemBuilder.builder("result2").pubDate(Instant.now().minus(2, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink2").hasNfo(false).grabs(1).size(mbToBytes(1)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result1, result2), 0, 2);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().toString().contains("nzblink1")) {
                return new MockResponse().setBody("nzbcontent1").setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().toString().contains("nzblink2")) {
                return new MockResponse().setBody("nzbcontent2").setHeader("Content-Type", "application/xml; charset=utf-8");
            } else {
                return null;
            }
        }
    });
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) NewznabAttribute(org.nzbhydra.mapping.newznab.xml.NewznabAttribute) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) ArrayList(java.util.ArrayList) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) Dispatcher(okhttp3.mockwebserver.Dispatcher)

Example 23 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.

the class ExternalApiSearchingIntegrationTest method shouldUseProvidedIdentifiers.

@Test
public void shouldUseProvidedIdentifiers() throws Exception {
    prepareIndexerWithOneResponse();
    searchModuleProvider.getIndexers().get(0).getConfig().setSupportedSearchIds(Arrays.asList(IdType.IMDB, IdType.TMDB));
    NewznabXmlRoot root = (NewznabXmlRoot) externalApi.api(NewznabParameters.builder().tmdbid("abcd").imdbid("1234").t(ActionAttribute.MOVIE).apikey("apikey").build()).getBody();
    RecordedRequest request = webServer.takeRequest(2, TimeUnit.SECONDS);
    assertThat(request.getPath()).contains("imdbid=1234").contains("tmdbid=abcd");
    assertThat(root.getRssChannel().getNewznabResponse().getTotal()).isEqualTo(1);
    assertThat(root.getRssChannel().getItems().size()).isEqualTo(1);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.

the class ExternalApiSearchingIntegrationTest method shouldCallNewznabTwice.

@Test
public void shouldCallNewznabTwice() throws Exception {
    NewznabResponseBuilder builder = new NewznabResponseBuilder();
    String xml1 = builder.getTestResult(1, 100, "indexer1", 0, 150).toXmlString();
    String xml2 = builder.getTestResult(101, 150, "indexer1", 100, 150).toXmlString();
    String xml3 = builder.getTestResult(1, 0, "indexer2", 0, 0).toXmlString();
    webServer.enqueue(new MockResponse().setBody(xml1).setHeader("Content-Type", "application/xml; charset=utf-8"));
    webServer.enqueue(new MockResponse().setBody(xml2).setHeader("Content-Type", "application/xml; charset=utf-8"));
    webServer.enqueue(new MockResponse().setBody(xml3).setHeader("Content-Type", "application/xml; charset=utf-8"));
    NewznabParameters apiCallParameters = new NewznabParameters();
    apiCallParameters.setApikey("apikey");
    apiCallParameters.setOffset(0);
    apiCallParameters.setLimit(100);
    apiCallParameters.setT(ActionAttribute.SEARCH);
    NewznabXmlRoot apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
    assertThat(apiSearchResult.getRssChannel().getItems().size()).isEqualTo(100);
    apiCallParameters.setLimit(100);
    apiCallParameters.setOffset(100);
    apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
    assertThat(apiSearchResult.getRssChannel().getItems().size()).isEqualTo(50);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabResponseBuilder(org.nzbhydra.fortests.NewznabResponseBuilder) NewznabParameters(org.nzbhydra.mapping.newznab.NewznabParameters) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.

the class NewznabResponseBuilder method getTestResult.

public NewznabXmlRoot getTestResult(int startCount, int endCount, String itemTitleBase, Integer offset, Integer total) {
    NewznabXmlRoot rssRoot = new NewznabXmlRoot();
    rssRoot.setVersion("2.0");
    NewznabXmlChannel channel = new NewznabXmlChannel();
    channel.setTitle("channelTitle");
    channel.setDescription("channelDescription");
    channel.setLanguage("en-gb");
    channel.setWebMaster("webmaster@master.com");
    channel.setLink("http://www.link.xyz");
    channel.setNewznabResponse(new NewznabXmlResponse(offset == null ? startCount - 1 : offset, total == null ? endCount : total));
    List<NewznabXmlItem> items = new ArrayList<>();
    for (int i = startCount; i <= endCount; i++) {
        NewznabXmlItem item = new NewznabXmlItem();
        item.setDescription("Some longer itemDescription that whatever" + i);
        item.setTitle(itemTitleBase + i);
        item.setPubDate(Instant.now().minus(i * 1000, ChronoUnit.HOURS));
        item.setEnclosure(new NewznabXmlEnclosure("enclosureUrl", 5L, "application/x-nzb"));
        item.setComments("http://www.comments.com/" + i);
        item.setLink("http://www.link.com/" + i);
        item.setCategory("category");
        item.setRssGuid(new NewznabXmlGuid("http://www." + itemTitleBase + ".com/" + i, true));
        List<NewznabAttribute> attributes = new ArrayList<>();
        attributes.add(new NewznabAttribute("category", "7000"));
        attributes.add(new NewznabAttribute("size", String.valueOf(random.nextInt())));
        attributes.add(new NewznabAttribute("guid", "attributeGuid" + i));
        attributes.add(new NewznabAttribute("poster", "poster"));
        attributes.add(new NewznabAttribute("group", "group"));
        item.setNewznabAttributes(attributes);
        items.add(item);
    }
    channel.setItems(items);
    rssRoot.setRssChannel(channel);
    return rssRoot;
}
Also used : NewznabXmlEnclosure(org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure) NewznabXmlGuid(org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabAttribute(org.nzbhydra.mapping.newznab.xml.NewznabAttribute) ArrayList(java.util.ArrayList) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) NewznabXmlChannel(org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel) NewznabXmlResponse(org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)

Aggregations

NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)41 Test (org.junit.Test)30 MockResponse (okhttp3.mockwebserver.MockResponse)12 NewznabXmlItem (org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)11 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)10 NewznabAttribute (org.nzbhydra.mapping.newznab.xml.NewznabAttribute)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 ArrayList (java.util.ArrayList)5 Dispatcher (okhttp3.mockwebserver.Dispatcher)4 NewznabXmlChannel (org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel)4 NzbhydraMockMvcTest (org.nzbhydra.tests.NzbhydraMockMvcTest)4 URI (java.net.URI)3 NewznabResponseBuilder (org.nzbhydra.fortests.NewznabResponseBuilder)3 NewznabParameters (org.nzbhydra.mapping.newznab.NewznabParameters)3 NewznabXmlEnclosure (org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure)3 NewznabXmlGuid (org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Matcher (java.util.regex.Matcher)2 NewznabXmlResponse (org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)2