Bug 1207714 - Pre: Tweaks to the autopush client. r=me
MozReview-Commit-ID: INWEkLJfVDQ
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/push/autopush/AutopushClientException.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/push/autopush/AutopushClientException.java
@@ -16,16 +16,20 @@ public class AutopushClientException ext
public AutopushClientException(String detailMessage) {
super(detailMessage);
}
public AutopushClientException(Exception e) {
super(e);
}
+ public boolean isTransientError() {
+ return false;
+ }
+
public static class AutopushClientRemoteException extends AutopushClientException {
private static final long serialVersionUID = 2209313149952001000L;
public final HttpResponse response;
public final long httpStatusCode;
public final long apiErrorNumber;
public final String error;
public final String message;
@@ -51,16 +55,25 @@ public class AutopushClientException ext
public boolean isInvalidAuthentication() {
return httpStatusCode == HttpStatus.SC_UNAUTHORIZED;
}
public boolean isNotFound() {
return httpStatusCode == HttpStatus.SC_NOT_FOUND;
}
+
+ public boolean isGone() {
+ return httpStatusCode == HttpStatus.SC_GONE;
+ }
+
+ @Override
+ public boolean isTransientError() {
+ return httpStatusCode >= 500;
+ }
}
public static class AutopushClientMalformedResponseException extends AutopushClientRemoteException {
private static final long serialVersionUID = 2209313149952001909L;
public AutopushClientMalformedResponseException(HttpResponse response) {
super(response, 0, 999, "Response malformed", "Response malformed", new ExtendedJSONObject());
}
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestLiveAutopushClient.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestLiveAutopushClient.java
@@ -30,17 +30,17 @@ import static org.mockito.Mockito.verify
/**
* This test straddles an awkward line: it uses Mockito, but doesn't actually mock the service
* endpoint. That's why it's a <b>live</b> test: most of its value is checking that the client
* implementation and the upstream server implementation are corresponding correctly.
*/
@RunWith(TestRunner.class)
@Ignore("Live test that requires network connection -- remove this line to run this test.")
public class TestLiveAutopushClient {
- final String serverURL = "https://updates-autopush-dev.stage.mozaws.net/v1/gcm/829133274407";
+ final String serverURL = "https://updates-autopush.stage.mozaws.net/v1/gcm/829133274407";
protected AutopushClient client;
@Before
public void setUp() throws Exception {
BaseResource.rewriteLocalhost = false;
client = new AutopushClient(serverURL, Utils.newSynchronousExecutor());
}
@@ -88,17 +88,17 @@ public class TestLiveAutopushClient {
Assert.assertNull(assertSuccess(unregisterDelegate, Void.class));
// Trying to unregister a second time should give a 404.
final RequestDelegate<Void> reunregisterDelegate = mock(RequestDelegate.class);
client.unregisterUserAgent(registerResponse.uaid, registerResponse.secret, reunregisterDelegate);
final AutopushClientException failureException = assertFailure(reunregisterDelegate, Void.class);
Assert.assertThat(failureException, instanceOf(AutopushClientException.AutopushClientRemoteException.class));
- Assert.assertTrue(((AutopushClientException.AutopushClientRemoteException) failureException).isNotFound());
+ Assert.assertTrue(((AutopushClientException.AutopushClientRemoteException) failureException).isGone());
}
@Test
public void testChannel() throws Exception {
final RequestDelegate<RegisterUserAgentResponse> registerDelegate = mock(RequestDelegate.class);
client.registerUserAgent(Utils.generateGuid(), registerDelegate);
final RegisterUserAgentResponse registerResponse = assertSuccess(registerDelegate, RegisterUserAgentResponse.class);
@@ -117,23 +117,23 @@ public class TestLiveAutopushClient {
Assert.assertThat(subscribeResponse.endpoint, startsWith(FxAccountUtils.getAudienceForURL(serverURL)));
// And we should be able to unsubscribe.
final RequestDelegate<Void> unsubscribeDelegate = mock(RequestDelegate.class);
client.unsubscribeChannel(registerResponse.uaid, registerResponse.secret, subscribeResponse.channelID, unsubscribeDelegate);
Assert.assertNull(assertSuccess(unsubscribeDelegate, Void.class));
- // Trying to unsubscribe a second time should give a 404.
+ // Trying to unsubscribe a second time should give a 410.
final RequestDelegate<Void> reunsubscribeDelegate = mock(RequestDelegate.class);
client.unsubscribeChannel(registerResponse.uaid, registerResponse.secret, subscribeResponse.channelID, reunsubscribeDelegate);
final AutopushClientException reunsubscribeFailureException = assertFailure(reunsubscribeDelegate, Void.class);
Assert.assertThat(reunsubscribeFailureException, instanceOf(AutopushClientException.AutopushClientRemoteException.class));
- Assert.assertTrue(((AutopushClientException.AutopushClientRemoteException) reunsubscribeFailureException).isNotFound());
+ Assert.assertTrue(((AutopushClientException.AutopushClientRemoteException) reunsubscribeFailureException).isGone());
// Trying to unsubscribe from a non-existent channel should give a 404. Right now it gives a 401!
final RequestDelegate<Void> badUnsubscribeDelegate = mock(RequestDelegate.class);
client.unsubscribeChannel(registerResponse.uaid + "BAD", registerResponse.secret, subscribeResponse.channelID, badUnsubscribeDelegate);
final AutopushClientException badUnsubscribeFailureException = assertFailure(badUnsubscribeDelegate, Void.class);
Assert.assertThat(badUnsubscribeFailureException, instanceOf(AutopushClientException.AutopushClientRemoteException.class));
Assert.assertTrue(((AutopushClientException.AutopushClientRemoteException) badUnsubscribeFailureException).isInvalidAuthentication());