Search in sources :

Example 16 with NewznabXmlRoot

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

the class SearchingResultsUiTest method prepareFiveResultsFromTwoIndexers.

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

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            int mockServerPort = mockWebServer.getPort();
            String mockServerBaseUrl = "http://127.0.0.1:" + mockServerPort + "/";
            if (request.getRequestUrl().queryParameter("apikey") != null && request.getRequestUrl().queryParameter("apikey").equals("apikey1")) {
                NewznabXmlItem result1 = RssItemBuilder.builder("indexer1-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("indexer1-result2").pubDate(Instant.now().minus(2, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink2").hasNfo(true).grabs(2).size(mbToBytes(2)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5040")))).category("TV SD").build();
                NewznabXmlItem result3 = RssItemBuilder.builder("indexer1-result3").pubDate(Instant.now().minus(3, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink3").comments("comments").grabs(3).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5030")))).category("TV HD").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result1, result2, result3), 0, 3);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().queryParameter("apikey") != null && request.getRequestUrl().queryParameter("apikey").equals("apikey2")) {
                NewznabXmlItem result5 = RssItemBuilder.builder("indexer2-result2").pubDate(Instant.now().minus(5, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink5").grabs(5).size(mbToBytes(5)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "2040")))).category("Movies HD").build();
                NewznabXmlItem result4 = RssItemBuilder.builder("indexer2-result1").pubDate(Instant.now().minus(4, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink4").grabs(4).size(mbToBytes(4)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "2000")))).category("Movies").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result4, result5), 0, 2);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getPath().endsWith("nzbzip")) {
                System.out.println("Returning NZB ZIP response");
                String body = request.getBody().readString(Charset.defaultCharset());
                ObjectMapper objectMapper = new ObjectMapper();
                try {
                    List<Long> ids = objectMapper.readValue(body, new TypeReference<List<Long>>() {
                    });
                    FileZipResponse response = new FileZipResponse(true, "bla", null, ids, Collections.emptyList());
                    return new MockResponse().setBody(objectMapper.writeValueAsString(response)).setHeader("Content-Type", "application/xml; charset=utf-8");
                } catch (IOException e) {
                }
                throw new RuntimeException("Unable to handle nzbzip");
            } else if (request.getPath().contains("nzblink")) {
                System.out.println("Returning NZB");
                return new MockResponse().setBody("nzb").setHeader("Content-Type", "application/x-nzb; charset=utf-8");
            } else {
                throw new RuntimeException("Unexpected api key " + request.getRequestUrl().queryParameter("apikey"));
            }
        }
    });
}
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) IOException(java.io.IOException) Dispatcher(okhttp3.mockwebserver.Dispatcher) ArrayList(java.util.ArrayList) List(java.util.List) FileZipResponse(org.nzbhydra.downloading.FileZipResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 17 with NewznabXmlRoot

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

the class SearchingResultsUiTest method prepareDuplicateAndTitleGroupedResults.

protected void prepareDuplicateAndTitleGroupedResults() throws IOException {
    replaceConfig(getClass().getResource("twoIndexers.json"));
    mockWebServer.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            if (request.getRequestUrl().queryParameter("apikey").equals("apikey1")) {
                NewznabXmlItem duplicate = RssItemBuilder.builder("duplicate").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).hasNfo(false).grabs(1).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").link("link1").build();
                NewznabXmlItem result2 = RssItemBuilder.builder("grouptitle").pubDate(Instant.now().minus(2, ChronoUnit.DAYS)).hasNfo(true).grabs(2).size(mbToBytes(2)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5040")))).category("TV SD").link("link2").build();
                NewznabXmlItem result3 = RssItemBuilder.builder("grouptitle").pubDate(Instant.now().minus(3, ChronoUnit.DAYS)).comments("comments").grabs(3).size(mbToBytes(1)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5030")))).category("TV HD").link("link3").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(duplicate, result2, result3), 0, 3);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().queryParameter("apikey").equals("apikey2")) {
                NewznabXmlItem duplicate = RssItemBuilder.builder("duplicate").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).hasNfo(false).grabs(1).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").link("link4").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(duplicate), 0, 1);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else {
                throw new RuntimeException("Unexpected api key " + request.getRequestUrl().queryParameter("apikey"));
            }
        }
    });
}
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 18 with NewznabXmlRoot

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

