public void testCardemo() throws Exception {
mcp.getRealizedVisibleBrowserWindow();
final BitSet bitSet = new BitSet();
AjaxListener listener = new AjaxListener() {
public void endAjax(Map eventMap) {
bitSet.flip(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal());
if (null != eventMap) {
bitSet.flip(TestFeature.HAS_MAP.ordinal());
}
// Make some assertions about the response text
String responseText = (String) eventMap.get("responseText");
if (null != responseText) {
if (-1 != responseText.indexOf("<partial-response>") &&
-1 != responseText.indexOf("</partial-response>")) {
bitSet.flip(TestFeature.HAS_VALID_RESPONSE_TEXT.ordinal());
}
}
Document responseXML = (Document)
eventMap.get("responseXML");
Element rootElement = null, element = null;
Node node = null;
String tagName = null;
try {
rootElement = responseXML.getDocumentElement();
tagName = rootElement.getTagName();
if (tagName.equals("partial-response")) {
element = (Element) rootElement.getFirstChild();
tagName = element.getTagName();
if (tagName.equals("components")) {
element = (Element) rootElement.getLastChild();
tagName = element.getTagName();
if (tagName.equals("state")) {
bitSet.flip(TestFeature.
HAS_VALID_RESPONSE_XML.ordinal());
}
}
}
}
catch (Throwable t) {
}
String readyState = (String) eventMap.get("readyState");
bitSet.set(TestFeature.HAS_VALID_READYSTATE.ordinal(),
null != readyState && readyState.equals("4"));
bitSet.flip(TestFeature.STOP_WAITING.ordinal());
}
};
mcp.addAjaxListener(listener);
// Load the main page of the app
mcp.blockingLoad("http://javaserver.org/jsf-ajax-cardemo/faces/chooseLocale.jsp");
// Choose the "German" language button
mcp.blockingClickElement("Germany");
// Choose the roadster
mcp.blockingClickElement("roadsterButton");
// Sample the Basis-Preis and Ihr Preis before the ajax transaction
Element pricePanel = mcp.findElement("zone1");
assertNotNull(pricePanel);
String pricePanelText = pricePanel.getTextContent();
assertNotNull(pricePanelText);
assertTrue(pricePanelText.matches("(?s).*Basis-Preis\\s*15700.*"));
assertTrue(pricePanelText.matches("(?s).*Ihr Preis\\s*15700.*"));
// Choose the "Tempomat" checkbox
bitSet.clear();
mcp.clickElement("cruiseControlCheckbox");
while (!bitSet.get(TestFeature.STOP_WAITING.ordinal())) {
Thread.currentThread().sleep(5000);
}
// assert that the ajax transaction succeeded
assertTrue(bitSet.get(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal()));
assertTrue(bitSet.get(TestFeature.HAS_MAP.ordinal()));
assertTrue(bitSet.get(TestFeature.HAS_VALID_RESPONSE_TEXT.ordinal()));
assertTrue(bitSet.get(TestFeature.HAS_VALID_RESPONSE_XML.ordinal()));
assertTrue(bitSet.get(TestFeature.HAS_VALID_READYSTATE.ordinal()));
bitSet.clear();
// Sample the Basis-Preis and Ihr-Preis after the ajax transaction
pricePanel = mcp.findElement("zone1");
assertNotNull(pricePanel);
pricePanelText = pricePanel.getTextContent();
assertNotNull(pricePanelText);
assertTrue(pricePanelText.matches("(?s).*Basis-Preis\\s*15700.*"));
assertTrue(pricePanelText.matches("(?s).*Ihr Preis\\s*16600.*"));
mcp.deleteBrowserControl();
}