Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing need for user agent to be passed in to template constructors…

… - now generating it automatically based on pom.version
  • Loading branch information...
commit 5003a418bea9bfb5c9f012631c89284b41353e47 1 parent d6ad295
@michaellavelle authored
View
6 pom.xml
@@ -82,5 +82,11 @@
<version>2.5.1</version>
</plugin>
</plugins>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
</build>
</project>
View
10 src/main/java/org/springframework/social/lastfm/api/impl/LastFmTemplate.java
@@ -18,6 +18,8 @@
import java.util.List;
import org.codehaus.jackson.map.ObjectMapper;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
@@ -70,8 +72,8 @@ private void initSubApis(LastFmAccessGrant lastFmAccessGrant,
* will support those operations. Those operations requiring authentication
* will throw {@link NotAuthorizedException}.
*/
- public LastFmTemplate(String userAgent, String apiKey) {
- super(userAgent);
+ public LastFmTemplate(String apiKey) {
+ super();
initialize(null, apiKey, null);
}
@@ -83,9 +85,9 @@ public LastFmTemplate(String userAgent, String apiKey) {
* An access token given by LastFm after a successful
* authentication
*/
- public LastFmTemplate(String userAgent,
+ public LastFmTemplate(
LastFmAccessGrant lastFmAccessGrant, String apiKey, String secret) {
- super(userAgent, lastFmAccessGrant);
+ super(lastFmAccessGrant);
initialize(lastFmAccessGrant, apiKey, secret);
}
View
28 src/main/java/org/springframework/social/lastfm/api/impl/UserAgentHelper.java
@@ -0,0 +1,28 @@
+package org.springframework.social.lastfm.api.impl;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.springframework.core.io.ClassPathResource;
+
+public class UserAgentHelper {
+
+ public static String getUserAgent()
+ {
+ String pomVersion = getPomVersion();
+ return "spring-social-lastfm" + (pomVersion == null ? "" : "/" + pomVersion);
+ }
+
+ private static String getPomVersion() {
+ Properties properties = new Properties();
+ try {
+ properties.load(new ClassPathResource("project.properties").getInputStream());
+ return properties.getProperty("pom.version");
+
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+
+}
View
20 src/main/java/org/springframework/social/lastfm/auth/AbstractLastFmAuthApiBinding.java
@@ -15,11 +15,15 @@
*/
package org.springframework.social.lastfm.auth;
+import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Properties;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequestFactory;
@@ -29,6 +33,7 @@
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.social.ApiBinding;
+import org.springframework.social.lastfm.api.impl.UserAgentHelper;
import org.springframework.social.lastfm.connect.RestTemplateWithHeaders;
import org.springframework.social.support.ClientHttpRequestFactorySelector;
import org.springframework.web.client.RestTemplate;
@@ -41,21 +46,21 @@
public abstract class AbstractLastFmAuthApiBinding implements ApiBinding {
private LastFmAccessGrant lastFmAccessGrant;
- private final String userAgent;
private final RestTemplate restTemplate;
+
+
/**
* Constructs the API template without user authorization. This is useful
* for accessing operations on a provider's API that do not require user
* authorization.
*/
- protected AbstractLastFmAuthApiBinding(String userAgent) {
- this.userAgent = userAgent;
+ protected AbstractLastFmAuthApiBinding() {
+
this.lastFmAccessGrant = null;
HttpHeaders headers = new HttpHeaders();
- headers.add("User-Agent", userAgent);
-
+ headers.add("User-Agent", UserAgentHelper.getUserAgent());
restTemplate = new RestTemplateWithHeaders(
ClientHttpRequestFactorySelector.getRequestFactory(), headers);
restTemplate.setMessageConverters(getMessageConverters(true));
@@ -70,12 +75,11 @@ protected AbstractLastFmAuthApiBinding(String userAgent) {
* @param accessToken
* the access token
*/
- protected AbstractLastFmAuthApiBinding(String userAgent,
+ protected AbstractLastFmAuthApiBinding(
LastFmAccessGrant lastFmAccessGrant) {
this.lastFmAccessGrant = lastFmAccessGrant;
- this.userAgent = userAgent;
HttpHeaders headers = new HttpHeaders();
- headers.add("User-Agent", userAgent);
+ headers.add("User-Agent", UserAgentHelper.getUserAgent());
restTemplate = new RestTemplateWithHeaders(
ClientHttpRequestFactorySelector.getRequestFactory(), headers);
View
33 src/main/java/org/springframework/social/lastfm/connect/LastFmAuthTemplate.java
@@ -1,5 +1,6 @@
package org.springframework.social.lastfm.connect;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
@@ -7,8 +8,10 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Map.Entry;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.converter.FormHttpMessageConverter;
@@ -42,20 +45,17 @@
private final RestTemplate restTemplate;
- private final String userAgent;
- public LastFmAuthTemplate(String clientId, String clientSecret,
- String userAgent) {
+ public LastFmAuthTemplate(String clientId, String clientSecret) {
this(clientId, clientSecret, "http://www.last.fm/api/auth/",
- "http://ws.audioscrobbler.com/2.0/", userAgent);
+ "http://ws.audioscrobbler.com/2.0/");
}
public LastFmAuthTemplate(String clientId, String clientSecret,
- String authorizeUrl, String accessTokenUrl, String userAgent) {
+ String authorizeUrl, String accessTokenUrl) {
Assert.notNull(clientId, "The clientId property cannot be null");
Assert.notNull(clientSecret, "The clientSecret property cannot be null");
Assert.notNull(authorizeUrl, "The authorizeUrl property cannot be null");
- Assert.notNull(userAgent, "The userAgent property cannot be null");
Assert.notNull(accessTokenUrl,
"The accessTokenUrl property cannot be null");
@@ -64,7 +64,6 @@ public LastFmAuthTemplate(String clientId, String clientSecret,
String clientInfo = "?api_key=" + formEncode(clientId);
this.authorizeUrl = authorizeUrl + clientInfo;
this.accessTokenUrl = accessTokenUrl;
- this.userAgent = userAgent;
this.restTemplate = createRestTemplate(true);
}
@@ -98,6 +97,24 @@ public LastFmAccessGrant exchangeForAccess(String token,
// subclassing hooks
+ private String getUserAgent()
+ {
+ String pomVersion = getPomVersion();
+ return "spring-social-lastfm" + (pomVersion == null ? "" : "/" + pomVersion);
+ }
+
+ private String getPomVersion() {
+ Properties properties = new Properties();
+ try {
+ properties.load(new ClassPathResource("project.properties").getInputStream());
+ return properties.getProperty("pom.version");
+
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+
/**
* Creates the {@link RestTemplate} used to communicate with the provider's
* OAuth 2 API. This implementation creates a RestTemplate with a minimal
@@ -109,7 +126,7 @@ public LastFmAccessGrant exchangeForAccess(String token,
*/
protected RestTemplate createRestTemplate(boolean json) {
HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.add("User-Agent", userAgent);
+ httpHeaders.add("User-Agent", getUserAgent());
RestTemplate restTemplate = new RestTemplateWithHeaders(
ClientHttpRequestFactorySelector.getRequestFactory(),
httpHeaders);
View
3  src/main/java/org/springframework/social/lastfm/connect/LastFmConnectionFactory.java
@@ -41,8 +41,7 @@
* the LastFm Api clientSecret
*/
public LastFmConnectionFactory(String clientId, String clientSecret) {
- super("lastfm", new LastFmServiceProvider(clientId, clientSecret,
- "spring-social-lastfm/1.0.0-SNAPSHOT"), new LastFmAdapter());
+ super("lastfm", new LastFmServiceProvider(clientId, clientSecret), new LastFmAdapter());
}
/**
View
10 src/main/java/org/springframework/social/lastfm/connect/LastFmServiceProvider.java
@@ -29,7 +29,6 @@
private String clientId;
private String secret;
- private String userAgent;
private final LastFmAuthOperations lastFmAuthOperations;
@@ -44,13 +43,10 @@ public LastFmServiceProvider(LastFmAuthOperations lastFmAuthOperations) {
this.lastFmAuthOperations = lastFmAuthOperations;
}
- public LastFmServiceProvider(String clientId, String clientSecret,
- String userAgent) {
- lastFmAuthOperations = new LastFmAuthTemplate(clientId, clientSecret,
- userAgent);
+ public LastFmServiceProvider(String clientId, String clientSecret) {
+ lastFmAuthOperations = new LastFmAuthTemplate(clientId, clientSecret);
this.clientId = clientId;
this.secret = clientSecret;
- this.userAgent = userAgent;
}
// implementing OAuth2ServiceProvider
@@ -60,7 +56,7 @@ public final LastFmAuthOperations getLastFmAuthOperations() {
}
public LastFm getApi(LastFmAccessGrant lastFmAccessGrant) {
- return new LastFmTemplate(userAgent, lastFmAccessGrant, clientId,
+ return new LastFmTemplate(lastFmAccessGrant, clientId,
secret);
}
View
2  ...ain/java/org/springframework/social/lastfm/pseudooauth2/connect/LastFmPseudoOAuth2ConnectionFactory.java
@@ -38,7 +38,7 @@
public LastFmPseudoOAuth2ConnectionFactory(String clientId,
String clientSecret) {
super("lastfm", new LastFmPseudoOAuth2ServiceProvider(clientId,
- clientSecret, "spring-social-lastfm/1.0.0-SNAPSHOT"),
+ clientSecret),
new LastFmAdapter());
this.lastFmConnectionFactory = new LastFmConnectionFactory(clientId,
clientSecret);
View
7 src/main/java/org/springframework/social/lastfm/pseudooauth2/connect/LastFmPseudoOAuth2ServiceProvider.java
@@ -31,19 +31,18 @@
private String userAgent;
public LastFmPseudoOAuth2ServiceProvider(String clientId,
- String clientSecret, String userAgent) {
+ String clientSecret) {
super(new LastFmPseudoOAuth2Template(clientId, new LastFmAuthTemplate(
- clientId, clientSecret, userAgent)));
+ clientId, clientSecret)));
this.clientId = clientId;
this.secret = clientSecret;
- this.userAgent = userAgent;
}
@Override
public LastFm getApi(String accessToken) {
LastFmPseudoOAuth2AccessGrant lastFmAccessGrant = LastFmPseudoOAuth2AccessGrant
.fromAccessToken(accessToken);
- return new LastFmTemplate(userAgent, lastFmAccessGrant, clientId,
+ return new LastFmTemplate(lastFmAccessGrant, clientId,
secret);
}
View
1  src/main/resources/project.properties
@@ -0,0 +1 @@
+pom.version=${pom.version}
View
6 src/test/java/org/springframework/social/lastfm/api/AbstractLastFmApiTest.java
@@ -28,8 +28,6 @@
protected static final String API_KEY = "someApiKey";
protected static final String SECRET = "secret";
- protected static final String USER_AGENT = "someUserAgent";
-
protected static final LastFmAccessGrant ACCESS_GRANT = new LastFmAccessGrant(
"someToken", "someSessionKey");
@@ -42,14 +40,14 @@
@Before
public void setup() {
- lastFm = new LastFmTemplate(USER_AGENT, ACCESS_GRANT, API_KEY, SECRET);
+ lastFm = new LastFmTemplate(ACCESS_GRANT, API_KEY, SECRET);
mockServer = MockRestServiceServer.createServer(lastFm
.getRestTemplate());
responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
- unauthorizedLastFm = new LastFmTemplate(USER_AGENT, API_KEY);
+ unauthorizedLastFm = new LastFmTemplate(API_KEY);
mockUnauthorizedServer = MockRestServiceServer
.createServer(unauthorizedLastFm.getRestTemplate());
}
View
59 src/test/java/org/springframework/social/lastfm/api/UserTemplateTest.java
@@ -33,6 +33,7 @@
import org.junit.Test;
import org.springframework.social.NotAuthorizedException;
import org.springframework.social.ResourceNotFoundException;
+import org.springframework.social.lastfm.api.impl.UserAgentHelper;
public class UserTemplateTest extends AbstractLastFmApiTest {
@@ -44,7 +45,7 @@ public void getUserProfile_currentUser() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_sig=8bbd32f49982b528b16cb704b671d242&api_key=someApiKey&sk=someSessionKey&method=user.getInfo&token=someToken"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/full-profile"),
responseHeaders));
@@ -64,7 +65,7 @@ public void getUserProfile_specificUserByUserId() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getInfo&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/full-profile"),
responseHeaders));
@@ -80,7 +81,7 @@ public void getRecentTracks() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getrecenttracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/recent-tracks"),
responseHeaders));
@@ -96,7 +97,7 @@ public void getRecentTracksSingleTrackResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getrecenttracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/recent-tracks-single-track-response"),
responseHeaders));
@@ -116,7 +117,7 @@ public void getRecentTracksEmptyResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getrecenttracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(
jsonResource("testdata/recent-tracks-empty"),
@@ -135,7 +136,7 @@ public void getTopTracks() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.gettoptracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/top-tracks"),
responseHeaders));
@@ -150,7 +151,7 @@ public void getTopArtists() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.gettopartists&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/top-artists"),
responseHeaders));
@@ -165,7 +166,7 @@ public void getTopArtistsEmptyResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.gettopartists&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/top-artists-empty"),
responseHeaders));
@@ -181,7 +182,7 @@ public void getRecommendedArtists() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_sig=616df1497ae31b96429906947d82bad2&api_key=someApiKey&sk=someSessionKey&method=user.getrecommendedartists&token=someToken"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/recommended-artists"),
responseHeaders));
@@ -199,7 +200,7 @@ public void getTopTracksSingleTrackResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.gettoptracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/top-tracks-single-track-response"),
responseHeaders));
@@ -219,7 +220,7 @@ public void getTopTracksEmptyResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.gettoptracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(
jsonResource("testdata/top-tracks-empty"),
@@ -240,7 +241,7 @@ public void getLovedTracks() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getlovedtracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/loved-tracks"),
responseHeaders));
@@ -256,7 +257,7 @@ public void getSimilarTracks() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=track.similar&track=Music&artist=Madonna"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/similar-tracks"),
responseHeaders));
@@ -273,7 +274,7 @@ public void getShouts() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getshouts&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/shouts"),
responseHeaders));
@@ -291,7 +292,7 @@ public void getShoutsSingleShoutResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getshouts&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/single-shout-response"),
responseHeaders));
@@ -307,7 +308,7 @@ public void getShoutsEmptyShoutsResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getshouts&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/empty-shouts-response"),
responseHeaders));
@@ -323,7 +324,7 @@ public void getFriendsEmptyFriendsResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getfriends&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/empty-friends-response"),
responseHeaders));
@@ -339,7 +340,7 @@ public void getFriends() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getfriends&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/friends"),
responseHeaders));
@@ -355,7 +356,7 @@ public void getNeighbours() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getneighbours&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/neighbours"),
responseHeaders));
@@ -371,7 +372,7 @@ public void getFriendsSingleFriendResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getfriends&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/single-friend-response"),
responseHeaders));
@@ -397,7 +398,7 @@ public void getLovedTracksSingleTrackResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getlovedtracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(
jsonResource("testdata/loved-tracks-single-track-response"),
@@ -419,7 +420,7 @@ public void getLovedTracksEmptyResponse() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getlovedtracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(
jsonResource("testdata/loved-tracks-empty"),
@@ -438,7 +439,7 @@ public void getLovedTracks_withoutAuthorization() {
mockUnauthorizedServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getlovedtracks&user=mattslip"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/loved-tracks"),
responseHeaders));
@@ -455,7 +456,7 @@ public void getLovedTracks_invalidUser() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/?format=json&api_key=someApiKey&method=user.getlovedtracks&user=someOtherUser"))
.andExpect(method(GET))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andRespond(
withResponse(jsonResource("testdata/invalid-user"),
responseHeaders));
@@ -472,7 +473,7 @@ public void shout() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/"))
.andExpect(method(POST))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andExpect(
body("format=json&api_sig=0086bb835c43ac345624691862cc9fd4&api_key=someApiKey&sk=someSessionKey&method=user.shout&token=someToken&message=someMessage&user=someUserName"))
.andRespond(
@@ -497,7 +498,7 @@ public void scrobble() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/"))
.andExpect(method(POST))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andExpect(
body("format=json&api_sig=b4c8c73655abc90599cdfc0ed9c3b3e8&api_key=someApiKey&sk=someSessionKey&method=track.scrobble&token=someToken&timestamp=123456&track=My+track+name&artist=My+artist+name"))
.andRespond(
@@ -516,7 +517,7 @@ public void love() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/"))
.andExpect(method(POST))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andExpect(
body("format=json&api_sig=b50a3b8e66b396f78133d34dc887bda3&api_key=someApiKey&sk=someSessionKey&method=track.love&token=someToken&track=My+track+name&artist=My+artist+name"))
.andRespond(
@@ -551,7 +552,7 @@ public void unlove() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/"))
.andExpect(method(POST))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andExpect(
body("format=json&api_sig=929dd59b92e361a3e3ffb7b687856a2b&api_key=someApiKey&sk=someSessionKey&method=track.unlove&token=someToken&track=My+track+name&artist=My+artist+name"))
.andRespond(
@@ -577,7 +578,7 @@ public void updateNowPlaying() {
mockServer
.expect(requestTo("http://ws.audioscrobbler.com/2.0/"))
.andExpect(method(POST))
- .andExpect(header("User-Agent", "someUserAgent"))
+ .andExpect(header("User-Agent", UserAgentHelper.getUserAgent()))
.andExpect(
body("format=json&api_sig=6511f45e73a7fd12edab35d18a6655ce&api_key=someApiKey&sk=someSessionKey&method=track.updateNowPlaying&token=someToken&track=My+track+name&artist=My+artist+name"))
.andRespond(
Please sign in to comment.
Something went wrong with that request. Please try again.