use of org.nzbhydra.mapping.newznab.NewznabParameters 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.NewznabParameters in project nzbhydra2 by theotherp.
the class ExternalApiTest method shouldCache.
@Test
public void shouldCache() throws Exception {
NewznabParameters parameters = new NewznabParameters();
parameters.setQ("q");
parameters.setApikey("apikey");
parameters.setT(ActionAttribute.SEARCH);
parameters.setCachetime(5);
testee.api(parameters);
verify(searcher).search(any());
testee.api(parameters);
verify(searcher, times(1)).search(any());
}
use of org.nzbhydra.mapping.newznab.NewznabParameters 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.NewznabParameters 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