use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class BinsearchTest method shouldAddRequiredWords.
@Test
public void shouldAddRequiredWords() throws IndexerSearchAbortedException {
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
searchRequest.getInternalData().setRequiredWords(Arrays.asList("a", "b"));
searchRequest.setQuery("query");
UriComponentsBuilder builder = testee.buildSearchUrl(searchRequest, 0, 100);
assertThat(builder.build().toString(), is("https://www.binsearch.info/?adv_col=on&postdate=date&adv_sort=date&min=0&max=100&q=query a b"));
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class IndexerTest method shouldUseFallback.
@Test
public void shouldUseFallback() throws Exception {
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
Map<IdType, String> identifiers = new HashMap<>();
identifiers.put(IdType.IMDB, "123");
searchRequest.setIdentifiers(identifiers);
SearchResultItem item = new SearchResultItem();
item.setIndexer(indexerMock);
item.setIndexerGuid("indexerGuid");
// searchResultItemsToReturn = Arrays.asList(item);
IndexerSearchResult search = testee.search(searchRequest, 0, 100);
verify(testee, times(2)).searchInternal(searchRequestCaptor.capture(), anyInt(), anyInt());
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class NewznabTest method shouldThrowAuthException.
@Test(expected = IndexerAuthException.class)
public void shouldThrowAuthException() throws Exception {
doReturn(new NewznabXmlError("101", "Wrong API key")).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);
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class NewznabTest method shouldGenerateQueryIfFallbackRequested.
@Test
public void shouldGenerateQueryIfFallbackRequested() throws Exception {
testee.config = new IndexerConfig();
baseConfig.getSearching().setGenerateQueries(SearchSourceRestriction.BOTH);
testee.config.setHost("http://www.indexer.com");
testee.config.setSupportedSearchIds(Arrays.asList(IdType.TVDB));
testee.config.setSupportedSearchTypes(Arrays.asList(ActionAttribute.TVSEARCH, ActionAttribute.SEARCH));
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.TVSEARCH, 0, 100);
searchRequest.getInternalData().setFallbackState(FallbackState.REQUESTED);
searchRequest.getIdentifiers().put(IdType.TVDB, "tvdbId");
when(infoProviderMock.canConvert(any(), any())).thenReturn(false);
MediaInfo mediaInfo = new MediaInfo();
mediaInfo.setTitle("someShow");
when(infoProviderMock.convert("tvdbId", IdType.TVDB)).thenReturn(mediaInfo);
assertEquals("someShow", testee.generateQueryIfApplicable(searchRequest, ""));
// Don't add season/episode for fallback queries
searchRequest.getInternalData().setFallbackState(FallbackState.REQUESTED);
searchRequest.setSeason(1);
searchRequest.setEpisode("1");
assertEquals("someShow", testee.generateQueryIfApplicable(searchRequest, ""));
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class NewznabTest method shouldAccountForRejectedResults.
@Test
public void shouldAccountForRejectedResults() throws Exception {
List<NewznabXmlItem> items = Arrays.asList(RssItemBuilder.builder("title1").build(), RssItemBuilder.builder("title2").build(), RssItemBuilder.builder("title3").build(), RssItemBuilder.builder("title4").build(), RssItemBuilder.builder("title5").build());
NewznabXmlRoot root = RssBuilder.builder().items(items).newznabResponse(100, 105).build();
when(indexerWebAccessMock.get(any(), eq(testee.config), any())).thenReturn(root);
// Two items will be rejected
when(resultAcceptorMock.acceptResults(any(), any(), any())).thenAnswer(new Answer<AcceptorResult>() {
@Override
public AcceptorResult answer(InvocationOnMock invocation) throws Throwable {
List<SearchResultItem> argument = invocation.getArgument(0);
HashMultiset<String> reasonsForRejection = HashMultiset.create();
reasonsForRejection.add("some reason", 2);
return new AcceptorResult(argument.subList(0, 3), reasonsForRejection);
}
});
IndexerSearchResult indexerSearchResult = testee.searchInternal(new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100), 0, 100);
assertThat(indexerSearchResult.getSearchResultItems().size(), is(3));
assertThat(indexerSearchResult.getTotalResults(), is(105));
assertThat(indexerSearchResult.isHasMoreResults(), is(false));
assertThat(indexerSearchResult.isTotalResultsKnown(), is(true));
}
Aggregations