use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class WSResponseTest method illegalControlCharactersAreChomped1.
/*
* Use an authentic response from last.fm, and assert that WSResponse
* silently replaces illegal XML characters in it.
*/
@Test
public void illegalControlCharactersAreChomped1() throws ApplicationException {
String ctrlCharResponse = new ResourceUtil(CTRL_CHAR_RESPONSE_1).getContent();
WSResponse response = new WSResponse(ctrlCharResponse);
// supposed to work, as WSResponse chomps illegal control characters
new ArtistInfoParserImpl(new StringUtil(response.getResponseBody()).getInputStream());
try {
// supposed to fail, as it hasn't passed WSResponse
new ArtistInfoParserImpl(new ResourceUtil(CTRL_CHAR_RESPONSE_1).getInputStream());
Assert.fail();
} catch (ApplicationException e) {
}
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class WSResponseTest method illegalControlCharactersAreChomped2.
/*
* Use an authentic response from last.fm, and assert that WSResponse
* silently replaces illegal XML characters in it.
*/
@Test
public void illegalControlCharactersAreChomped2() throws ApplicationException {
String ctrlCharResponse = new ResourceUtil(CTRL_CHAR_RESPONSE_2).getContent();
WSResponse response = new WSResponse(ctrlCharResponse);
// supposed to work, as WSResponse chomps illegal control characters
new ArtistTopTracksParserImpl(new StringUtil(response.getResponseBody()).getInputStream());
try {
// supposed to fail, as it hasn't passed WSResponse
new ArtistTopTracksParserImpl(new ResourceUtil(CTRL_CHAR_RESPONSE_2).getInputStream());
Assert.fail();
} catch (ApplicationException e) {
}
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class MusicBrainzServiceTest method handlesArtistFailureDuringUpdate.
@Test
public void handlesArtistFailureDuringUpdate() throws ApplicationException {
final String revName = reverse(artistName);
submitFile(additionDao, getFile(revName, albumName, trackName));
Mockito.when(service.artistQueryClient.get(revName)).thenThrow(new ApplicationException("Fail", new HttpResponseException(503, "Overloaded")));
service.updateDiscography();
List<MBAlbum> albums = service.getMissingAlbums(artistName, asList(TYPE_EP), null, -1, 0);
Assert.assertEquals(2, albums.size());
assertEquals("Switchblade / Cult of Luna", albums.get(0).getTitle());
assertEquals("Bodies / Recluse", albums.get(1).getTitle());
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class UpdateNowPlayingService method receive.
@SuppressWarnings("unchecked")
public void receive() {
while (true) {
Message<Scrobble> message = (Message<Scrobble>) scrobbleChannel.receive();
if (message == null || message.equals(FINISHED_MESSAGE)) {
break;
} else {
try {
LOG.debug("Try updating now playing.");
Scrobble scrobble = message.getPayload();
Scrobble previous = getPrevious(scrobble);
LOG.debug("previous: " + previous + ", scrobble = " + scrobble);
if (previous != null && tooClose(scrobble, previous) && scrobble.getTrack().getId() == previous.getTrack().getId()) {
LOG.debug("Same track was scrobbled just recently, ignore.");
} else {
addScrobble(scrobble);
WSResponse wsResponse = client.updateNowPlaying(message.getPayload());
LOG.debug("Successful: " + wsResponse.wasCallSuccessful());
LOG.debug("Response: " + wsResponse.getResponseBody());
}
} catch (ApplicationException e) {
LOG.warn("Could not update now playing at last.fm.", e);
}
}
}
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class UserTopArtistsService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
setTotalOperations(users.size() * Period.values().length);
List<UserTopArtists> userTopArtists = new ArrayList<>();
for (LastFmUser user : users) {
for (Period period : Period.values()) {
try {
WSResponse wsResponse = userTopArtistsClient.getUserTopArtists(user, period);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
UserTopArtistsParser parser = new UserTopArtistsParserImpl(stringUtil.getInputStream());
userTopArtists.add(new UserTopArtists(user, period, parser.getArtists()));
}
} catch (ApplicationException e) {
LOG.warn("Fetching top artist for " + user.getLastFmUsername() + ", " + period.getDescription() + " failed.", e);
}
addFinishedOperation();
}
}
userTopArtistsDao.createUserTopArtists(userTopArtists);
}
Aggregations