Search in sources :

Example 1 with WebserviceInvocation

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

the class ArtistTopTracksServiceTest method artistTopTracksUpdateUpdatesAllArtists.

@Test
public void artistTopTracksUpdateUpdatesAllArtists() throws ApplicationException, IOException {
    clearLibraryAndAddCherTrack();
    WebserviceInvocation wi = new WebserviceInvocation(ARTIST_GET_TOP_TRACKS, new Artist(artistName));
    Assert.assertTrue(webserviceHistoryService.isWebserviceInvocationAllowed(wi));
    Set<String> artists = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_TOP_TRACKS);
    Assert.assertNotNull(artists);
    Assert.assertEquals(1, artists.size());
    Assert.assertTrue(artists.contains(artistName));
    ArtistTopTracksService artistTopTracksService = new ArtistTopTracksService();
    artistTopTracksService.setArtistTopTracksClient(getArtistTopTracksClient(webserviceHistoryService));
    artistTopTracksService.setArtistTopTracksDao(artistTopTracksDao);
    artistTopTracksService.setWebserviceHistoryService(webserviceHistoryService);
    artistTopTracksService.updateSearchIndex();
    Assert.assertFalse(webserviceHistoryService.isWebserviceInvocationAllowed(wi));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 2 with WebserviceInvocation

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

the class AbstractWSGetClientTest method getTestWSClient.

/*
	 * Help method to create a base TestWSClient.
	 */
private TestWSGetClient getTestWSClient(boolean allowCalls) {
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    ClientConnectionManager connectionManager = Mockito.mock(ClientConnectionManager.class);
    when(httpClient.getConnectionManager()).thenReturn(connectionManager);
    WebserviceHistoryService historyService = mock(WebserviceHistoryService.class);
    when(historyService.isWebserviceInvocationAllowed(Mockito.any(WebserviceInvocation.class))).thenReturn(allowCalls);
    WebserviceInvocation invocation = mock(WebserviceInvocation.class);
    List<NameValuePair> params = new ArrayList<>();
    TestWSGetClient testClient = new TestWSGetClient(invocation, params);
    testClient.setWebserviceHistoryService(historyService);
    testClient.setHttpClient(httpClient);
    // create a throttling service that allows calls at any rate
    ThrottleService throttleService = mock(ThrottleService.class);
    testClient.setThrottleService(throttleService);
    return testClient;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) ThrottleService(com.github.hakko.musiccabinet.service.lastfm.ThrottleService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager)

Example 3 with WebserviceInvocation

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

the class ArtistInfoClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = ArtistInfoClient.METHOD;
    final String artistName = "madonna";
    final String lang = Locale.FRANCE.getLanguage();
    new ArtistInfoClient() {

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

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getArtistInfo(new Artist(artistName), lang);
}
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 4 with WebserviceInvocation

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

the class ArtistTopTagsClientTest method validateParameters.

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

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ARTIST_GET_TOP_TAGS, 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);
        }
    }.getTopTags(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 5 with WebserviceInvocation

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

the class GroupWeeklyArtistChartClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = GroupWeeklyArtistChartClient.METHOD;
    final String lastFmGroup = "Brainwashed";
    new GroupWeeklyArtistChartClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.GROUP_WEEKLY_ARTIST_CHART, wi.getCallType());
            Assert.assertEquals(lastFmGroup, wi.getGroup().getName());
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_GROUP, lastFmGroup);
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getWeeklyArtistChart(new LastFmGroup(lastFmGroup));
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) LastFmGroup(com.github.hakko.musiccabinet.domain.model.library.LastFmGroup) 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