You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2006/12/29 18:11:11 UTC
svn commit: r491051 - in
/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test:
AbstractTagLibTestCase.java MyFacesTagLibTestCase.java
Author: dennisbyrne
Date: Fri Dec 29 09:11:10 2006
New Revision: 491051
URL: http://svn.apache.org/viewvc?view=rev&rev=491051
Log:
refactored tests
Modified:
myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTagLibTestCase.java
myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/MyFacesTagLibTestCase.java
Modified: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTagLibTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTagLibTestCase.java?view=diff&rev=491051&r1=491050&r2=491051
==============================================================================
--- myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTagLibTestCase.java (original)
+++ myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/AbstractTagLibTestCase.java Fri Dec 29 09:11:10 2006
@@ -38,15 +38,13 @@
import org.w3c.dom.Document;
/**
- * Insures the following ...
- *
+ * Insures the following ...
* <ul>
* <li> all tag handlers are in the classpath</li>
* <li> tag handlers do not appear in the TLD more than once</li>
* <li> tag handler attributes do not occur mare than once</li>
* <li> tag handlers have setters for all tag attributes</li>
* </ul>
- *
* TODO get this in Shale test jar ?
*
* @author Dennis C. Byrne
@@ -60,12 +58,15 @@
protected String[] tldPaths;
- private static final String WARNING = " This test can fail when " +
- "validating TLDs produced by any project, not necessarily" +
- " the project it is run from";
+ private static final String WARNING = " This test can fail when "
+ + "validating TLDs produced by any project, not necessarily "
+ + "the project it is run from. This is a temporary "
+ + "problem, allowing us to avoid some undesired "
+ + "dependencies or copy and pasting this class in "
+ + "multiple projects.";
/**
- * Unmarshall TLDs to an object model. TLDs are supplied by a subclass.
+ * Unmarshall TLDs to an object model. TLDs are supplied by a subclass.
*/
protected void setUp() throws Exception {
@@ -102,39 +103,48 @@
throw new NullPointerException("tag");
String name = tag.getName();
- String msg = name + " found more than once in " + tldPaths[lib] + WARNING;
+ String msg = name + " found more than once in " + tldPaths[lib]
+ + WARNING;
assertFalse(msg, tagNames.contains(name));
- tagNames.add(tag.getName());
+ tagNames.add(name);
} // end t
} // end lib
-
}
public void testUniqueTagAttributes() throws Exception {
- List attributeNames = null;
-
for (int lib = 0; lib < tlds.length; lib++) {
Tld tld = tlds[lib];
Tag[] tags = tld.getTags();
for (int t = 0; t < tags.length; t++) {
+
Tag tag = tags[t];
- attributeNames = new ArrayList();
- TagAttribute[] atts = tag.getAttributes();
+ assertUniqueTagAttributes(tag, tldPaths[lib]);
- for (int a = 0; a < atts.length; a++) {
- TagAttribute att = atts[a];
- String name = att.getAttributeName();
- String msg = " @" + name + " of " + tldPaths[lib] + ":"
- + tag.getName() + " is duplicated." + WARNING;
- assertFalse(msg, attributeNames.contains(name));
- attributeNames.add(name);
- } // end a
} // end t
} // end lib
}
+ private void assertUniqueTagAttributes(final Tag tag, final String path) {
+
+ List attributeNames = new ArrayList();
+ TagAttribute[] atts = tag.getAttributes();
+ String tagName = tag.getName();
+
+ for (int a = 0; a < atts.length;) {
+
+ TagAttribute att = atts[a++];
+ String name = att.getAttributeName();
+ String msg = " @" + name + " of " + path + ":" + tagName
+ + " is duplicated." + WARNING;
+ assertFalse(msg, attributeNames.contains(name));
+ attributeNames.add(name);
+
+ } // end a
+
+ }
+
/**
* Make sure the class exists. Make sure there is a setter for each
* attribute.
@@ -151,28 +161,38 @@
String filename = tld.getFilename();
Object object = TldTestUtils.getTagClassInstance(tag, filename,
getClass().getClassLoader());
- TagAttribute[] attributes = tag.getAttributes();
- for (int a = 0; a < attributes.length; a++) {
- TagAttribute attribute = attributes[a];
- String name = attribute.getAttributeName();
- String msg = filename + ":" + tag.getName() + "@"
- + attribute.getAttributeName() + " exists, but "
- + object.getClass().getName() + " has no setter." + WARNING;
- assertTrue(msg, PropertyUtils.isWriteable(object, name));
- } // end for attributes
+ assertSetters(tag, filename, object);
+
} // end for tag
} // end for lib
} // end method
+ private void assertSetters(final Tag tag, final String path,
+ final Object object) {
+
+ TagAttribute[] attributes = tag.getAttributes();
+
+ for (int a = 0; a < attributes.length; a++) {
+ TagAttribute attribute = attributes[a];
+ String name = attribute.getAttributeName();
+ String msg = path + ":" + tag.getName() + "@" + name
+ + " exists, but " + object.getClass().getName()
+ + " has no setter." + WARNING;
+ assertTrue(msg, PropertyUtils.isWriteable(object, name));
+ } // end for attributes
+
+ }
+
public static class TldTestUtils {
private static Log log = LogFactory.getLog(TldTestUtils.class);
private static DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
- public static Tld getTld(String name, InputStream stream) throws Exception {
+ public static Tld getTld(String name, InputStream stream)
+ throws Exception {
if (stream == null)
log.error(" input stream is null ");
@@ -228,5 +248,5 @@
}
}
-
+
}
Modified: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/MyFacesTagLibTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/MyFacesTagLibTestCase.java?view=diff&rev=491051&r1=491050&r2=491051
==============================================================================
--- myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/MyFacesTagLibTestCase.java (original)
+++ myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/MyFacesTagLibTestCase.java Fri Dec 29 09:11:10 2006
@@ -32,11 +32,13 @@
protected static final String META_INF = "META-INF/";
protected void setUp() throws Exception {
+
tldPaths = new String[3];
tldPaths[0] = META_INF + "myfaces_html.tld";
tldPaths[1] = META_INF + "myfaces_core.tld";
tldPaths[2] = META_INF + "tomahawk.tld";
// tldPaths[3] = META_INF + "myfaces_sandbox.tld";
+
tlds = new Tld[tldPaths.length];
super.setUp();