GCMWrapper { public void send(GCMMessage messageBase, final Map<String, String> tokens, final String uid) { if (gcmURI == null) { log.error("Error sending push. Google cloud messaging properties not provided."); return; } String message; try { messageBase.setTitle(title); message = messageBase.toJson(); } catch (JsonProcessingException e) { log.error("Error sending push. Wrong message format."); return; } httpclient.preparePost(gcmURI).setHeader("Authorization", apiKey) .setHeader(HttpHeaderNames.CONTENT_TYPE, "application/json; charset=utf-8") .setBody(message) .execute(new AsyncCompletionHandler<Response>() { @Override public Response onCompleted(Response response) throws Exception { if (response.getStatusCode() == HttpResponseStatus.OK.code()) { GCMResponseMessage gcmResponseMessage = gcmResponseReader.readValue(response.getResponseBody()); if (gcmResponseMessage.failure == 1) { String errorMessage = gcmResponseMessage.results != null && gcmResponseMessage.results.length > 0 ? gcmResponseMessage.results[0].error : messageBase.getToken(); processError(errorMessage, tokens, uid); } return response; } return response; } @Override public void onThrowable(Throwable t) { processError(t.getMessage(), tokens, uid); } }); } GCMWrapper(GCMProperties props, AsyncHttpClient httpclient, String productName); void send(GCMMessage messageBase, final Map<String, String> tokens, final String uid);  }
@Test @Ignore public void testIOS() { GCMWrapper gcmWrapper = new GCMWrapper(props, client, AppNameUtil.BLYNK); gcmWrapper.send(new IOSGCMMessage("to", Priority.normal, "yo!!!", 1), null, null); }
@Test @Ignore public void testAndroid() throws Exception { when(props.getProperty("gcm.api.key")).thenReturn(""); when(props.getProperty("gcm.server")).thenReturn(""); GCMWrapper gcmWrapper = new GCMWrapper(props, client, AppNameUtil.BLYNK); gcmWrapper.send(new AndroidGCMMessage("", Priority.normal, "yo!!!", 1), null, null); Thread.sleep(5000); }