Search in sources :

Example 11 with WebserviceInvocation

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

the class JdbcWebserviceHistoryDaoTest method oldInvocationsAreIgnored.

@Test
public void oldInvocationsAreIgnored() {
    Calltype SIMILAR = Calltype.TRACK_GET_SIMILAR;
    Track track = new Track("Red Sparowes", "Finally, As That Blazing Sun Shone Down Upon Us, Did We Know That True Enemy Was the Voice of Blind Idolatry; and Only Then Did We Begin to Think for Ourselves.");
    WebserviceInvocation similarTrack = new WebserviceInvocation(SIMILAR, track);
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(similarTrack));
    dao.logWebserviceInvocation(similarTrack);
    assertFalse(dao.isWebserviceInvocationAllowed(similarTrack));
    // make the invocation age in database, by updating it.
    DateTime dateTime = new DateTime();
    JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
    for (int days = 1; days <= 14; days++) {
        jdbcTemplate.update("update library.webservice_history set invocation_time = ?", new Object[] { dateTime.minusDays(days).toDate() });
        boolean isAllowed = dao.isWebserviceInvocationAllowed(similarTrack);
        boolean cacheIsInvalid = days > SIMILAR.getDaysToCache();
        assertTrue(isAllowed == cacheIsInvalid);
    }
}
Also used : Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Track(com.github.hakko.musiccabinet.domain.model.music.Track) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 12 with WebserviceInvocation

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

the class JdbcWebserviceHistoryDaoTest method tagHistoryAllowanceIsBasedOnId.

@Test
public void tagHistoryAllowanceIsBasedOnId() {
    tagDao.createTags(Arrays.asList("disco", "sludge"));
    Tag tag1 = tagDao.getTags().get(0);
    Tag tag2 = tagDao.getTags().get(1);
    Calltype TOP_ARTISTS = Calltype.TAG_GET_TOP_ARTISTS;
    WebserviceInvocation topArtists1 = new WebserviceInvocation(TOP_ARTISTS, tag1);
    WebserviceInvocation topArtists2 = new WebserviceInvocation(TOP_ARTISTS, tag2);
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists2);
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists2);
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists1);
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists1));
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
}
Also used : Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) Test(org.junit.Test)

Example 13 with WebserviceInvocation

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

the class JdbcWebserviceHistoryDaoTest method clearsLanguageSpecificWebserviceInvocations.

@Test
public void clearsLanguageSpecificWebserviceInvocations() {
    Artist artist = new Artist("ABBA");
    WebserviceInvocation wiInfo = new WebserviceInvocation(ARTIST_GET_INFO, artist);
    WebserviceInvocation wiSimilar = new WebserviceInvocation(ARTIST_GET_SIMILAR, artist);
    dao.logWebserviceInvocation(wiInfo);
    dao.logWebserviceInvocation(wiSimilar);
    Assert.assertFalse(dao.isWebserviceInvocationAllowed(wiInfo));
    Assert.assertFalse(dao.isWebserviceInvocationAllowed(wiSimilar));
    dao.clearLanguageSpecificWebserviceInvocations();
    Assert.assertTrue(dao.isWebserviceInvocationAllowed(wiInfo));
    Assert.assertFalse(dao.isWebserviceInvocationAllowed(wiSimilar));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 14 with WebserviceInvocation

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

the class JdbcWebserviceHistoryDaoTest method artistNullThrowsException.

@Test(expected = IllegalArgumentException.class)
public void artistNullThrowsException() {
    Calltype SIMILAR = Calltype.TRACK_GET_SIMILAR;
    new WebserviceInvocation(SIMILAR, (Artist) null);
}
Also used : Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 15 with WebserviceInvocation

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

the class JdbcWebserviceHistoryDaoTest method differentUsersDontInterfere.

@Test
public void differentUsersDontInterfere() {
    Calltype TOP_ARTISTS = Calltype.USER_GET_TOP_ARTISTS;
    LastFmUser user1 = new LastFmUser("user1");
    LastFmUser user2 = new LastFmUser("user2");
    WebserviceInvocation topArtists1 = new WebserviceInvocation(TOP_ARTISTS, user1, OVERALL.getDays());
    WebserviceInvocation topArtists2 = new WebserviceInvocation(TOP_ARTISTS, user2, OVERALL.getDays());
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists2);
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
}
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)

Aggregations

WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)53 Test (org.junit.Test)36 NameValuePair (org.apache.http.NameValuePair)26 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)19 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)19 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)16 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)13 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)11 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)7 Track (com.github.hakko.musiccabinet.domain.model.music.Track)4 ArrayList (java.util.ArrayList)4 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)3 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)3 HttpClient (org.apache.http.client.HttpClient)2 LastFmDao (com.github.hakko.musiccabinet.dao.LastFmDao)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 Period (com.github.hakko.musiccabinet.domain.model.library.Period)1 Album (com.github.hakko.musiccabinet.domain.model.music.Album)1 ThrottleService (com.github.hakko.musiccabinet.service.lastfm.ThrottleService)1 IOException (java.io.IOException)1