Search in sources :

Example 1 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class UserTopArtistsServiceTest method updatesTopArtistsWhenImportIsOnlyAllowedForOneUser.

/*
	 * User story: user1 and user2 have (previously imported) top artists.
	 * During import, new data can only be fetched for user1.
	 * Expected: top artists for user1 are updated, while user2 keeps original artists.
	 */
@Test
public void updatesTopArtistsWhenImportIsOnlyAllowedForOneUser() throws Exception {
    PostgreSQLUtil.truncateTables(userTopArtistsDao);
    createArtistInfosAndLocalFiles();
    lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER1));
    lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER2));
    LastFmUser user1 = lastFmDao.getLastFmUser(USER1), user2 = lastFmDao.getLastFmUser(USER2);
    LastFmSettingsService lastFmSettingsService = mock(LastFmSettingsService.class);
    when(lastFmSettingsService.getLastFmUsers()).thenReturn(asList(user1, user2));
    UserTopArtistsClient userTopArtistsClient = mock(UserTopArtistsClient.class);
    for (Period period : Period.values()) {
        String fileName = format(TOP_ARTISTS_FILE, period.getDescription());
        when(userTopArtistsClient.getUserTopArtists(user1, period)).thenReturn(new WSResponse(new ResourceUtil(fileName, UTF8).getContent()));
        when(userTopArtistsClient.getUserTopArtists(user2, period)).thenReturn(new WSResponse(false, 403, "Forbidden"));
    }
    UserTopArtistsService userTopArtistsService = new UserTopArtistsService();
    userTopArtistsService.setLastFmSettingsService(lastFmSettingsService);
    userTopArtistsService.setUserTopArtistsClient(userTopArtistsClient);
    userTopArtistsService.setUserTopArtistsDao(userTopArtistsDao);
    userTopArtistsDao.createUserTopArtists(asList(new UserTopArtists(user1, OVERALL, asList(new Artist("M83"))), new UserTopArtists(user2, SIX_MONTHS, asList(new Artist("Zola Jesus")))));
    assertEquals("M83", userTopArtistsService.getUserTopArtists(user1, OVERALL, 0, 10).get(0).getArtistName());
    assertEquals("Zola Jesus", userTopArtistsService.getUserTopArtists(user2, SIX_MONTHS, 0, 10).get(0).getArtistName());
    userTopArtistsService.updateSearchIndex();
    assertEquals(1, userTopArtistsService.getUserTopArtists(user2, SIX_MONTHS, 0, 10).size());
    for (Period period : Period.values()) {
        assertEquals("Expected 50 artists for period " + period, 50, userTopArtistsService.getUserTopArtists(user1, period, 0, 50).size());
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) UserTopArtistsClient(com.github.hakko.musiccabinet.ws.lastfm.UserTopArtistsClient) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Period(com.github.hakko.musiccabinet.domain.model.library.Period) UserTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) Test(org.junit.Test)

Example 2 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class ScrobbleServiceTest method createTestData.

@Before
public void createTestData() throws ApplicationException {
    scrobbleService = new ScrobbleService();
    UpdateNowPlayingClient nowPlayinglient = mock(UpdateNowPlayingClient.class);
    when(nowPlayinglient.updateNowPlaying(Mockito.any(Scrobble.class))).thenReturn(new WSResponse(false, 404, "Not found"));
    scrobbleService.setUpdateNowPlayingClient(nowPlayinglient);
    ScrobbleClient scrobbleClient = mock(ScrobbleClient.class);
    when(scrobbleClient.scrobble(Mockito.any(Scrobble.class))).thenReturn(new WSResponse("<lfm status=\"ok\"></lfm>"));
    scrobbleService.setScrobbleClient(scrobbleClient);
    PlayCountDao playCountDao = mock(PlayCountDao.class);
    scrobbleService.setPlayCountDao(playCountDao);
    MetaData metaData1 = new MetaData();
    metaData1.setArtist("artist 1");
    metaData1.setArtistId(artist1Id);
    metaData1.setAlbum("album 1");
    metaData1.setAlbumId(album1Id);
    track1 = new Track(track1Id, "track 1", metaData1);
    track2 = new Track(track2Id, "track 2", metaData1);
    user1 = new LastFmUser(username1, sessionKey1);
    user2 = new LastFmUser(username2, sessionKey2);
}
Also used : ScrobbleClient(com.github.hakko.musiccabinet.ws.lastfm.ScrobbleClient) MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) UpdateNowPlayingClient(com.github.hakko.musiccabinet.ws.lastfm.UpdateNowPlayingClient) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Scrobble(com.github.hakko.musiccabinet.domain.model.aggr.Scrobble) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) Track(com.github.hakko.musiccabinet.domain.model.music.Track) PlayCountDao(com.github.hakko.musiccabinet.dao.PlayCountDao) Before(org.junit.Before)

