Search in sources :

Example 6 with NewznabParameters

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);
}
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 7 with NewznabParameters

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());
}
Also used : NewznabParameters(org.nzbhydra.mapping.newznab.NewznabParameters) Test(org.junit.Test)

Example 8 with NewznabParameters

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");
}
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 9 with NewznabParameters

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

NewznabParameters (org.nzbhydra.mapping.newznab.NewznabParameters)9 Test (org.junit.Test)7 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)4 MockResponse (okhttp3.mockwebserver.MockResponse)3 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)3 NewznabResponseBuilder (org.nzbhydra.fortests.NewznabResponseBuilder)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Stopwatch (com.google.common.base.Stopwatch)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 Stream (java.util.stream.Stream)1 AllArgsConstructor (lombok.AllArgsConstructor)1