Search in sources :

Example 6 with ResourceUtil

use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.

the class ArtistRelationServiceTest method getArtistSimilarityClient.

@SuppressWarnings("unchecked")
private ArtistSimilarityClient getArtistSimilarityClient(WebserviceHistoryService historyService) throws IOException {
    // create a HTTP client that always returns Cher artist relations
    HttpClient httpClient = mock(HttpClient.class);
    ClientConnectionManager connectionManager = mock(ClientConnectionManager.class);
    when(httpClient.getConnectionManager()).thenReturn(connectionManager);
    String httpResponse = new ResourceUtil(CHER_ARTIST_RELATIONS).getContent();
    when(httpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).thenReturn(httpResponse);
    // create a throttling service that allows calls at any rate
    ThrottleService throttleService = mock(ThrottleService.class);
    // create a client that allows all calls and returns Cher artist relations
    ArtistSimilarityClient asClient = new ArtistSimilarityClient();
    asClient.setWebserviceHistoryService(historyService);
    asClient.setHttpClient(httpClient);
    asClient.setThrottleService(throttleService);
    return asClient;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ResponseHandler(org.apache.http.client.ResponseHandler) ArtistSimilarityClient(com.github.hakko.musiccabinet.ws.lastfm.ArtistSimilarityClient) HttpClient(org.apache.http.client.HttpClient) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager)

Example 7 with ResourceUtil

use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.

the class ArtistTopTagsServiceTest method getArtistTopTagsClient.

@SuppressWarnings("unchecked")
private ArtistTopTagsClient getArtistTopTagsClient(WebserviceHistoryService historyService) throws IOException {
    // create a HTTP client that always returns Cher top tracks
    HttpClient httpClient = mock(HttpClient.class);
    ClientConnectionManager connectionManager = mock(ClientConnectionManager.class);
    when(httpClient.getConnectionManager()).thenReturn(connectionManager);
    String httpResponse = new ResourceUtil(CHER_TOP_TAGS).getContent();
    when(httpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).thenReturn(httpResponse);
    // create a throttling service that allows calls at any rate
    ThrottleService throttleService = mock(ThrottleService.class);
    // create a client based on mocked HTTP client
    ArtistTopTagsClient attClient = new ArtistTopTagsClient();
    attClient.setWebserviceHistoryService(historyService);
    attClient.setHttpClient(httpClient);
    attClient.setThrottleService(throttleService);
    return attClient;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ResponseHandler(org.apache.http.client.ResponseHandler) HttpClient(org.apache.http.client.HttpClient) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) ArtistTopTagsClient(com.github.hakko.musiccabinet.ws.lastfm.ArtistTopTagsClient)

Example 8 with ResourceUtil

use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.

the class JdbcUserLovedTracksDaoTest method deletesUnlovedTracksIdentifiedInImport.

@Test
public void deletesUnlovedTracksIdentifiedInImport() throws ApplicationException {
    List<Track> lovedTracks = new UserLovedTracksParserImpl(new ResourceUtil(LOVED_TRACKS_FILE).getInputStream()).getLovedTracks();
    dao.createLovedTracks(asList(new UserLovedTracks(USERNAME1, lovedTracks)));
    lovedTracks.remove(0);
    dao.createLovedTracks(asList(new UserLovedTracks(USERNAME1, lovedTracks)));
    List<Track> dbLovedTracks = dao.getLovedTracks(USERNAME1);
    Collections.sort(lovedTracks);
    Collections.sort(dbLovedTracks);
    assertEquals(lovedTracks, dbLovedTracks);
}
Also used : UserLovedTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) UserLovedTracks(com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks) UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 9 with ResourceUtil

use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.

the class JdbcUserLovedTracksDaoTest method createAndRetrievesUserLovedTracks.

@Test
public void createAndRetrievesUserLovedTracks() throws ApplicationException {
    List<Track> lovedTracks = new UserLovedTracksParserImpl(new ResourceUtil(LOVED_TRACKS_FILE).getInputStream()).getLovedTracks();
    dao.createLovedTracks(asList(new UserLovedTracks(USERNAME1, lovedTracks)));
    List<Track> dbLovedTracks = dao.getLovedTracks(USERNAME1);
    Collections.sort(lovedTracks);
    Collections.sort(dbLovedTracks);
    assertEquals(lovedTracks, dbLovedTracks);
}
Also used : UserLovedTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) UserLovedTracks(com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks) UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 10 with ResourceUtil

use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.

the class JdbcUserRecommendedArtistsDaoTest method loadFunctionDependency.

@Before
public void loadFunctionDependency() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_USER_RECOMMENDED_ARTISTS);
    joanRec = new UserRecommendedArtists(joan, new UserRecommendedArtistsParserImpl(new ResourceUtil(JOAN_FILE).getInputStream()).getArtists());
    rjRec = new UserRecommendedArtists(rj, new UserRecommendedArtistsParserImpl(new ResourceUtil(RJ_FILE).getInputStream()).getArtists());
    String body = new WSResponse(new ResourceUtil(FTPAREA_FILE).getContent()).getResponseBody();
    ftpareaRec = new UserRecommendedArtists(ftparea, new UserRecommendedArtistsParserImpl(new StringUtil(body).getInputStream()).getArtists());
    createArtistMetaData();
}
Also used : UserRecommendedArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) UserRecommendedArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) Before(org.junit.Before)

Aggregations

ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)45 Test (org.junit.Test)25 Before (org.junit.Before)7 HttpClient (org.apache.http.client.HttpClient)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 Track (com.github.hakko.musiccabinet.domain.model.music.Track)5 ResponseHandler (org.apache.http.client.ResponseHandler)5 File (com.github.hakko.musiccabinet.domain.model.library.File)4 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)4 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)4 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)4 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)4 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)4 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)3 MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)3 ArtistTopTracksParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl)3 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)3 ArrayList (java.util.ArrayList)3 UserLovedTracks (com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks)2 UserStarredTrack (com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)2