<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.6.4">
</HEAD>
<BODY>
Hi all,<BR>
<BR>
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.<BR>
<BR>
The approach is the following:<BR>
<BR>
&nbsp; - 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]<BR>
&nbsp; - The PushApplication, Android Variant and Android installations registrations are performed outside the container<BR>
&nbsp; - 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<BR>
&nbsp; - 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<BR>
&nbsp; -&nbsp; There is a test which is executed inside the container, accesses the CGMCache, retrieves the custom Sender from the cache and uses the <B>Awaitility framework [2]</B> in order to wait until the notifications are sent<BR>
<BR>
The code looks like the following:<BR>
<BR>
def &quot;verify that Push were sent to the correct devices&quot;() {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expect:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Awaitility.await().atMost(Duration.FIVE_SECONDS).until(<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Callable&lt;Boolean&gt;() {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Boolean call() throws Exception {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return cache.getSenderForAPIKey(ANDROID_VARIANT_GOOGLE_KEY).regIdsList != null &amp;&amp; cache.getSenderForAPIKey(ANDROID_VARIANT_GOOGLE_KEY).regIdsList.size() == 2; // The condition that must be fulfilled<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cache.getSenderForAPIKey(ANDROID_VARIANT_GOOGLE_KEY).regIdsList.size() == 2 &amp;&amp; cache.getSenderForAPIKey(ANDROID_VARIANT_GOOGLE_KEY).regIdsList.contains(ANDROID_DEVICE_TOKEN_2) &amp;&amp; Sender.regIdsList.contains(ANDROID_DEVICE_TOKEN)<BR>
&nbsp;&nbsp;&nbsp; }<BR>
<BR>
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. <BR>
<BR>
[1]: <A HREF="https://github.com/aerogear/aerogear-unified-push-server/blob/master/src/main/java/org/jboss/aerogear/connectivity/message/cache/GCMCache.java">https://github.com/aerogear/aerogear-unified-push-server/blob/master/src/main/java/org/jboss/aerogear/connectivity/message/cache/GCMCache.java</A><BR>
[2]: <A HREF="http://code.google.com/p/awaitility/">http://code.google.com/p/awaitility/</A>
</BODY>
</HTML>