コード例 #1
0
  public void testReRegisterFailNative() throws Throwable {
    try {

      Context context = getInstrumentation().getTargetContext();
      final SharedPreferences sharedPreferences =
          PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

      final Container container = new Container();
      final String handle = "handle";

      String registrationId1 = "registrationId1";
      String registrationId2 = "registrationId2";

      MobileServiceClient client = new MobileServiceClient(appUrl, appKey, context);

      MobileServiceClient registrationclient =
          client.withFilter(getUpsertTestFilter(registrationId1));
      MobileServiceClient reRegistrationclient =
          client.withFilter(getUpsertFailTestFilter(registrationId2));

      final MobileServicePush registrationPush = registrationclient.getPush();
      final MobileServicePush reRegistrationPush = reRegistrationclient.getPush();

      forceRefreshSync(registrationPush, handle);
      forceRefreshSync(reRegistrationPush, handle);

      try {
        registrationPush.register(handle, new String[] {"tag1"}).get();
      } catch (Exception exception) {
        fail(exception.getMessage());
      }

      try {
        reRegistrationPush.register(handle, new String[] {"tag1"}).get();

      } catch (Exception exception) {
        if (exception instanceof ExecutionException) {
          container.exception = (Exception) exception.getCause();
        } else {
          container.exception = exception;
        }

        container.storedRegistrationId =
            sharedPreferences.getString(
                STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + DEFAULT_REGISTRATION_NAME, null);
      }

      // Asserts
      Exception exception = container.exception;

      if (!(exception instanceof RegistrationGoneException)) {
        fail("Expected Exception RegistrationGoneException");
      }

      Assert.assertNull(container.storedRegistrationId);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  public void testReRegisterNative() throws Throwable {
    try {

      Context context = getInstrumentation().getTargetContext();
      final SharedPreferences sharedPreferences =
          PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

      final Container container = new Container();
      final String handle = "handle";

      String registrationId1 = "registrationId1";
      String registrationId2 = "registrationId2";

      String[] tags1 = new String[] {"tag1"};
      final String[] tags2 = new String[] {"tag2"};

      MobileServiceClient client = new MobileServiceClient(appUrl, appKey, context);

      MobileServiceClient registrationclient =
          client.withFilter(getUpsertTestFilter(registrationId1));
      MobileServiceClient reRegistrationclient =
          client.withFilter(getUpsertTestFilter(registrationId2));

      final MobileServicePush registrationPush = registrationclient.getPush();
      final MobileServicePush reRegistrationPush = reRegistrationclient.getPush();

      forceRefreshSync(registrationPush, handle);
      forceRefreshSync(reRegistrationPush, handle);

      try {
        registrationPush.register(handle, tags1).get();

        Registration registration2 = reRegistrationPush.register(handle, tags2).get();

        container.storedRegistrationId =
            sharedPreferences.getString(
                STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + DEFAULT_REGISTRATION_NAME, null);
        container.tags = registration2.getTags();

      } catch (Exception exception) {
        container.exception = exception;
      }

      // Asserts
      Exception exception = container.exception;

      if (exception != null) {
        fail(exception.getMessage());
      } else {
        Assert.assertEquals(registrationId2, container.storedRegistrationId);
        Assert.assertTrue(matchTags(tags2, container.tags));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
  public void testRegisterUnregisterTemplate() throws Throwable {

    Context context = getInstrumentation().getTargetContext();
    final SharedPreferences sharedPreferences =
        PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

    final Container container = new Container();
    final String handle = "handle";
    final String templateName = "templateName";

    String registrationId = "registrationId";

    MobileServiceClient client = new MobileServiceClient(appUrl, appKey, context);

    client = client.withFilter(getUpsertTestFilter(registrationId));

    final MobileServicePush push = client.getPush();

    forceRefreshSync(push, handle);

    try {
      TemplateRegistration registration =
          push.registerTemplate(handle, templateName, "{ }", new String[] {"tag1"}).get();

      container.registrationId = registration.getRegistrationId();

      container.storedRegistrationId =
          sharedPreferences.getString(
              STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + templateName, null);

      push.unregisterTemplate(templateName).get();

      container.unregister =
          sharedPreferences.getString(
              STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + templateName, null);

      Assert.assertEquals(registrationId, container.storedRegistrationId);
      Assert.assertEquals(registrationId, container.registrationId);
      Assert.assertNull(container.unregister);

    } catch (Exception exception) {

      if (exception instanceof ExecutionException) {
        container.exception = (Exception) exception.getCause();
      } else {
        container.exception = exception;
      }

      fail(container.exception.getMessage());
    }
  }