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));
}
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;
}
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);
}
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));
}
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));
}
Aggregations