Search in sources :

Example 1 with ThrottleService

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

the class ScrobbledTracksServiceTest method getScrobbledTracksClient.

@SuppressWarnings("unchecked")
private ScrobbledTracksClient getScrobbledTracksClient() throws IOException {
    // create a HistoryDao that allows all calls
    WebserviceHistoryService historyService = mock(WebserviceHistoryService.class);
    when(historyService.isWebserviceInvocationAllowed(Mockito.any(WebserviceInvocation.class))).thenReturn(true);
    // create a HTTP client that always returns sampled scrobbled tracks from last.fm
    HttpClient httpClient = mock(HttpClient.class);
    ClientConnectionManager connectionManager = mock(ClientConnectionManager.class);
    when(httpClient.getConnectionManager()).thenReturn(connectionManager);
    String httpResponse = new ResourceUtil(SCROBBLED_TRACKS).getContent();
    when(httpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).thenReturn(httpResponse);
    // create a client out of the components above
    ScrobbledTracksClient stClient = new ScrobbledTracksClient();
    stClient.setWebserviceHistoryService(historyService);
    stClient.setHttpClient(httpClient);
    // create a throttling service that allows calls at any rate
    ThrottleService throttleService = mock(ThrottleService.class);
    stClient.setThrottleService(throttleService);
    return stClient;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ResponseHandler(org.apache.http.client.ResponseHandler) HttpClient(org.apache.http.client.HttpClient) ThrottleService(com.github.hakko.musiccabinet.service.lastfm.ThrottleService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) ScrobbledTracksClient(com.github.hakko.musiccabinet.ws.lastfm.ScrobbledTracksClient) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager)

Example 2 with ThrottleService

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

Aggregations

WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)2 ThrottleService (com.github.hakko.musiccabinet.service.lastfm.ThrottleService)2 HttpClient (org.apache.http.client.HttpClient)2 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)2 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)1 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 ScrobbledTracksClient (com.github.hakko.musiccabinet.ws.lastfm.ScrobbledTracksClient)1 ArrayList (java.util.ArrayList)1 NameValuePair (org.apache.http.NameValuePair)1 ResponseHandler (org.apache.http.client.ResponseHandler)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1