the class SearchingResultsUiTest method testMessageIfAllResultsRejected.

@Test
public void testMessageIfAllResultsRejected() throws Exception {
    replaceIndexers(Arrays.asList(IndexerConfigBuilder.builder().build()));
    baseConfig.getSearching().setRequiredWords(Collections.singletonList("not in there"));
    baseConfig.getSearching().setApplyRestrictions(SearchSourceRestriction.INTERNAL);
    replaceConfig(baseConfig);
    NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(RssItemBuilder.builder("someresult").build()), 0, 1);
    mockWebServer.enqueue(new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8"));
    webDriver.get(url + "/?category=All&query=uitest&mode=search");
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("no-search-results")));
    SearchResultsPO searchResultsPage = factory.createPage(SearchResultsPO.class);
    assertThat(searchResultsPage.noSearchResultsWarning().text()).isEqualTo("No (non-rejected) results were found for this search");
    assertThat(webDriver.findElements(By.className("search-results-table")).isEmpty()).isTrue();
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) NzbhydraMockMvcTest(org.nzbhydra.tests.NzbhydraMockMvcTest) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest)

Example 19 with NewznabXmlRoot

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

the class ExternalApiEndToEndTest method prepareDuplicateAndTitleGroupedResults.

protected void prepareDuplicateAndTitleGroupedResults() throws IOException {
    replaceConfig(getClass().getResource("twoIndexers.json"));
    mockWebServer.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            if (request.getRequestUrl().queryParameter("apikey").equals("apikey1")) {
                NewznabXmlItem duplicate = RssItemBuilder.builder("duplicate").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).hasNfo(false).grabs(1).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").link("link1").build();
                NewznabXmlItem result2 = RssItemBuilder.builder("grouptitle").pubDate(Instant.now().minus(2, ChronoUnit.DAYS)).hasNfo(true).grabs(2).size(mbToBytes(2)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5040")))).category("TV SD").link("link2").build();
                NewznabXmlItem result3 = RssItemBuilder.builder("grouptitle").pubDate(Instant.now().minus(3, ChronoUnit.DAYS)).comments("comments").grabs(3).size(mbToBytes(1)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5030")))).category("TV HD").link("link3").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(duplicate, result2, result3), 0, 3);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().queryParameter("apikey").equals("apikey2")) {
                NewznabXmlItem duplicate = RssItemBuilder.builder("duplicate").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).hasNfo(false).grabs(1).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").link("link4").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(duplicate), 0, 1);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else {
                throw new RuntimeException("Unexpected api key " + request.getRequestUrl().queryParameter("apikey"));
            }
        }
    });
}
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 20 with NewznabXmlRoot

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

the class ExternalApiEndToEndTest method shouldAllowMagnetLinkDownload.

@Test
public void shouldAllowMagnetLinkDownload() throws Exception {
    replaceIndexers(Arrays.asList(IndexerConfigBuilder.builder().searchModuleType(SearchModuleType.TORZNAB).apiKey("apikey").build()));
    NewznabXmlItem result = RssItemBuilder.builder("result").category("5000").link("magnet:x&dn=y").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);
    Response response = new OkHttpClient.Builder().build().newCall(new Request.Builder().url(link).build()).execute();
    assertThat(response.code()).isEqualTo(302);
    assertThat(response.header("Location")).isEqualTo("magnet:x&dn=y");
}
Also used : Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) OkHttpClient(okhttp3.OkHttpClient) Matcher(java.util.regex.Matcher) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabMockBuilder(org.nzbhydra.mapping.newznab.mock.NewznabMockBuilder) RssItemBuilder(org.nzbhydra.mapping.newznab.builder.RssItemBuilder) IndexerConfigBuilder(org.nzbhydra.config.IndexerConfigBuilder) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) NzbhydraMockMvcTest(org.nzbhydra.tests.NzbhydraMockMvcTest) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest)

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