Search in sources :

Example 1 with Calltype

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

the class JdbcWebserviceHistoryDaoTest method importPageFromPersonLibraryNotPossibleTwice.

@Test
public void importPageFromPersonLibraryNotPossibleTwice() {
    Calltype LIB = Calltype.GET_SCROBBLED_TRACKS;
    short page3 = 3;
    short page4 = 4;
    WebserviceInvocation libPage3 = new WebserviceInvocation(LIB, page3);
    WebserviceInvocation libPage4 = new WebserviceInvocation(LIB, page4);
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(libPage3));
    assertTrue(dao.isWebserviceInvocationAllowed(libPage4));
    dao.logWebserviceInvocation(libPage4);
    assertTrue(dao.isWebserviceInvocationAllowed(libPage3));
    assertFalse(dao.isWebserviceInvocationAllowed(libPage4));
    dao.logWebserviceInvocation(libPage3);
    assertFalse(dao.isWebserviceInvocationAllowed(libPage3));
    assertFalse(dao.isWebserviceInvocationAllowed(libPage4));
}
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 2 with Calltype

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

the class JdbcWebserviceHistoryDaoTest method identifiesArtistsWithoutInvocations.

@Test
public void identifiesArtistsWithoutInvocations() {
    deleteLibraryTracks();
    deleteWebserviceInvocations();
    File file = UnittestLibraryUtil.getFile("Madonna", null, "Jump");
    UnittestLibraryUtil.submitFile(additionDao, file);
    final Calltype INFO = ARTIST_GET_INFO, TOP_TRACKS = ARTIST_GET_TOP_TRACKS;
    final String MADONNA = file.getMetadata().getArtist();
    List<String> artistInfo, artistTopTracks;
    artistInfo = dao.getArtistNamesWithNoInvocations(INFO);
    artistTopTracks = dao.getArtistNamesWithNoInvocations(TOP_TRACKS);
    Assert.assertNotNull(artistInfo);
    Assert.assertNotNull(artistTopTracks);
    Assert.assertTrue(artistInfo.contains(MADONNA));
    Assert.assertTrue(artistTopTracks.contains(MADONNA));
    dao.logWebserviceInvocation(new WebserviceInvocation(INFO, new Artist(MADONNA)));
    artistInfo = dao.getArtistNamesWithNoInvocations(INFO);
    artistTopTracks = dao.getArtistNamesWithNoInvocations(TOP_TRACKS);
    Assert.assertFalse(artistInfo.contains(MADONNA));
    Assert.assertTrue(artistTopTracks.contains(MADONNA));
    dao.logWebserviceInvocation(new WebserviceInvocation(TOP_TRACKS, new Artist(MADONNA)));
    artistInfo = dao.getArtistNamesWithNoInvocations(INFO);
    artistTopTracks = dao.getArtistNamesWithNoInvocations(TOP_TRACKS);
    Assert.assertFalse(artistInfo.contains(MADONNA));
    Assert.assertFalse(artistTopTracks.contains(MADONNA));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) File(com.github.hakko.musiccabinet.domain.model.library.File) Test(org.junit.Test)

Example 3 with Calltype

use of com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype 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 4 with Calltype

use of com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype 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 5 with Calltype

use of com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype 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)

Aggregations

WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)19 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)19 Test (org.junit.Test)19 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)7 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)3 Track (com.github.hakko.musiccabinet.domain.model.music.Track)3 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)2 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1