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