Search in sources :

Example 36 with Track

use of com.github.hakko.musiccabinet.domain.model.music.Track in project musiccabinet by hakko.

the class JdbcWebserviceHistoryDaoTest method importTrackSimilaritiesIsPossibleForCovers.

@Test
public void importTrackSimilaritiesIsPossibleForCovers() {
    Calltype SIMILAR = Calltype.TRACK_GET_SIMILAR;
    Track track1 = new Track("Daniel Johnston", "True Love Will Find You In The End");
    Track track2 = new Track("Headless Heroes", "True Love Will Find You In The End");
    WebserviceInvocation similarTrack1 = new WebserviceInvocation(SIMILAR, track1);
    WebserviceInvocation similarTrack2 = new WebserviceInvocation(SIMILAR, track2);
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(similarTrack1));
    assertTrue(dao.isWebserviceInvocationAllowed(similarTrack2));
    dao.logWebserviceInvocation(similarTrack1);
    assertFalse(dao.isWebserviceInvocationAllowed(similarTrack1));
    assertTrue(dao.isWebserviceInvocationAllowed(similarTrack2));
    dao.logWebserviceInvocation(similarTrack2);
    assertFalse(dao.isWebserviceInvocationAllowed(similarTrack1));
    assertFalse(dao.isWebserviceInvocationAllowed(similarTrack2));
}
Also used : Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 37 with Track

use of com.github.hakko.musiccabinet.domain.model.music.Track in project musiccabinet by hakko.

the class TrackPlayCountTest method validateConstructor.

@Test
public void validateConstructor() {
    String artistName = "madonna";
    String trackName = "material girl";
    int playCount = 30;
    TrackPlayCount tpc = new TrackPlayCount(artistName, trackName, playCount);
    Assert.assertEquals(tpc.getTrack(), new Track(artistName, trackName));
    Assert.assertEquals(tpc.getPlayCount(), playCount);
}
Also used : Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 38 with Track

use of com.github.hakko.musiccabinet.domain.model.music.Track 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 39 with Track

use of com.github.hakko.musiccabinet.domain.model.music.Track 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)

Example 40 with Track

use of com.github.hakko.musiccabinet.domain.model.music.Track in project musiccabinet by hakko.

the class JdbcArtistTopTracksDao method batchInsert.

private void batchInsert(Artist artist, List<Track> topTracks) {
    int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", artist.getName());
    String sql = "insert into music.artisttoptrack_import (artist_id, track_name, rank) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_id", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("track_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("rank", Types.SMALLINT));
    short rank = 0;
    for (Track t : topTracks) {
        batchUpdate.update(new Object[] { sourceArtistId, t.getName(), ++rank });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) Track(com.github.hakko.musiccabinet.domain.model.music.Track)

Aggregations

Track (com.github.hakko.musiccabinet.domain.model.music.Track)40 Test (org.junit.Test)23 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)9 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)9 UserStarredTrack (com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)6 File (com.github.hakko.musiccabinet.domain.model.library.File)5 Album (com.github.hakko.musiccabinet.domain.model.music.Album)5 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)5 UserLovedTracks (com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks)4 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)4 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)4 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)4 ArrayList (java.util.ArrayList)4 NameValuePair (org.apache.http.NameValuePair)4 Before (org.junit.Before)4 MetaData (com.github.hakko.musiccabinet.domain.model.library.MetaData)3 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)3 UserLovedTracksParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl)3 UnittestLibraryUtil.submitFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.submitFile)3 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)3