@Test
  public void testSearch() throws MetadataException {
    TMDB3MetadataProvider provider =
        (TMDB3MetadataProvider) Phoenix.getInstance().getMetadataManager().getProvider("tmdb3");
    assertNotNull("TMDB3 is not registered.", provider);

    SearchQuery q = new SearchQuery(MediaType.MOVIE, "Iron Man 2", "2010");
    // set the title in the QUERY fields, since providers look in the QUERY
    // field
    q.set(Field.QUERY, "Iron Man 2");
    List<IMetadataSearchResult> results = provider.search(q);
    assertTrue(results.size() > 0);

    for (IMetadataSearchResult r : results) {
      System.out.printf("RESULT: %s; %s; %s\n", r.getTitle(), r.getYear(), r.getScore());
    }

    // Iron Man 2 should be first result
    IMetadataSearchResult sr = results.get(0);
    assertEquals("10138", sr.getId());
    assertEquals("tmdb3", sr.getProviderId());
    assertEquals(MediaType.MOVIE, sr.getMediaType());
    assertEquals("Iron Man 2", sr.getTitle());
    assertEquals("2010", String.valueOf(sr.getYear()));
    assertTrue(sr.getScore() > .9);
  }
  @Test
  public void testProcessRequest_DefaultFanartFromUserData() throws IOException {
    // but we want to test that it reads from the userdata area.
    File file =
        new File(
            Phoenix.getInstance().getUserPath(AdvancedFanartMediaRequestHandler.DEFAULT_FANART),
            "default_movie_poster.jpg");
    FileUtils.touch(file);

    AdvancedFanartMediaRequestHandler handler = spy(new AdvancedFanartMediaRequestHandler());
    doNothing().when(handler).sendFile(any(File.class), any(HttpServletResponse.class));
    doNothing()
        .when(handler)
        .error(
            anyInt(), anyString(), any(HttpServletRequest.class), any(HttpServletResponse.class));
    HttpServletRequest req = mock(HttpServletRequest.class);
    HttpServletResponse resp = mock(HttpServletResponse.class);

    doReturn("true").when(req).getParameter(AdvancedFanartMediaRequestHandler.PARAM_USE_DEFAULT);
    doReturn("movie").when(req).getParameter(AdvancedFanartMediaRequestHandler.PARAM_MEDIATYPE);
    doReturn("poster").when(req).getParameter(AdvancedFanartMediaRequestHandler.PARAM_ARTIFACTTYPE);
    doReturn("1").when(req).getParameter(AdvancedFanartMediaRequestHandler.PARAM_MEDIAFILE);
    handler.processRequest(req, resp);

    ArgumentCaptor<File> capture = ArgumentCaptor.forClass(File.class);
    verify(handler).sendFile(capture.capture(), any(HttpServletResponse.class));
    assertEquals("default_movie_poster.jpg", capture.getValue().getName());
    assertEquals("Should be 0 byte file, since we just created it", 0, capture.getValue().length());
  }
  @Test
  public void testDetailsByIMDBID() throws MetadataException, IOException {
    TMDB3MetadataProvider provider =
        (TMDB3MetadataProvider) Phoenix.getInstance().getMetadataManager().getProvider("tmdb3");
    assertNotNull("TMDB3 is not registered.", provider);

    IMetadata md = ((HasFindByIMDBID) provider).getMetadataForIMDBId("tt1228705");
    verifyMetadata(md);
  }
  @Test
  public void testDetailsByID() throws MetadataException, IOException {
    TMDB3MetadataProvider provider =
        (TMDB3MetadataProvider) Phoenix.getInstance().getMetadataManager().getProvider("tmdb3");
    assertNotNull("TMDB3 is not registered.", provider);

    SearchQuery q = new SearchQuery(MediaType.MOVIE, Field.ID, "10138");
    List<IMetadataSearchResult> results = provider.search(q);
    assertEquals(1, results.size());
    verifyMetadata(provider.getMetaData(results.get(0)));
  }
 /**
  * Finds and returns a profile for the given username.
  *
  * <p>Returns null if no profile is found.
  *
  * @param user
  * @return
  */
 public Profile GetUserProfile(String user) {
   return Phoenix.getInstance().getProfileManager().getProfile(user);
 }
 /**
  * Removes a user profile
  *
  * @param profile
  */
 public void RemoveUserProfile(Profile profile) {
   Phoenix.getInstance().getProfileManager().removeProfile(profile);
 }
 /**
  * Creates and adds a new User profile for the given name.
  *
  * @param userName
  * @return
  */
 public Profile AddUserProfile(String userName) {
   Profile p = new Profile(userName);
   Phoenix.getInstance().getProfileManager().addProfile(p);
   return p;
 }
 /**
  * Return an array of the currently known user profiles
  *
  * <p>TODO: Currently this returns a static list
  *
  * @return
  */
 public Profile[] GetUserProfiles() {
   return Phoenix.getInstance().getProfileManager().getProfiles();
 }
 /**
  * Set the current User Profile to the current client.
  *
  * @param profile
  */
 public void SetCurrentUserProfile(Profile profile) {
   Phoenix.getInstance().getProfileManager().setCurrentProfile(profile);
 }
 /**
  * Get the current User Profile that is active for a given client. If not profile is active, then
  * a default profile is created and set as the active profile.
  *
  * @return Current User Profile
  */
 public Profile GetCurrentUserProfile() {
   return Phoenix.getInstance().getProfileManager().getCurrentProfile();
 }
 public static ViewFactory registerView(String factoryId, IMediaFolder view) {
   StubViewFactory stub = new StubViewFactory(factoryId, view);
   Phoenix.getInstance().getVFSManager().getVFSViewFactory().addFactory(stub);
   return stub;
 }