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));
}
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));
}
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);
}
}
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));
}
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);
}
Aggregations