Search in sources :

Example 41 with ApplicationException

use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.

the class UserLovedTracksClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = UserLovedTracksClient.METHOD;
    final String limit = UserLovedTracksClient.LIMIT;
    final LastFmUser lastFmUser = new LastFmUser("rj");
    final short page = 4;
    new UserLovedTracksClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.USER_GET_LOVED_TRACKS, wi.getCallType());
            Assert.assertEquals(lastFmUser, wi.getUser());
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_LIMIT, limit);
            assertHasParameter(params, PARAM_USER, lastFmUser.getLastFmUsername());
            assertHasParameter(params, PARAM_PAGE, Short.toString(page));
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getUserLovedTracks(lastFmUser, page);
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 42 with ApplicationException

use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.

the class UserTopArtistsClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = UserTopArtistsClient.METHOD;
    final String lastFmUser = "arnathalon";
    final Period period = Period.OVERALL;
    new UserTopArtistsClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.USER_GET_TOP_ARTISTS, wi.getCallType());
            Assert.assertEquals(lastFmUser, wi.getUser().getLastFmUsername());
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_USER, lastFmUser);
            assertHasParameter(params, PARAM_PERIOD, period.getDescription());
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getUserTopArtists(new LastFmUser(lastFmUser), period);
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) Period(com.github.hakko.musiccabinet.domain.model.library.Period) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 43 with ApplicationException

use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.

the class AbstractMusicBrainzClientTest method doesntLogFailedCall.

@Test
@SuppressWarnings("unchecked")
public void doesntLogFailedCall() throws Exception {
    TestMusicBrainzClient client = getClient();
    when(client.getHttpClient().execute(any(HttpUriRequest.class), any(ResponseHandler.class))).thenThrow(new IOException("Interrupted"));
    WebserviceInvocation invocation = client.getInvocation();
    try {
        client.get();
    } catch (ApplicationException e) {
        verify(client.getWebserviceHistoryService(), never()).logWebserviceInvocation(invocation);
        return;
    }
    Assert.fail();
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ResponseHandler(org.apache.http.client.ResponseHandler) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)43 Test (org.junit.Test)20 NameValuePair (org.apache.http.NameValuePair)18 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)14 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)11 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)11 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)10 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)10 ArrayList (java.util.ArrayList)8 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)7 IOException (java.io.IOException)6 Track (com.github.hakko.musiccabinet.domain.model.music.Track)4 ArtistUserTag (com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag)2 Scrobble (com.github.hakko.musiccabinet.domain.model.aggr.Scrobble)2 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)2 Period (com.github.hakko.musiccabinet.domain.model.library.Period)2 Album (com.github.hakko.musiccabinet.domain.model.music.Album)2 MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)2 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)2 ArtistInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl)2