use of org.infobip.mobile.messaging.api.registration.RegistrationResponse in project mobile-messaging-sdk-android by infobip.
the class PushUnregisteredTest method test_push_registration_default_status.
@Test
public void test_push_registration_default_status() throws Exception {
// Verify disable
given(mobileApiRegistration.upsert(anyString(), anyBoolean())).willReturn(new RegistrationResponse("testDeviceApplicationInstanceId", false));
mobileMessagingCore.disablePushRegistration();
verify(mobileApiRegistration, after(1000).times(1)).upsert(anyString(), anyBoolean());
verify(coreBroadcaster, times(1)).registrationEnabled(anyString(), eq("testDeviceApplicationInstanceId"), eq(false));
// Verify resync
reset(mobileApiRegistration);
given(mobileApiRegistration.upsert(anyString(), anyBoolean())).willReturn(new RegistrationResponse("testDeviceApplicationInstanceId", true));
registrationSynchronizer.setRegistrationIdReported(false);
registrationSynchronizer.sync();
verify(mobileApiRegistration, after(1000).times(1)).upsert(anyString(), anyBoolean());
verify(coreBroadcaster, times(1)).registrationCreated(anyString(), eq("testDeviceApplicationInstanceId"));
// Verify final value of 'enabled'
assertTrue(MobileMessaging.getInstance(context).isPushRegistrationEnabled());
}
use of org.infobip.mobile.messaging.api.registration.RegistrationResponse in project mobile-messaging-sdk-android by infobip.
the class RegistrationSynchronizer method updateStatus.
public void updateStatus(final Boolean enabled) {
new MRetryableTask<Boolean, Registration>() {
@Override
public Registration run(Boolean[] params) {
String cloudToken = mobileMessagingCore.getCloudToken();
Boolean pushRegistrationEnabled = params.length > 0 ? params[0] : null;
MobileMessagingLogger.v("REGISTRATION >>>", cloudToken, pushRegistrationEnabled);
RegistrationResponse registrationResponse = mobileApiRegistration.upsert(cloudToken, pushRegistrationEnabled);
MobileMessagingLogger.v("REGISTRATION <<<", registrationResponse);
return new Registration(cloudToken, registrationResponse.getDeviceApplicationInstanceId(), registrationResponse.getPushRegistrationEnabled());
}
@Override
public void after(Registration registration) {
setPushRegistrationEnabled(registration.enabled);
setPushRegistrationId(registration.registrationId);
setRegistrationIdReported(true);
broadcaster.registrationEnabled(registration.cloudToken, registration.registrationId, registration.enabled);
}
@Override
public void error(Throwable error) {
MobileMessagingLogger.e("MobileMessaging API returned error (push registration status update)!");
mobileMessagingCore.setLastHttpException(error);
stats.reportError(MobileMessagingStatsError.PUSH_REGISTRATION_STATUS_UPDATE_ERROR);
broadcaster.error(MobileMessagingError.createFrom(error));
}
}.retryWith(retryPolicyProvider.ONE_RETRY()).execute(executor, enabled);
}
use of org.infobip.mobile.messaging.api.registration.RegistrationResponse in project mobile-messaging-sdk-android by infobip.
the class RegistrationSynchronizer method reportCloudToken.
private void reportCloudToken(final String cloudToken) {
if (StringUtils.isBlank(cloudToken)) {
return;
}
new MRetryableTask<String, Registration>() {
@Override
public Registration run(String[] params) {
String cloudToken = params.length > 0 ? params[0] : null;
MobileMessagingLogger.v("REGISTRATION >>>", cloudToken);
RegistrationResponse registrationResponse = mobileApiRegistration.upsert(cloudToken, null);
MobileMessagingLogger.v("REGISTRATION <<<", registrationResponse);
return new Registration(cloudToken, registrationResponse.getDeviceApplicationInstanceId(), registrationResponse.getPushRegistrationEnabled());
}
@Override
public void after(Registration registration) {
setPushRegistrationEnabled(registration.enabled);
setPushRegistrationId(registration.registrationId);
setRegistrationIdReported(true);
MobileMessagingCore.getInstance(context).reportSystemData();
broadcaster.registrationCreated(registration.cloudToken, registration.registrationId);
}
@Override
public void error(Throwable error) {
MobileMessagingLogger.e("MobileMessaging API returned error (registration)!");
setRegistrationIdReported(false);
mobileMessagingCore.setLastHttpException(error);
stats.reportError(MobileMessagingStatsError.PUSH_REGISTRATION_STATUS_UPDATE_ERROR);
broadcaster.error(MobileMessagingError.createFrom(error));
}
}.retryWith(retryPolicyProvider.DEFAULT()).execute(executor, cloudToken);
}
use of org.infobip.mobile.messaging.api.registration.RegistrationResponse in project mobile-messaging-sdk-android by infobip.
the class MobileApiRegistrationTest method create_success.
@Test
public void create_success() throws Exception {
debugServer.respondWith(NanoHTTPD.Response.Status.OK, DefaultApiClient.JSON_SERIALIZER.serialize(new RegistrationResponse("11", true)));
RegistrationResponse response = mobileApiRegistration.upsert("123", true);
// inspect http context
assertEquals("/mobile/4/registration", debugServer.getUri());
assertEquals(1, debugServer.getRequestCount());
assertEquals(NanoHTTPD.Method.POST, debugServer.getRequestMethod());
assertEquals(3, debugServer.getQueryParametersCount());
assertEquals("App my_API_key", debugServer.getHeader("Authorization"));
assertNull(debugServer.getBody());
// inspect parameters
assertEquals("123", debugServer.getQueryParameter("registrationId"));
assertEquals("GCM", debugServer.getQueryParameter("platformType"));
// inspect response
assertEquals("11", response.getDeviceApplicationInstanceId());
assertTrue(response.getPushRegistrationEnabled());
}
use of org.infobip.mobile.messaging.api.registration.RegistrationResponse in project mobile-messaging-sdk-android by infobip.
the class PushUnregisteredTest method test_push_registration_enabled.
@Test
public void test_push_registration_enabled() throws Exception {
// Given
given(mobileApiRegistration.upsert(anyString(), anyBoolean())).willReturn(new RegistrationResponse("testDeviceApplicationInstanceId", true));
verifyRegistrationStatusUpdate(after(1000).atLeastOnce(), true);
boolean isPushRegistrationEnabled = captor.getValue();
assertTrue(isPushRegistrationEnabled);
verifySeenStatusReporter(after(1000).atLeastOnce());
// reports should BE called if push is enabled
verifyGeoReporting(after(1000).atLeastOnce());
verifyMessagesSynchronizer(after(1000).atLeastOnce());
}
Aggregations