Search in sources :

Example 11 with SearchRequest

use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.

the class NewznabTest method shouldUseDifferentExclusionFormatForNzedbAndOmgWtf.

@Test
public void shouldUseDifferentExclusionFormatForNzedbAndOmgWtf() throws Exception {
    testee.config.setBackend(BackendType.NZEDB);
    SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
    searchRequest.setQuery("q");
    searchRequest.getInternalData().setForbiddenWords(Lists.newArrayList("a", "b", "c"));
    assertEquals(UriComponentsBuilder.fromHttpUrl("http://127.0.0.1:1234/api?t=search&extended=1&q=q !a,!b,!c").build(), testee.buildSearchUrl(searchRequest, null, null).build());
    searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
    searchRequest.setQuery("aquery");
    searchRequest.getInternalData().setForbiddenWords(Lists.newArrayList("a", "b", "c"));
    assertEquals(UriComponentsBuilder.fromHttpUrl("http://127.0.0.1:1234/api?t=search&extended=1&q=aquery !a,!b,!c").build(), testee.buildSearchUrl(searchRequest, null, null).build());
    testee.config.setBackend(BackendType.NEWZNAB);
    testee.config.setHost("http://www.OMGwtfnzbs.com");
    searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
    searchRequest.setQuery("q");
    searchRequest.getInternalData().setForbiddenWords(Lists.newArrayList("a", "b", "c"));
    assertEquals(UriComponentsBuilder.fromHttpUrl("http://www.OMGwtfnzbs.com/api?t=search&extended=1&q=q !a,!b,!c").build(), testee.buildSearchUrl(searchRequest, null, null).build());
    searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
    searchRequest.setQuery("aquery");
    searchRequest.getInternalData().setForbiddenWords(Lists.newArrayList("a", "b", "c"));
    assertEquals(UriComponentsBuilder.fromHttpUrl("http://www.OMGwtfnzbs.com/api?t=search&extended=1&q=aquery !a,!b,!c").build(), testee.buildSearchUrl(searchRequest, null, null).build());
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) Test(org.junit.Test)

Example 12 with SearchRequest

use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.

the class NewznabTest method shouldThrowErrorCodeWhen100ApiHitLimits.

@Test(expected = IndexerErrorCodeException.class)
public void shouldThrowErrorCodeWhen100ApiHitLimits() throws Exception {
    doReturn(new NewznabXmlError("100", "Daily Hits Limit Reached\"")).when(testee).getAndStoreResultToDatabase(any(), eq(Xml.class), eq(IndexerApiAccessType.SEARCH));
    doNothing().when(testee).handleFailure(errorMessageCaptor.capture(), disabledPermanentlyCaptor.capture(), any(IndexerApiAccessType.class), any(), indexerApiAccessResultCaptor.capture());
    testee.searchInternal(new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100), 0, 100);
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) Test(org.junit.Test)

Example 13 with SearchRequest

use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.

the class NewznabTest method shouldUseAuthorAndTitleIfBookSearchSupported.

@Test
public void shouldUseAuthorAndTitleIfBookSearchSupported() throws Exception {
    testee.config = new IndexerConfig();
    baseConfig.getSearching().setGenerateQueries(SearchSourceRestriction.BOTH);
    testee.config.setHost("http://www.indexer.com");
    testee.config.setSupportedSearchTypes(Arrays.asList(ActionAttribute.BOOK));
    SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.BOOK, 0, 100);
    searchRequest.setAuthor("author");
    searchRequest.setTitle("title");
    assertEquals(UriComponentsBuilder.fromHttpUrl("http://www.indexer.com/api?t=book&extended=1&q=title&title=title&author=author").build(), testee.buildSearchUrl(searchRequest, null, null).build());
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) Test(org.junit.Test)

Example 14 with SearchRequest

use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.

the class NewznabTest method shouldGenerateQueryIfNecessaryAndAllowed.

@Test
public void shouldGenerateQueryIfNecessaryAndAllowed() throws Exception {
    testee.config = new IndexerConfig();
    baseConfig.getSearching().setGenerateQueries(SearchSourceRestriction.BOTH);
    testee.config.setHost("http://www.indexer.com");
    testee.config.setSupportedSearchIds(Collections.emptyList());
    SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
    searchRequest.getIdentifiers().put(IdType.IMDB, "imdbId");
    when(infoProviderMock.canConvert(any(), any())).thenReturn(false);
    MediaInfo mediaInfo = new MediaInfo();
    mediaInfo.setTitle("someMovie");
    when(infoProviderMock.convert("imdbId", IdType.IMDB)).thenReturn(mediaInfo);
    assertEquals(UriComponentsBuilder.fromHttpUrl("http://www.indexer.com/api?t=search&extended=1&imdbid=imdbId&q=someMovie").build(), testee.buildSearchUrl(searchRequest, null, null).build());
    // Should use title if provided
    searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
    searchRequest.setTitle("anotherTitle");
    UriComponents actual = testee.buildSearchUrl(searchRequest, null, null).build();
    assertEquals(UriComponentsBuilder.fromHttpUrl("http://www.indexer.com/api?t=search&extended=1&q=anotherTitle").build(), actual);
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) UriComponents(org.springframework.web.util.UriComponents) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) Test(org.junit.Test)

Example 15 with SearchRequest

use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.

the class NewznabTest method shouldNotUseMovieWithoutIdentifiers.

@Test
public void shouldNotUseMovieWithoutIdentifiers() throws Exception {
    SearchRequest request = new SearchRequest(SearchSource.INTERNAL, SearchType.MOVIE, 0, 100);
    String uri = testee.buildSearchUrl(request, 0, 100).toUriString();
    assertThat(uri, containsString("t=search"));
    request = new SearchRequest(SearchSource.INTERNAL, SearchType.MOVIE, 0, 100);
    request.getIdentifiers().put(IdType.IMDB, "123");
    testee.config.getSupportedSearchIds().add(IdType.IMDB);
    testee.config.getSupportedSearchTypes().add(ActionAttribute.MOVIE);
    uri = testee.buildSearchUrl(request, 0, 100).toUriString();
    assertThat(uri, containsString("t=movie"));
    assertThat(uri, containsString("imdbid=123"));
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)48 Test (org.junit.Test)40 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)8 Stopwatch (com.google.common.base.Stopwatch)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 IdType (org.nzbhydra.mediainfo.InfoProvider.IdType)4 Iterables (com.google.common.collect.Iterables)3 Sets (com.google.common.collect.Sets)3 Instant (java.time.Instant)3 java.util (java.util)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 ConfigProvider (org.nzbhydra.config.ConfigProvider)3 Indexer (org.nzbhydra.indexers.Indexer)3 LoggingMarkers (org.nzbhydra.logging.LoggingMarkers)3 MediaInfo (org.nzbhydra.mediainfo.MediaInfo)3 SearchSource (org.nzbhydra.searching.searchrequests.SearchRequest.SearchSource)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3