Search in sources :

Example 46 with WebserviceInvocation

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

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

Example 48 with WebserviceInvocation

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

the class AlbumInfoClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = AlbumInfoClient.METHOD;
    final String artistName = "The Beatles";
    final String albumName = "Sergeant Pepper's Lonely Hearts Club Band";
    new AlbumInfoClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ALBUM_GET_INFO, wi.getCallType());
            Assert.assertTrue(albumName.equals(wi.getAlbum().getName()));
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_ARTIST, artistName);
            assertHasParameter(params, PARAM_ALBUM, albumName);
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getAlbumInfo(new Album(artistName, albumName));
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) Album(com.github.hakko.musiccabinet.domain.model.music.Album) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 49 with WebserviceInvocation

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

the class ArtistSimilarityClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = ArtistSimilarityClient.METHOD;
    final String artistName = "madonna";
    new ArtistSimilarityClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ARTIST_GET_SIMILAR, wi.getCallType());
            Assert.assertTrue(artistName.equals(wi.getArtist().getName()));
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_ARTIST, artistName);
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getArtistSimilarity(new Artist(artistName));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 50 with WebserviceInvocation

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

the class ArtistTopTracksClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = ArtistTopTracksClient.METHOD;
    final String artistName = "madonna";
    new ArtistTopTracksClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ARTIST_GET_TOP_TRACKS, wi.getCallType());
            Assert.assertTrue(artistName.equals(wi.getArtist().getName()));
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_ARTIST, artistName);
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getTopTracks(new Artist(artistName));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Aggregations

WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)53 Test (org.junit.Test)36 NameValuePair (org.apache.http.NameValuePair)26 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)19 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)19 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)16 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)13 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)11 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)7 Track (com.github.hakko.musiccabinet.domain.model.music.Track)4 ArrayList (java.util.ArrayList)4 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)3 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)3 HttpClient (org.apache.http.client.HttpClient)2 LastFmDao (com.github.hakko.musiccabinet.dao.LastFmDao)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 Period (com.github.hakko.musiccabinet.domain.model.library.Period)1 Album (com.github.hakko.musiccabinet.domain.model.music.Album)1 ThrottleService (com.github.hakko.musiccabinet.service.lastfm.ThrottleService)1 IOException (java.io.IOException)1