Hi all,

I've managed to write an integration test which verifies that the correct GCM notifications are sent to the GCM server when using the selective send method.

The approach is the following:

  - I have an Arquillian test which is executed inside the container. The reason for executing the test inside the container is that I want to access the application scoped GCMCache [1]
  - The PushApplication, Android Variant and Android installations registrations are performed outside the container
  - When creating the WAR which is finally deployed from Arquillian, the whole jar containing the GCM dependencies is removed and a custom GCM Sender is added to the classpath
  - The custom GCM Sender is defined as ApplicationScoped and it contains some static fields. These static fields are instantiated when the send method is called. e.g there is a static list which is filled with the android token ids
  -  There is a test which is executed inside the container, accesses the CGMCache, retrieves the custom Sender from the cache and uses the Awaitility framework [2] in order to wait until the notifications are sent

The code looks like the following:

def "verify that Push were sent to the correct devices"() {
        expect:
        Awaitility.await().atMost(Duration.FIVE_SECONDS).until(
            new Callable<Boolean>() {
                public Boolean call() throws Exception {
                    return cache.getSenderForAPIKey(ANDROID_VARIANT_GOOGLE_KEY).regIdsList != null && cache.getSenderForAPIKey(ANDROID_VARIANT_GOOGLE_KEY).regIdsList.size() == 2; // The condition that must be fulfilled
                }
            }
        );
        cache.getSenderForAPIKey(ANDROID_VARIANT_GOOGLE_KEY).regIdsList.size() == 2 && cache.getSenderForAPIKey(ANDROID_VARIANT_GOOGLE_KEY).regIdsList.contains(ANDROID_DEVICE_TOKEN_2) && Sender.regIdsList.contains(ANDROID_DEVICE_TOKEN)
    }

Even if this everything works perfectly using this approach, I'm not sure if the specific test should be included in the upstream. Having 2 GCM Sender classes in the project might confuse the end users. Wdyt? If anyone has to propose a more elegant way to verify that the correct notifications are sent plz tell me.

[1]: https://github.com/aerogear/aerogear-unified-push-server/blob/master/src/main/java/org/jboss/aerogear/connectivity/message/cache/GCMCache.java
[2]: http://code.google.com/p/awaitility/