@Test
public void atmospherePush()
{
final String updateTimeIsExecuted = "updateTime is executed!";
WicketTester tester = new WicketTester();
HomePage page = new HomePage(new PageParameters())
{
@Subscribe
public void updateTime(AjaxRequestTarget target, Date event)
{
super.updateTime(target, event);
updateTimeCalled.set(true);
target.appendJavaScript(updateTimeIsExecuted);
}
@Subscribe(contextAwareFilter = ReceiverFilter.class)
public void receiveMessage(AjaxRequestTarget target, ChatMessage message)
{
super.receiveMessage(target, message);
receiveMessageCalled.set(true);
}
};
AtmosphereTester waTester = new AtmosphereTester(tester, page);
assertThat(updateTimeCalled.get(), is(false));
assertThat(receiveMessageCalled.get(), is(false));
Date payload = new Date();
waTester.post(payload);
assertThat(updateTimeCalled.get(), is(true));
assertThat(receiveMessageCalled.get(), is(false));
tester.assertContains(updateTimeIsExecuted);
final FormTester form = tester.newFormTester("form");
form.setValue("input", "Atmosphere rocks!");
form.submit("send");
assertThat(updateTimeCalled.get(), is(true));
assertThat(receiveMessageCalled.get(), is(true));
// get the the collected so far content of the suspended response
// Note: it may contain several <ajax-response>s.
// use waTester.resetResponse() to remove the collected data
String atmosphereResponse = waTester.getPushedResponse();
// System.out.println("RES:" + atmosphereResponse);
// assert
assertThat(atmosphereResponse,
is(not(equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ajax-response></ajax-response>"))));
waTester.switchOnTestMode();
// now the assertions are against the Atmosphere's suspended response data
tester.assertComponentOnAjaxResponse("message");
waTester.switchOffTestMode();
// now the assertions will be the real last response
tester.assertLabel("message", "Atmosphere rocks!");
tester.destroy();
}