Search in sources :

Example 1 with NewznabResponseBuilder

use of org.nzbhydra.fortests.NewznabResponseBuilder in project nzbhydra2 by theotherp.

the class NewznabCheckerTest method shouldCheckCapsWithoutSupport.

@Test
public void shouldCheckCapsWithoutSupport() throws Exception {
    NewznabResponseBuilder builder = new NewznabResponseBuilder();
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&tvdbid=121361"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "somethingElse", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&rid=24493"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "somethingElse", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&tvmazeid=82"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "somethingElse", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&traktid=1390"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "somethingElse", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=movie&tmdbid=1399"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "somethingElse", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=movie&imdbid=0848228"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "somethingElse", 0, 100));
    CheckCapsResponse checkCapsRespone = testee.checkCaps(indexerConfig);
    assertEquals(0, checkCapsRespone.getIndexerConfig().getSupportedSearchIds().size());
    verify(indexerWebAccess, times(7)).get(any(), eq(indexerConfig));
}
Also used : NewznabResponseBuilder(org.nzbhydra.fortests.NewznabResponseBuilder) URI(java.net.URI) BinsearchTest(org.nzbhydra.indexers.BinsearchTest) Test(org.junit.Test)

Example 2 with NewznabResponseBuilder

use of org.nzbhydra.fortests.NewznabResponseBuilder in project nzbhydra2 by theotherp.

the class NewznabCheckerTest method shouldCheckCaps.

@Test
public void shouldCheckCaps() throws Exception {
    NewznabResponseBuilder builder = new NewznabResponseBuilder();
    NewznabXmlRoot thronesResult = builder.getTestResult(1, 100, "Thrones", 0, 100);
    thronesResult.getRssChannel().setGenerator("nzedb");
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&tvdbid=121361"), indexerConfig)).thenReturn(thronesResult);
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&rid=24493"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "Thrones", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&tvmazeid=82"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "Thrones", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&traktid=1390"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "GOT", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=movie&tmdbid=1399"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "Avengers", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=movie&imdbid=0848228"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "Avengers", 0, 100));
    capsRoot.getSearching().setAudioSearch(new CapsSearch("yes", "q"));
    CheckCapsResponse checkCapsRespone = testee.checkCaps(indexerConfig);
    assertEquals(6, checkCapsRespone.getIndexerConfig().getSupportedSearchIds().size());
    assertTrue(checkCapsRespone.getIndexerConfig().getSupportedSearchIds().contains(TVDB));
    assertTrue(checkCapsRespone.getIndexerConfig().getSupportedSearchIds().contains(TVRAGE));
    assertTrue(checkCapsRespone.getIndexerConfig().getSupportedSearchIds().contains(TVMAZE));
    assertTrue(checkCapsRespone.getIndexerConfig().getSupportedSearchIds().contains(TRAKT));
    assertTrue(checkCapsRespone.getIndexerConfig().getSupportedSearchIds().contains(IMDB));
    assertTrue(checkCapsRespone.getIndexerConfig().getSupportedSearchIds().contains(TMDB));
    assertEquals(3, checkCapsRespone.getIndexerConfig().getSupportedSearchTypes().size());
    assertTrue(checkCapsRespone.getIndexerConfig().getSupportedSearchTypes().contains(ActionAttribute.AUDIO));
    assertTrue(checkCapsRespone.getIndexerConfig().getSupportedSearchTypes().contains(ActionAttribute.TVSEARCH));
    assertTrue(checkCapsRespone.getIndexerConfig().getSupportedSearchTypes().contains(ActionAttribute.MOVIE));
    assertEquals(BackendType.NZEDB, checkCapsRespone.getIndexerConfig().getBackend());
    assertTrue(checkCapsRespone.isAllCapsChecked());
    verify(indexerWebAccess, times(7)).get(any(), eq(indexerConfig));
}
Also used : NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabResponseBuilder(org.nzbhydra.fortests.NewznabResponseBuilder) URI(java.net.URI) CapsSearch(org.nzbhydra.mapping.newznab.caps.CapsSearch) BinsearchTest(org.nzbhydra.indexers.BinsearchTest) Test(org.junit.Test)

Example 3 with NewznabResponseBuilder

use of org.nzbhydra.fortests.NewznabResponseBuilder in project nzbhydra2 by theotherp.

the class ExternalApiSearchingIntegrationTest method shouldCallNewznabTwice.

@Test
public void shouldCallNewznabTwice() throws Exception {
    NewznabResponseBuilder builder = new NewznabResponseBuilder();
    String xml1 = builder.getTestResult(1, 100, "indexer1", 0, 150).toXmlString();
    String xml2 = builder.getTestResult(101, 150, "indexer1", 100, 150).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.setApikey("apikey");
    apiCallParameters.setOffset(0);
    apiCallParameters.setLimit(100);
    apiCallParameters.setT(ActionAttribute.SEARCH);
    NewznabXmlRoot apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
    assertThat(apiSearchResult.getRssChannel().getItems().size()).isEqualTo(100);
    apiCallParameters.setLimit(100);
    apiCallParameters.setOffset(100);
    apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
    assertThat(apiSearchResult.getRssChannel().getItems().size()).isEqualTo(50);
}
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 4 with NewznabResponseBuilder

use of org.nzbhydra.fortests.NewznabResponseBuilder 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 5 with NewznabResponseBuilder

use of org.nzbhydra.fortests.NewznabResponseBuilder in project nzbhydra2 by theotherp.

the class NewznabCheckerTest method shouldSaySoIfNotAllWereChecked.

@Test
public void shouldSaySoIfNotAllWereChecked() throws Exception {
    NewznabResponseBuilder builder = new NewznabResponseBuilder();
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&tvdbid=121361"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "Thrones", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&rid=24493"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "Thrones", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&tvmazeid=82"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "Thrones", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=tvsearch&traktid=1390"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "Thrones", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=movie&tmdbid=1399"), indexerConfig)).thenReturn(builder.getTestResult(1, 100, "Avengers", 0, 100));
    when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=movie&imdbid=0848228"), indexerConfig)).thenThrow(new IndexerAccessException("some error"));
    CheckCapsResponse checkCapsRespone = testee.checkCaps(indexerConfig);
    assertEquals(5, checkCapsRespone.getIndexerConfig().getSupportedSearchIds().size());
    assertFalse(checkCapsRespone.isAllCapsChecked());
    verify(indexerWebAccess, times(7)).get(any(), eq(indexerConfig));
}
Also used : NewznabResponseBuilder(org.nzbhydra.fortests.NewznabResponseBuilder) IndexerAccessException(org.nzbhydra.indexers.exceptions.IndexerAccessException) URI(java.net.URI) BinsearchTest(org.nzbhydra.indexers.BinsearchTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 NewznabResponseBuilder (org.nzbhydra.fortests.NewznabResponseBuilder)5 URI (java.net.URI)3 BinsearchTest (org.nzbhydra.indexers.BinsearchTest)3 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)3 MockResponse (okhttp3.mockwebserver.MockResponse)2 NewznabParameters (org.nzbhydra.mapping.newznab.NewznabParameters)2 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 IndexerAccessException (org.nzbhydra.indexers.exceptions.IndexerAccessException)1 CapsSearch (org.nzbhydra.mapping.newznab.caps.CapsSearch)1