Search in sources :

Example 26 with ResourceUtil

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

the class JdbcAlbumInfoDaoTest method loadFunctionDependency.

@Before
public void loadFunctionDependency() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_ALBUMINFO);
    aiNirvana = new AlbumInfoParserImpl(new ResourceUtil(AI_NIRVANA_FILE).getInputStream()).getAlbumInfo();
    aiHurts = new AlbumInfoParserImpl(new ResourceUtil(AI_HURTS_FILE).getInputStream()).getAlbumInfo();
    aiSchuller = new AlbumInfoParserImpl(new ResourceUtil(AI_SCHULLER_FILE).getInputStream()).getAlbumInfo();
    aiNirvana2 = new AlbumInfoParserImpl(new ResourceUtil(AI_NIRVANA2_FILE).getInputStream()).getAlbumInfo();
    aiNirvana3 = new AlbumInfoParserImpl(new ResourceUtil(AI_NIRVANA3_FILE).getInputStream()).getAlbumInfo();
    deleteArtists();
    deleteLibraryTracks();
    createLibraryTracks(aiNirvana, aiNirvana2, aiNirvana3, aiHurts, aiSchuller);
    for (AlbumInfo ai : asList(aiNirvana, aiHurts, aiSchuller)) {
        ai.getAlbum().getArtist().setId(musicDao.getArtistId(ai.getAlbum().getArtist()));
    }
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) AlbumInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) Before(org.junit.Before)

Example 27 with ResourceUtil

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

the class JdbcArtistInfoDaoTest method loadFunctionDependency.

@Before
public void loadFunctionDependency() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_ARTISTINFO);
    aiAbba = new ArtistInfoParserImpl(new ResourceUtil(AI_ABBA_FILE).getInputStream()).getArtistInfo();
    aiCher = new ArtistInfoParserImpl(new ResourceUtil(AI_CHER_FILE).getInputStream()).getArtistInfo();
    aiTina = new ArtistInfoParserImpl(new ResourceUtil(AI_TINA_FILE).getInputStream()).getArtistInfo();
    deleteArtists();
    // re-create artists
    for (ArtistInfo ai : new ArtistInfo[] { aiAbba, aiCher, aiTina }) {
        musicDao.getArtistId(ai.getArtist());
    }
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ArtistInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) Before(org.junit.Before)

Example 28 with ResourceUtil

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

the class UserLovedTracksServiceTest method updatesStarredTracksWhenImportIsOnlyAllowedForOneUser.

/*
	 * User story: user1 has starred track2, user2 has starred track3 & track4.
	 * When importing loved tracks, user2 is unavailable and user1 has loved track1.
	 * Expected outcome: afterwards, user1 has starred track1 & 2 and user2 track3 & 4.
	 */
