@Override
public void test(PluginContext pluginContext, Domain domain) throws Exception {
GoogleTalkConfig config = getConfig(pluginContext.getCouchServer(), domain);
if (config == null) {
String msg = "The Google Talk config has not been specified.";
pluginContext.setLastMessage(msg);
return;
}
String recipient = config.getTestAddress();
if (isBlank((recipient))) {
String msg = "Test message cannot be sent with out specifying the test address.";
pluginContext.setLastMessage(msg);
return;
}
String override = config.getRecipientOverride();
if (isNotBlank(override)) {
recipient = override;
}
String when = Formats.defaultStamp(new java.util.Date());
String msg = String.format("This is a test message from Cosmic Push sent at %s.", when);
GoogleTalkPush push = GoogleTalkPush.newPush(recipient, msg, null, "gtalk-test:true");
PushRequest pushRequest = new PushRequest(AppContext.CURRENT_API_VERSION, domain, push);
pluginContext.getPushRequestStore().create(pushRequest);
new GoogleTalkDelegate(pluginContext, domain, pushRequest, push, config).run();
msg = String.format("Test message sent to %s:\n%s", recipient, msg);
pluginContext.setLastMessage(msg);
}