use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class NewznabTest method shouldGenerateQueryIfBookSearchTypeNotSupported.
@Test
public void shouldGenerateQueryIfBookSearchTypeNotSupported() throws Exception {
testee.config = new IndexerConfig();
baseConfig.getSearching().setGenerateQueries(SearchSourceRestriction.BOTH);
testee.config.setHost("http://www.indexer.com");
testee.config.setSupportedSearchIds(Collections.emptyList());
testee.config.setSupportedSearchTypes(Collections.emptyList());
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=search&extended=1&q=title author").build(), testee.buildSearchUrl(searchRequest, null, null).build());
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class NewznabTest method shouldBuildCorrectSearchUrl.
@Test
public void shouldBuildCorrectSearchUrl() throws Exception {
SearchRequest request = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
String uri = testee.buildSearchUrl(request, 0, 100).toUriString();
assertThat(uri, is("http://127.0.0.1:1234/api?t=search&extended=1&limit=100&offset=0"));
otherCategory.setNewznabCategories(Arrays.asList(2000));
request.setCategory(otherCategory);
uri = testee.buildSearchUrl(request, 0, 100).toUriString();
assertThat(uri, is("http://127.0.0.1:1234/api?t=search&extended=1&cat=2000&limit=100&offset=0"));
otherCategory.setNewznabCategories(Arrays.asList(2030, 2040));
request.setCategory(otherCategory);
uri = testee.buildSearchUrl(request, 0, 100).toUriString();
assertThat(uri, is("http://127.0.0.1:1234/api?t=search&extended=1&cat=2030,2040&limit=100&offset=0"));
animeCategory.setSubtype(Subtype.ANIME);
request.setCategory(animeCategory);
testee.getConfig().getCategoryMapping().setAnime(9090);
uri = testee.buildSearchUrl(request, 0, 100).toUriString();
assertThat(uri, is("http://127.0.0.1:1234/api?t=search&extended=1&cat=9090&limit=100&offset=0"));
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class NewznabTest method shouldGetIdsIfNoneOfTheProvidedAreSupported.
@Test
public void shouldGetIdsIfNoneOfTheProvidedAreSupported() throws Exception {
when(infoProviderMock.canConvertAny(anySet(), anySet())).thenReturn(true);
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
searchRequest.getIdentifiers().put(IdType.IMDB, "imdbId");
searchRequest.getIdentifiers().put(IdType.TVMAZE, "tvmazeId");
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://www.indexerName.com/api");
builder = testee.extendQueryUrlWithSearchIds(searchRequest, builder);
MultiValueMap<String, String> params = builder.build().getQueryParams();
assertTrue(params.containsKey("imdbid"));
assertTrue(params.containsKey("tmdbid"));
assertTrue(params.containsKey("rid"));
assertTrue(params.containsKey("tvmazeid"));
verify(infoProviderMock, times(1)).convert(anyMap());
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class NewznabTest method shouldReturnCorrectSearchResults.
@Test
public void shouldReturnCorrectSearchResults() throws Exception {
NewznabXmlRoot root = RssBuilder.builder().items(Arrays.asList(RssItemBuilder.builder("title").build())).newznabResponse(0, 1).build();
when(indexerWebAccessMock.get(any(), eq(testee.config), any())).thenReturn(root);
IndexerSearchResult indexerSearchResult = testee.searchInternal(new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100), 0, 100);
assertThat(indexerSearchResult.getSearchResultItems().size(), is(1));
assertThat(indexerSearchResult.getTotalResults(), is(1));
assertThat(indexerSearchResult.isHasMoreResults(), is(false));
assertThat(indexerSearchResult.isTotalResultsKnown(), is(true));
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class ExternalApiTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(configProvider.getBaseConfig()).thenReturn(baseConfig);
baseConfig.setMain(new MainConfig());
baseConfig.getMain().setApiKey("apikey");
when(searchRequestFactory.getSearchRequest(any(), any(), any(), anyLong(), any(), any())).thenReturn(new SearchRequest(SearchSource.API, SearchType.SEARCH, 0, 100));
when(searchRequestFactory.extendWithSavedIdentifiers(any())).thenAnswer(x -> x.getArguments()[0]);
when(searcher.search(any())).thenReturn(searchResult);
when(searchResult.getNumberOfAcceptedResults()).thenReturn(10);
when(searchResult.getNumberOfProcessedResults()).thenReturn(10);
when(searchResult.getNumberOfRejectedResults()).thenReturn(0);
when(searchResult.getNumberOfRemovedDuplicates()).thenReturn(0);
when(searchResult.getNumberOfTotalAvailableResults()).thenReturn(10);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
StreamResult streamResult = (StreamResult) invocation.getArguments()[1];
streamResult.getOutputStream().write("".getBytes(), 0, "".getBytes().length);
return null;
}
}).when(jaxb2MarshallerMock).marshal(any(), any());
when(indexerMock.getConfig()).thenReturn(indexerConfig);
}
Aggregations