Example 3 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class JdbcLastFmDaoTest method storesAndRetrievesUser.

@Test
public void storesAndRetrievesUser() {
    LastFmUser user = new LastFmUser("username", "sessionkey");
    dao.createOrUpdateLastFmUser(user);
    LastFmUser dbUser = dao.getLastFmUser(user.getLastFmUsername());
    Assert.assertNotNull(dbUser);
    Assert.assertEquals(user.getLastFmUsername(), dbUser.getLastFmUsername());
    Assert.assertEquals(user.getSessionKey(), dbUser.getSessionKey());
    user.setSessionKey("another session key");
    dao.createOrUpdateLastFmUser(user);
    dbUser = dao.getLastFmUser(user.getLastFmUsername());
    Assert.assertNotNull(dbUser);
    Assert.assertEquals(user.getLastFmUsername(), dbUser.getLastFmUsername());
    Assert.assertEquals(user.getSessionKey(), dbUser.getSessionKey());
}
Also used : LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Test(org.junit.Test)

Example 4 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class JdbcLibraryBrowserDaoAggregationTest method prepareTestData.

@Before
public void prepareTestData() throws ApplicationException {
    PostgreSQLUtil.loadFunction(browserDao, ADD_TO_LIBRARY);
    browserDao.getJdbcTemplate().execute("truncate music.artist cascade");
    browserDao.getJdbcTemplate().execute("truncate library.file cascade");
    submitFile(additionDao, UnittestLibraryUtil.getFile(artistName1, albumName1, trackName1));
    submitFile(additionDao, UnittestLibraryUtil.getFile(artistName1, albumName2, trackName1));
    List<Artist> artists = browserDao.getArtists();
    Assert.assertEquals(1, artists.size());
    artist1 = artists.get(0);
    List<Album> albums = browserDao.getAlbums(artists.get(0).getId(), true);
    Assert.assertEquals(2, albums.size());
    Assert.assertEquals(1, albums.get(0).getTrackIds().size());
    Assert.assertEquals(1, albums.get(1).getTrackIds().size());
    Collections.sort(albums, getAlbumComparator());
    album1 = albums.get(0);
    album2 = albums.get(1);
    track1 = browserDao.getTracks(album1.getTrackIds()).get(0);
    track2 = browserDao.getTracks(album2.getTrackIds()).get(0);
    user1 = new LastFmUser(userName1);
    lastFmDao.createOrUpdateLastFmUser(user1);
    user2 = new LastFmUser(userName2);
    lastFmDao.createOrUpdateLastFmUser(user2);
    artistInfoDao.createArtistInfo(asList(new ArtistInfo(new Artist(artistName1), "img")));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) Album(com.github.hakko.musiccabinet.domain.model.music.Album) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) Before(org.junit.Before)

Example 5 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class JdbcStarDaoTest method prepareTestData.

@Before
public void prepareTestData() throws ApplicationException {
    PostgreSQLUtil.loadFunction(starDao, ADD_TO_LIBRARY);
    starDao.getJdbcTemplate().execute("truncate music.artist cascade");
    starDao.getJdbcTemplate().execute("truncate library.file cascade");
    submitFile(additionDao, UnittestLibraryUtil.getFile(artistName1, albumName1, trackName1));
    submitFile(additionDao, UnittestLibraryUtil.getFile(artistName2, albumName2, trackName2));
    List<Artist> artists = browserDao.getArtists();
    Assert.assertEquals(2, artists.size());
    album1 = browserDao.getAlbums((artist1 = artists.get(0)).getId(), true).get(0);
    album2 = browserDao.getAlbums((artist2 = artists.get(1)).getId(), true).get(0);
    track1 = browserDao.getTracks(album1.getTrackIds()).get(0);
    track2 = browserDao.getTracks(album2.getTrackIds()).get(0);
    lastFmUser1 = new LastFmUser(user1);
    lastFmDao.createOrUpdateLastFmUser(lastFmUser1);
    lastFmUser2 = new LastFmUser(user2);
    lastFmDao.createOrUpdateLastFmUser(lastFmUser2);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Before(org.junit.Before)

Aggregations

LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)35 Test (org.junit.Test)14 Track (com.github.hakko.musiccabinet.domain.model.music.Track)9 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)7 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)7 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)7 NameValuePair (org.apache.http.NameValuePair)6 Scrobble (com.github.hakko.musiccabinet.domain.model.aggr.Scrobble)4 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)4 Before (org.junit.Before)4 Period (com.github.hakko.musiccabinet.domain.model.library.Period)3 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)3 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)3 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)3 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)3 ArrayList (java.util.ArrayList)3 UserStarredTrack (com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)2 UserTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists)2 File (com.github.hakko.musiccabinet.domain.model.library.File)2 Album (com.github.hakko.musiccabinet.domain.model.music.Album)2