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);
}
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");
}
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);
}
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"));
}
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"));
}
Aggregations