Search in sources :

Example 6 with MediaInfo

use of org.nzbhydra.mediainfo.MediaInfo in project nzbhydra2 by theotherp.

the class ExternalApiSearchingIntegrationTest method shouldConvertProvidedIdentifier.

@Test
public void shouldConvertProvidedIdentifier() throws Exception {
    prepareIndexerWithOneResponse();
    searchModuleProvider.getIndexers().get(0).getConfig().setSupportedSearchIds(Arrays.asList(IdType.IMDB));
    when(infoProvider.convert(anyMap())).thenReturn(new MediaInfo(new MovieInfo("tt1234", null, null, 0, null)));
    when(infoProvider.canConvertAny(anySet(), anySet())).thenReturn(true);
    NewznabXmlRoot root = (NewznabXmlRoot) externalApi.api(NewznabParameters.builder().tmdbid("abcd").t(ActionAttribute.MOVIE).apikey("apikey").build()).getBody();
    RecordedRequest request = webServer.takeRequest(2, TimeUnit.SECONDS);
    assertThat(request.getRequestUrl().queryParameter("imdbid")).isEqualTo("1234");
    assertThat(root.getRssChannel().getNewznabResponse().getTotal()).isEqualTo(1);
    assertThat(root.getRssChannel().getItems().size()).isEqualTo(1);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) MovieInfo(org.nzbhydra.mediainfo.MovieInfo) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with MediaInfo

use of org.nzbhydra.mediainfo.MediaInfo in project nzbhydra2 by theotherp.

the class IndexerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(indexerMock.getIndexerEntity()).thenReturn(indexerEntityMock);
    when(indexerMock.getConfig()).thenReturn(indexerConfig);
    when(indexerEntityMock.getName()).thenReturn("indexerName");
    when(indexerMock.getName()).thenReturn("indexerName");
    testee.indexer = indexerEntityMock;
    testee.config = indexerConfig;
    indexerConfig.setTimeout(1);
    baseConfig = new BaseConfig();
    when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
    baseConfig.getSearching().setIdFallbackToQueryGeneration(SearchSourceRestriction.BOTH);
    when(resultAcceptor.acceptResults(anyList(), any(), any())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return new AcceptorResult(invocation.getArgument(0), HashMultiset.create());
        }
    });
    when(infoProviderMock.convert(anyString(), any())).thenReturn(new MediaInfo(new TvInfo("tvdbid", "tvrageid", "tvmazeid", "title", 2017, "")));
    testee = spy(testee);
}
Also used : AcceptorResult(org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TvInfo(org.nzbhydra.mediainfo.TvInfo) BaseConfig(org.nzbhydra.config.BaseConfig) Before(org.junit.Before)

Example 8 with MediaInfo

use of org.nzbhydra.mediainfo.MediaInfo in project nzbhydra2 by theotherp.

the class IndexerTest method shouldSanitizeQuery.

@Test
public void shouldSanitizeQuery() throws IndexerSearchAbortedException, InfoProviderException {
    when(infoProviderMock.convert(anyString(), any())).thenReturn(new MediaInfo(new TvInfo("tvdbid", "tvrageid", "tvmazeid", "title()':", 2017, "")));
    baseConfig.getSearching().setGenerateQueries(SearchSourceRestriction.BOTH);
    SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
    Map<IdType, String> identifiers = new HashMap<>();
    identifiers.put(IdType.IMDB, "123");
    searchRequest.setIdentifiers(identifiers);
    String query = testee.generateQueryIfApplicable(searchRequest, "query");
    assertThat(query, is("title"));
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) HashMap(java.util.HashMap) TvInfo(org.nzbhydra.mediainfo.TvInfo) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IdType(org.nzbhydra.mediainfo.InfoProvider.IdType) Test(org.junit.Test)

Aggregations

MediaInfo (org.nzbhydra.mediainfo.MediaInfo)8 Test (org.junit.Test)5 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Before (org.junit.Before)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)2 IdType (org.nzbhydra.mediainfo.InfoProvider.IdType)2 MovieInfo (org.nzbhydra.mediainfo.MovieInfo)2 TvInfo (org.nzbhydra.mediainfo.TvInfo)2 AcceptorResult (org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult)2 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 BaseConfig (org.nzbhydra.config.BaseConfig)1 InfoProviderException (org.nzbhydra.mediainfo.InfoProviderException)1 UriComponents (org.springframework.web.util.UriComponents)1