AbstractUITagTestpublic abstract class AbstractUITagTest extends AbstractTagTest
Fields Summary |
---|
private static final Log | LOG | static final String | FREEMARKER_ERROR_EXPECTATION |
Methods Summary |
---|
protected java.util.Map | initializedGenericTagTestProperties()Initialize a map of {@link PropertyHolder} for generic tag property testing. Will be used when calling {@link
#verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag, String, String[])} as properties to
verify. This implementation defines testdata for all common AbstractUITag properties and may be overridden in
subclasses.
Map result = new HashMap();
new PropertyHolder("name", "someName").addToMap(result);
new PropertyHolder("id", "someId").addToMap(result);
new PropertyHolder("cssClass", "cssClass1", "class=\"cssClass1\"").addToMap(result);
new PropertyHolder("cssStyle", "cssStyle1", "style=\"cssStyle1\"").addToMap(result);
new PropertyHolder("title", "someTitle").addToMap(result);
new PropertyHolder("disabled", "true", "disabled=\"disabled\"").addToMap(result);
//new PropertyHolder("label", "label", "label=\"label\"").addToMap(result);
//new PropertyHolder("required", "someTitle").addToMap(result);
new PropertyHolder("tabindex", "99").addToMap(result);
new PropertyHolder("value", "someValue").addToMap(result);
new PropertyHolder("onclick", "onclick1").addToMap(result);
new PropertyHolder("ondblclick", "ondblclick1").addToMap(result);
new PropertyHolder("onmousedown", "onmousedown1").addToMap(result);
new PropertyHolder("onmouseup", "onmouseup1").addToMap(result);
new PropertyHolder("onmouseover", "onmouseover1").addToMap(result);
new PropertyHolder("onmousemove", "onmousemove1").addToMap(result);
new PropertyHolder("onmouseout", "onmouseout1").addToMap(result);
new PropertyHolder("onfocus", "onfocus1").addToMap(result);
new PropertyHolder("onblur", "onblur1").addToMap(result);
new PropertyHolder("onkeypress", "onkeypress1").addToMap(result);
new PropertyHolder("onkeydown", "onkeydown1").addToMap(result);
new PropertyHolder("onkeyup", "onkeyup1").addToMap(result);
new PropertyHolder("onclick", "onclick1").addToMap(result);
new PropertyHolder("onselect", "onchange").addToMap(result);
return result;
| public static java.lang.String | normalize(java.lang.Object obj, boolean appendSpace)normalizes a string so that strings generated on different platforms can be compared. any group of one or more
space, tab, \r, and \n characters are converted to a single space character
StringTokenizer st = new StringTokenizer(obj.toString().trim(), " \t\r\n");
StringBuffer buffer = new StringBuffer(128);
while (st.hasMoreTokens()) {
buffer.append(st.nextToken());
/*
if (appendSpace && st.hasMoreTokens()) {
buffer.append("");
}
*/
}
return buffer.toString();
| protected void | setUp()
super.setUp();
ServletActionContext.setServletContext(pageContext.getServletContext());
| protected void | tearDown()
super.tearDown();
ActionContext.setContext(null);
| public void | verify(java.net.URL url)Attempt to verify the contents of this.writer against the contents of the URL specified. verify() performs a
trim on both ends
if (url == null) {
fail("unable to verify a null URL");
} else if (this.writer == null) {
fail("AbstractJspWriter.writer not initialized. Unable to verify");
}
StringBuffer buffer = new StringBuffer(128);
InputStream in = url.openStream();
byte[] buf = new byte[4096];
int nbytes;
while ((nbytes = in.read(buf)) > 0) {
buffer.append(new String(buf, 0, nbytes));
}
in.close();
/**
* compare the trimmed values of each buffer and make sure they're equivalent. however, let's make sure to
* normalize the strings first to account for line termination differences between platforms.
*/
String writerString = normalize(writer.toString(), true);
String bufferString = normalize(buffer.toString(), true);
assertEquals(bufferString, writerString);
| public void | verify(java.net.URL url, java.lang.String[] excluded)Attempt to verify the contents of this.writer against the contents of the URL specified. verify() performs a
trim on both ends
if (url == null) {
fail("unable to verify a null URL");
} else if (this.writer == null) {
fail("AbstractJspWriter.writer not initialized. Unable to verify");
}
StringBuffer buffer = new StringBuffer(128);
InputStream in = url.openStream();
byte[] buf = new byte[4096];
int nbytes;
while ((nbytes = in.read(buf)) > 0) {
buffer.append(new String(buf, 0, nbytes));
}
in.close();
/**
* compare the trimmed values of each buffer and make sure they're equivalent. however, let's make sure to
* normalize the strings first to account for line termination differences between platforms.
*/
String writerString = normalize(writer.toString(), true);
String bufferString = normalize(buffer.toString(), true);
assertEquals(bufferString, writerString);
| public void | verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag tag, java.lang.String theme, java.util.Map propertiesToTest, java.lang.String[] exclude)Do a generic verification that setting certain properties on a tag causes expected output regarding this
property. In most cases you would not call this directly, instead use {@link
#verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag, String, String[])}.
if (tag != null && propertiesToTest != null) {
List excludeList;
if (exclude != null) {
excludeList = Arrays.asList(exclude);
} else {
excludeList = Collections.EMPTY_LIST;
}
tag.setPageContext(pageContext);
if (theme != null) {
tag.setTheme(theme);
}
BeanHelper beanHelper = new BeanHelper(tag);
Iterator it = propertiesToTest.values().iterator();
while (it.hasNext()) {
PropertyHolder propertyHolder = (PropertyHolder) it.next();
if (! excludeList.contains(propertyHolder.getName())) {
beanHelper.set(propertyHolder.getName(), propertyHolder.getValue());
}
}
tag.doStartTag();
tag.doEndTag();
String writerString = normalize(writer.toString(), true);
if (LOG.isInfoEnabled()) {
LOG.info("AbstractUITagTest - [verifyGenericProperties]: Tag output is " + writerString);
}
assertTrue("Freemarker error detected in tag output: " + writerString, writerString.indexOf(FREEMARKER_ERROR_EXPECTATION) == -1);
it = propertiesToTest.values().iterator();
while (it.hasNext()) {
PropertyHolder propertyHolder = (PropertyHolder) it.next();
if (! excludeList.contains(propertyHolder.getName())) {
assertTrue("Expected to find: " + propertyHolder.getExpectation() + " in resulting String: " + writerString, writerString.indexOf(propertyHolder.getExpectation()) > -1);
}
}
}
| public void | verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag tag, java.lang.String theme, java.lang.String[] exclude)Do a generic verification that setting certain properties on a tag causes expected output regarding this
property. Which properties to test with which expectations will be determined by the Map retrieved by {@link #initializedGenericTagTestProperties()}.
verifyGenericProperties(tag, theme, initializedGenericTagTestProperties(), exclude);
|
|