Search in sources :

Example 1 with WebserviceHistoryService

use of com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService in project musiccabinet by hakko.

the class TagUpdateServiceTest method updatesWithinThresholdsAreIgnored.

@Test
public void updatesWithinThresholdsAreIgnored() throws ApplicationException {
    ArtistTopTagsDao artistTopTagsDao = mock(ArtistTopTagsDao.class);
    tagUpdateService.setArtistTopTagsDao(artistTopTagsDao);
    setClientResponse(responseOK);
    TagUpdateClient tagUpdateClient = tagUpdateService.tagUpdateClient;
    WebserviceHistoryService historyService = mock(WebserviceHistoryService.class);
    tagUpdateService.setWebserviceHistoryService(historyService);
    tagUpdateService.register(artist1Addition);
    tagUpdateService.register(artist2Removal);
    tagUpdateService.register(artist3Addition);
    tagUpdateService.updateTags();
    verify(tagUpdateClient, times(1)).updateTag(artist1Addition);
    verify(tagUpdateClient, times(1)).updateTag(artist2Removal);
    verify(tagUpdateClient, times(0)).updateTag(artist3Addition);
}
Also used : TagUpdateClient(com.github.hakko.musiccabinet.ws.lastfm.TagUpdateClient) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) ArtistTopTagsDao(com.github.hakko.musiccabinet.dao.ArtistTopTagsDao) Test(org.junit.Test)

Example 2 with WebserviceHistoryService

use of com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService in project musiccabinet by hakko.

the class TagUpdateServiceTest method duplicateUpdatesAreRemoved.

@Test
public void duplicateUpdatesAreRemoved() throws ApplicationException {
    tagUpdateService.failedUpdates.clear();
    setClientResponse(responseFail);
    ArtistTopTagsDao artistTopTagsDao = mock(ArtistTopTagsDao.class);
    tagUpdateService.setArtistTopTagsDao(artistTopTagsDao);
    WebserviceHistoryService historyService = mock(WebserviceHistoryService.class);
    tagUpdateService.setWebserviceHistoryService(historyService);
    tagUpdateService.register(artist1Addition);
    tagUpdateService.register(artist1Addition);
    tagUpdateService.register(artist1Addition);
    tagUpdateService.updateTags();
    // tag updates and web service blocking are instantaneous
    verify(historyService, times(3)).blockWebserviceInvocation(artist1.getId(), ARTIST_GET_TOP_TAGS);
    verify(artistTopTagsDao, times(3)).updateTopTag(artist1.getId(), artist1Addition.getTagName(), artist1Addition.getTagCount());
    // dupes removed, one item updated and put on fail queue
    assertEquals(1, tagUpdateService.failedUpdates.size());
}
Also used : WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) ArtistTopTagsDao(com.github.hakko.musiccabinet.dao.ArtistTopTagsDao) Test(org.junit.Test)

Example 3 with WebserviceHistoryService

use of com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService 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)

Example 4 with WebserviceHistoryService

use of com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService 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 5 with WebserviceHistoryService

use of com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService 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)

Aggregations

WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)16 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)12 Test (org.junit.Test)12 NameValuePair (org.apache.http.NameValuePair)11 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)10 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)5 HttpClient (org.apache.http.client.HttpClient)4 ArtistTopTagsDao (com.github.hakko.musiccabinet.dao.ArtistTopTagsDao)2 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)2 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)1 Period (com.github.hakko.musiccabinet.domain.model.library.Period)1 Album (com.github.hakko.musiccabinet.domain.model.music.Album)1 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)1 Track (com.github.hakko.musiccabinet.domain.model.music.Track)1 ThrottleService (com.github.hakko.musiccabinet.service.lastfm.ThrottleService)1 TagUpdateClient (com.github.hakko.musiccabinet.ws.lastfm.TagUpdateClient)1 ArrayList (java.util.ArrayList)1 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1