Search in sources :

Example 16 with LastFmUser

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

the class JdbcMusicBrainzAlbumDaoTest method findsAlbumsMissingFromLibraryWithRecentlyPlayedFilter.

@Test
public void findsAlbumsMissingFromLibraryWithRecentlyPlayedFilter() {
    List<MBAlbum> albums = albumDao.getMissingAlbums(null, null, USER, 10, 0);
    assertEquals(0, albums.size());
    LastFmUser lastFmUser = new LastFmUser(USER);
    lastFmDao.createOrUpdateLastFmUser(lastFmUser);
    submitFile(additionDao, getFile(artist.getName(), UNKNOWN, UNKNOWN));
    Track track = browserDao.getTracks(browserDao.getRandomTrackIds(1)).get(0);
    playCountDao.addPlayCount(lastFmUser, track);
    albums = albumDao.getMissingAlbums(null, null, USER, 10, 0);
    assertEquals(2, albums.size());
}
Also used : LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) MBAlbum(com.github.hakko.musiccabinet.domain.model.music.MBAlbum) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 17 with LastFmUser

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

the class JdbcPlayCountDaoTest method prepareTestData.

@Before
public void prepareTestData() throws ApplicationException {
    dao.getJdbcTemplate().execute("truncate music.lastfmuser cascade");
    dao.getJdbcTemplate().execute("truncate library.file cascade");
    dao.getJdbcTemplate().execute("truncate music.artist cascade");
    user1 = new LastFmUser(username1 = "user1");
    user2 = new LastFmUser(username2 = "user2");
    lastFmDao.createOrUpdateLastFmUser(user1);
    lastFmDao.createOrUpdateLastFmUser(user2);
    File file1 = UnittestLibraryUtil.getFile("artist1", "album1", "title1");
    File file2 = UnittestLibraryUtil.getFile("artist1", "album1", "title2");
    File file3 = UnittestLibraryUtil.getFile("artist2", "album2", "title3");
    submitFile(additionDao, Arrays.asList(file1, file2, file3));
    List<Artist> artists = browserDao.getArtists();
    assertEquals(2, artists.size());
    artist1 = artists.get(0);
    artist2 = artists.get(1);
    List<Album> albums1 = browserDao.getAlbums(artist1.getId(), true);
    assertEquals(1, albums1.size());
    album1 = albums1.get(0);
    List<Album> albums2 = browserDao.getAlbums(artist2.getId(), true);
    assertEquals(1, albums2.size());
    album2 = albums2.get(0);
    List<Track> tracks1 = browserDao.getTracks(album1.getTrackIds());
    Collections.sort(tracks1, trackComparator);
    assertEquals(2, tracks1.size());
    track1a = tracks1.get(0);
    track1b = tracks1.get(1);
    List<Track> tracks2 = browserDao.getTracks(album2.getTrackIds());
    assertEquals(1, tracks2.size());
    track2 = tracks2.get(0);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Album(com.github.hakko.musiccabinet.domain.model.music.Album) 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) Before(org.junit.Before)

Example 18 with LastFmUser

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

the class JdbcWebserviceHistoryDaoTest method importUserRelatedDataNotPossibleTwice.

@Test
public void importUserRelatedDataNotPossibleTwice() {
    Calltype TOP_ARTISTS = Calltype.USER_GET_TOP_ARTISTS;
    LastFmUser user = new LastFmUser("arnathalon");
    WebserviceInvocation topArtists = new WebserviceInvocation(TOP_ARTISTS, user, OVERALL.getDays());
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists));
    dao.logWebserviceInvocation(topArtists);
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists));
}
Also used : Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 19 with LastFmUser

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

the class TrackUnLoveClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = TrackUnLoveClient.METHOD;
    final String lastFmUser = "arnathalon";
    final String sessionKey = "sessionkey";
    final String artist = "artist";
    final String track = "track";
    new TrackUnLoveClient() {

        @Override
        protected WSResponse executeWSRequest(List<NameValuePair> params) throws ApplicationException {
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_TRACK, track);
            assertHasParameter(params, PARAM_ARTIST, artist);
            assertHasParameter(params, PARAM_SK, sessionKey);
            return null;
        }
    }.unlove(new Track(artist, track), new LastFmUser(lastFmUser, sessionKey));
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 20 with LastFmUser

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

the class UpdateNowPlayingClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final Track track = browserDao.getTracks(browserDao.getRandomTrackIds(1)).get(0);
    final LastFmUser user = new LastFmUser("lastFmUser", "sessionKey");
    final Scrobble scrobble = new Scrobble(user, track, false);
    final String method = UpdateNowPlayingClient.METHOD;
    new UpdateNowPlayingClient() {

        @Override
        protected WSResponse executeWSRequest(List<NameValuePair> params) throws ApplicationException {
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_ARTIST, track.getArtist().getName());
            assertHasParameter(params, PARAM_ALBUM, track.getMetaData().getAlbum());
            assertHasParameter(params, PARAM_TRACK, track.getName());
            assertHasParameter(params, PARAM_DURATION, "" + track.getMetaData().getDuration());
            assertHasParameter(params, PARAM_SK, user.getSessionKey());
            return null;
        }
    }.updateNowPlaying(scrobble);
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Scrobble(com.github.hakko.musiccabinet.domain.model.aggr.Scrobble) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

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