//value of the "token.invalid" key in the "org.apache.shale.util.TestBundle"
final String SUMMARY_MESSAGE = "Invalid resubmit of the same form is bad news Lucy Luo";
final String DETAIL_MESSAGE = "This page has been mark as having durability of a single submit and this contract has been violated by the submission of a dirty page.";
Token token = (Token) facesContext.getApplication().createComponent("org.apache.shale.Token");
assertNotNull(token);
UIViewRoot root = facesContext.getViewRoot();
assertNotNull(root);
// add token to the component tree
root.getChildren().add(root.getChildCount(), token);
token.setId("messageFacesConfigBundleOverride");
token.setMessageSummary(null); // no message property override
token.setMessageDetail(null); // no message property override
StringBuffer htmlSnippet = encode(token);
// check rendered markup
String id = getAttribute(htmlSnippet, "id");
assertEquals("id", token.getClientId(facesContext), id);
String name = getAttribute(htmlSnippet, "name");
assertEquals("id", token.getClientId(facesContext), name);
String type = getAttribute(htmlSnippet, "type");
assertEquals("id", "hidden", type);
String value = getAttribute(htmlSnippet, "value");
assertNotNull("value", value);
// simulate form post on dirty page
Map map = facesContext.getExternalContext().getRequestParameterMap();
map.put(id, value);
// simulate apply values
token.decode(facesContext);
assertEquals("value", value, token.getSubmittedValue());
// simulate validation and invalidates token
token.validate(facesContext);
checkNoMessages(token);
// simulate double post
token.validate(facesContext);
// check for the custom message
checkMessage(SUMMARY_MESSAGE, DETAIL_MESSAGE, token);
}