Search in sources :

Example 26 with NewznabXmlRoot

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

the class ExternalApiTest method shouldUseCorrectHeaders.

@Test
public void shouldUseCorrectHeaders() throws Exception {
    NewznabJsonRoot jsonRoot = new NewznabJsonRoot();
    when(newznabJsonTransformerMock.transformToRoot(any(), any(), anyInt(), any())).thenReturn(jsonRoot);
    NewznabParameters parameters = new NewznabParameters();
    parameters.setQ("q1");
    parameters.setApikey("apikey");
    parameters.setT(ActionAttribute.SEARCH);
    parameters.setO(OutputType.JSON);
    ResponseEntity<?> responseEntity = testee.api(parameters);
    assertThat(responseEntity.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON_UTF8);
    NewznabXmlRoot xmlRoot = new NewznabXmlRoot();
    when(newznabXmlTransformerMock.getRssRoot(any(), any(), anyInt(), any())).thenReturn(xmlRoot);
    parameters.setO(OutputType.XML);
    responseEntity = testee.api(parameters);
    assertThat(responseEntity.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_XML);
}
Also used : NewznabJsonRoot(org.nzbhydra.mapping.newznab.json.NewznabJsonRoot) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabParameters(org.nzbhydra.mapping.newznab.NewznabParameters) Test(org.junit.Test)

Example 27 with NewznabXmlRoot

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

the class ExternalApiSearchingIntegrationTest method shouldCallIndexerWithMoreResultsASecondTime.

@Test
public void shouldCallIndexerWithMoreResultsASecondTime() throws Exception {
    NewznabResponseBuilder builder = new NewznabResponseBuilder();
    String xml1 = builder.getTestResult(1, 2, "indexer1", 0, 3).toXmlString();
    String xml2 = builder.getTestResult(3, 3, "indexer1", 2, 3).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.setOffset(0);
    apiCallParameters.setLimit(2);
    apiCallParameters.setT(ActionAttribute.SEARCH);
    NewznabXmlRoot apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
    org.assertj.core.api.Assertions.assertThat(apiSearchResult.getRssChannel().getItems().size()).isEqualTo(2);
    apiCallParameters.setLimit(100);
    apiCallParameters.setOffset(2);
    apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
    org.assertj.core.api.Assertions.assertThat(apiSearchResult.getRssChannel().getItems().size()).isEqualTo(1);
    org.assertj.core.api.Assertions.assertThat(apiSearchResult.getRssChannel().getItems().get(0).getTitle()).isEqualTo("indexer13");
}
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 28 with NewznabXmlRoot

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

the class ExternalApiSearchingIntegrationTest method shouldGenerateQuery.

@Test
public void shouldGenerateQuery() throws Exception {
    prepareIndexerWithOneResponse();
    configProvider.getBaseConfig().getSearching().setGenerateQueries(SearchSourceRestriction.API);
    searchModuleProvider.getIndexers().get(0).getConfig().setSupportedSearchIds(Collections.emptyList());
    when(infoProvider.convert(anyMap())).thenReturn(new MediaInfo(new MovieInfo(null, null, "title", 0, null)));
    when(infoProvider.convert(any(), any())).thenReturn(new MediaInfo(new MovieInfo(null, null, "title", 0, null)));
    when(infoProvider.canConvertAny(anySet(), anySet())).thenReturn(false);
    NewznabXmlRoot root = (NewznabXmlRoot) externalApi.api(NewznabParameters.builder().tmdbid("abcd").t(ActionAttribute.MOVIE).apikey("apikey").build()).getBody();
    RecordedRequest request = webServer.takeRequest(2, TimeUnit.SECONDS);
    assertThat(request.getRequestUrl().queryParameter("q")).isEqualTo("title");
    assertThat(root.getRssChannel().getNewznabResponse().getTotal()).isEqualTo(1);
    assertThat(root.getRssChannel().getItems().size()).isEqualTo(1);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) MovieInfo(org.nzbhydra.mediainfo.MovieInfo) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 29 with NewznabXmlRoot

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

the class ExternalApiSearchingIntegrationTest method prepareIndexerWithOneResponse.

protected void prepareIndexerWithOneResponse() throws IOException {
    replaceConfig(getClass().getResource("oneIndexer.json"));
    NewznabXmlRoot response = NewznabMockBuilder.generateResponse(NewznabMockRequest.builder().total(1).offset(0).numberOfResults(1).build());
    webServer.enqueue(new MockResponse().setBody(response.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8"));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)

Example 30 with NewznabXmlRoot

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

the class ExternalApiSearchingIntegrationTest method shouldSearch.

@Test
public void shouldSearch() throws Exception {
    String expectedContent1a = Resources.toString(Resources.getResource(ExternalApiSearchingIntegrationTest.class, "simplesearchresult1a.xml"), Charsets.UTF_8);
    String expectedContent1b = Resources.toString(Resources.getResource(ExternalApiSearchingIntegrationTest.class, "simplesearchresult1b.xml"), Charsets.UTF_8);
    String expectedContent2 = Resources.toString(Resources.getResource(ExternalApiSearchingIntegrationTest.class, "simplesearchresult2.xml"), Charsets.UTF_8);
    webServer.enqueue(new MockResponse().setBody(expectedContent1a).setHeader("Content-Type", "application/xml; charset=utf-8"));
    webServer.enqueue(new MockResponse().setBody(expectedContent2).setHeader("Content-Type", "application/xml; charset=utf-8"));
    webServer.enqueue(new MockResponse().setBody(expectedContent1b).setHeader("Content-Type", "application/xml; charset=utf-8"));
    NewznabParameters apiCallParameters = new NewznabParameters();
    apiCallParameters.setApikey("apikey");
    apiCallParameters.setOffset(0);
    apiCallParameters.setLimit(2);
    apiCallParameters.setT(ActionAttribute.SEARCH);
    NewznabXmlRoot apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
    Assert.assertThat(apiSearchResult.getRssChannel().getItems().size(), is(2));
    Assert.assertThat(apiSearchResult.getRssChannel().getItems().get(0).getTitle(), is("itemTitle1a"));
    Assert.assertThat(apiSearchResult.getRssChannel().getItems().get(1).getTitle(), is("itemTitle2"));
    apiCallParameters.setLimit(100);
    apiCallParameters.setOffset(2);
    apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
    Assert.assertThat(apiSearchResult.getRssChannel().getItems().size(), is(1));
    Assert.assertThat(apiSearchResult.getRssChannel().getItems().get(0).getTitle(), is("itemTitle1b"));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabParameters(org.nzbhydra.mapping.newznab.NewznabParameters) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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