@Test
public void updatesStarredTracksWhenImportIsOnlyAllowedForOneUser() throws ApplicationException {
    lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER1));
    lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER2));
    LastFmUser user1 = lastFmDao.getLastFmUser(USER1), user2 = lastFmDao.getLastFmUser(USER2);
    Track track1 = new Track("Frank Ocean", "Lost"), track2 = new Track("Kate Bush", "Cloudbusting"), track3 = new Track("Adele", "Skyfall"), track4 = new Track("Kath Bloom", "Fall Again");
    File f1, f2, f3, f4;
    deleteLovedAndStarredTracks();
    submitFile(additionDao, asList(f1 = getFile(track1), f2 = getFile(track2), f3 = getFile(track3), f4 = getFile(track4)));
    int track1Id = browserDao.getTrackId(f1), track2Id = browserDao.getTrackId(f2), track3Id = browserDao.getTrackId(f3), track4Id = browserDao.getTrackId(f4);
    LastFmSettingsService lastFmSettingsService = mock(LastFmSettingsService.class);
    when(lastFmSettingsService.getLastFmUsers()).thenReturn(asList(user1, user2));
    when(lastFmSettingsService.isSyncStarredAndLovedTracks()).thenReturn(true);
    UserLovedTracksClient userLovedTracksClient = mock(UserLovedTracksClient.class);
    when(userLovedTracksClient.getUserLovedTracks(user1, (short) 0)).thenReturn(new WSResponse(new ResourceUtil(LOVED_TRACKS_FILE, UTF8).getContent()));
    when(userLovedTracksClient.getUserLovedTracks(user2, (short) 0)).thenReturn(new WSResponse(false, 403, "Forbidden"));
    UserLovedTracksService userLovedTracksService = new UserLovedTracksService();
    userLovedTracksService.setLastFmSettingsService(lastFmSettingsService);
    userLovedTracksService.setUserLovedTracksClient(userLovedTracksClient);
    userLovedTracksService.setUserLovedTracksDao(userLovedTracksDao);
    userLovedTracksService.setStarService(mock(StarService.class));
    userLovedTracksService.setTrackLoveClient(mock(TrackLoveClient.class));
    starDao.starTrack(user1, track2Id);
    starDao.starTrack(user2, track3Id);
    starDao.starTrack(user2, track4Id);
    userLovedTracksService.updateSearchIndex();
    assertEquals(sort(asList(track1Id, track2Id)), sort(starDao.getStarredTrackIds(user1)));
    assertEquals(sort(asList(track3Id, track4Id)), sort(starDao.getStarredTrackIds(user2)));
}
Also used : UserLovedTracksClient(com.github.hakko.musiccabinet.ws.lastfm.UserLovedTracksClient) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) TrackLoveClient(com.github.hakko.musiccabinet.ws.lastfm.TrackLoveClient) UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File) UnittestLibraryUtil.submitFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.submitFile) Track(com.github.hakko.musiccabinet.domain.model.music.Track) StarService(com.github.hakko.musiccabinet.service.StarService) Test(org.junit.Test)

Example 29 with ResourceUtil

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

the class UserTopArtistsServiceTest method createArtistInfosAndLocalFiles.

private void createArtistInfosAndLocalFiles() throws ApplicationException {
    Map<Artist, ArtistInfo> artistInfos = new HashMap<>();
    List<File> files = new ArrayList<>();
    for (Period period : Period.values()) {
        String fileName = format(TOP_ARTISTS_FILE, period.getDescription());
        for (Artist artist : new UserTopArtistsParserImpl(new ResourceUtil(fileName, UTF8).getInputStream()).getArtists()) {
            artistInfos.put(artist, new ArtistInfo(artist));
            files.add(UnittestLibraryUtil.getFile(artist.getName(), "A", "T"));
        }
    }
    artistInfoDao.createArtistInfo(new ArrayList<ArtistInfo>(artistInfos.values()));
    submitFile(additionDao, files);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) UserTopArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParserImpl) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(com.github.hakko.musiccabinet.domain.model.library.Period) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) File(com.github.hakko.musiccabinet.domain.model.library.File) UnittestLibraryUtil.submitFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.submitFile)

Example 30 with ResourceUtil

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

the class TrackSimilarityParserTest method resourceFileCorrectlyParsed.

@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
    TrackSimilarityParser parser = new TrackSimilarityParserImpl(new ResourceUtil(TRACK_SIMILARITY_FILE).getInputStream());
    assertNotNull(parser.getTrack());
    assertNotNull(parser.getTrackRelations());
    assertTrue(parser.getTrack().getArtist().getName().equals("Cher"));
    assertTrue(parser.getTrack().getName().equals("Believe"));
    assertEquals(parser.getTrackRelations().size(), 250);
    for (TrackRelation tr : parser.getTrackRelations()) {
        assertNotNull(tr.getTarget());
        assertNotNull(tr.getTarget().getArtist());
    }
    verifyTrackRelation(parser, 0, "Cher", "Strong Enough", 1.0f);
    verifyTrackRelation(parser, 1, "Cher", "All Or Nothing", 0.961879f);
    verifyTrackRelation(parser, 2, "Madonna", "Vogue", 0.291088f);
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation) Test(org.junit.Test)

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