myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bom...@apache.org
Subject svn commit: r511617 - in /myfaces/tobago/trunk/core: ./ src/test/java/org/apache/myfaces/tobago/taglib/component/
Date Sun, 25 Feb 2007 21:18:04 GMT
Author: bommel
Date: Sun Feb 25 13:18:04 2007
New Revision: 511617

URL: http://svn.apache.org/viewvc?view=rev&rev=511617
Log:
reenable tag tests

Modified:
    myfaces/tobago/trunk/core/pom.xml
    myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java
    myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTagUnitTest.java
    myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTestBase.java

Modified: myfaces/tobago/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/pom.xml?view=diff&rev=511617&r1=511616&r2=511617
==============================================================================
--- myfaces/tobago/trunk/core/pom.xml (original)
+++ myfaces/tobago/trunk/core/pom.xml Sun Feb 25 13:18:04 2007
@@ -140,6 +140,19 @@
   </scm>
 
   <dependencies>
+    <!--dependency>
+      <groupId>org.apache.shale</groupId>
+      <artifactId>shale-test</artifactId>
+      <version>1.0.4</version>
+      <scope>test</scope>
+    </dependency-->
+
+    <dependency>
+      <groupId>maven-taglib</groupId>
+      <artifactId>maven-taglib-plugin</artifactId>
+      <version>1.4.2</version>
+      <scope>test</scope>
+    </dependency>
 
     <dependency>
       <groupId>commons-beanutils</groupId>

Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java?view=diff&rev=511617&r1=511616&r2=511617
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java
(original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericComponentTagUnitTest.java
Sun Feb 25 13:18:04 2007
@@ -51,25 +51,21 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import net.sf.maventaglib.checker.Tld;
+
 public class GenericComponentTagUnitTest extends GenericTestBase {
-// ----------------------------------------------------------- class attributes
 
   private static final Log LOG = LogFactory.getLog(GenericComponentTagUnitTest.class);
 
-// ----------------------------------------------------------------- attributes
-
   private Application application;
   private MockFacesContext facesContext;
   private PageContext pageContext;
 
-// --------------------------------------------------------------- constructors
 
   public GenericComponentTagUnitTest(String name) {
     super(name);
   }
 
-// ----------------------------------------------------------- business methods
-
   public void setUp() throws Exception {
     super.setUp();
 
@@ -85,15 +81,17 @@
     FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
         "org.apache.myfaces.tobago.mock.faces.MockApplicationFactory");
     FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
-           "org.apache.myfaces.tobago.mock.faces.MockRenderKitFactory");
+        "org.apache.myfaces.tobago.mock.faces.MockRenderKitFactory");
 
     ApplicationFactory applicationFactory = (ApplicationFactory)
         FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
     application = applicationFactory.getApplication();
     application.addComponent("javax.faces.Command", "javax.faces.component.UICommand");
     application.addComponent("org.apache.myfaces.tobago.Command", "org.apache.myfaces.tobago.component.UICommand");
-    application.addComponent("org.apache.myfaces.tobago.LinkCommand", "org.apache.myfaces.tobago.component.UILinkCommand");
-    application.addComponent("org.apache.myfaces.tobago.ButtonCommand", "org.apache.myfaces.tobago.component.UIButtonCommand");
+    application
+        .addComponent("org.apache.myfaces.tobago.LinkCommand", "org.apache.myfaces.tobago.component.UILinkCommand");
+    application
+        .addComponent("org.apache.myfaces.tobago.ButtonCommand", "org.apache.myfaces.tobago.component.UIButtonCommand");
 
     facesContext.setApplication(application);
     UIViewRoot root = facesContext
@@ -105,21 +103,24 @@
         FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
     RenderKit renderKit = new MockRenderKit();
     try {
-        renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
-                                      renderKit);
+      renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
     } catch (IllegalArgumentException e) {
-        ;
+      // ignore
     }
     request.setAttribute("peter", new DummyBean(true, 20, "Peter"));
     request.setAttribute("marry", new DummyBean(false, 17, "Marry"));
   }
 
-  public void testComponent() throws JspException {
-//    for (int i = 0; i < componentTagList.length; i++) { TODO
-    for (int i = 0; i < 1; i++) {
-      UIComponentTag tag = componentTagList[i];
-      LOG.info("testing tag: " + tag.getClass().getName());
-      testComponent(tag);
+  public void testComponent()
+      throws JspException, IllegalAccessException, InstantiationException, ClassNotFoundException
{
+    for (Tld tld : tlds) {
+      for (net.sf.maventaglib.checker.Tag tag : tld.getTags()) {
+        javax.servlet.jsp.tagext.Tag tagInstance = getTagInstance(tag);
+        if (tagInstance instanceof UIComponentTag) {
+          LOG.info("testing tag: " + tagInstance.getClass().getName());
+          testComponent(tagInstance);
+        }
+      }
     }
   }
 
@@ -141,9 +142,9 @@
       Object disabled = component.getAttributes().get(ATTR_DISABLED);
       LOG.debug("disabled = '" + disabled + "'");
       Map attributes = component.getAttributes();
-      for (Iterator i = attributes.keySet().iterator(); i.hasNext(); ){
+      for (Iterator i = attributes.keySet().iterator(); i.hasNext();) {
         Object value = i.next();
-        LOG.debug("value = "  + value);
+        LOG.debug("value = " + value);
       }
       Object height = attributes.get(ATTR_HEIGHT);
       LOG.debug("height = '" + height + "'");

Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTagUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTagUnitTest.java?view=diff&rev=511617&r1=511616&r2=511617
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTagUnitTest.java
(original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTagUnitTest.java
Sun Feb 25 13:18:04 2007
@@ -17,167 +17,20 @@
  * limitations under the License.
  */
 
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.tobago.mock.servlet.MockPageContext;
-import org.xml.sax.SAXException;
-
-import javax.servlet.jsp.tagext.Tag;
-import java.beans.PropertyDescriptor;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
 
 public class GenericTagUnitTest extends GenericTestBase {
-// ----------------------------------------------------------- class attributes
-
-  private static final Log LOG = LogFactory.getLog(GenericTagUnitTest.class);
-
-// --------------------------------------------------------------- constructors
 
   public GenericTagUnitTest(String name) {
     super(name);
-  }
-
-// ----------------------------------------------------------- business methods
-
-/*
-  private TagLibraryInfo getTagLibraryInfo() throws IOException, SAXException {
-    InputStream tld = getClass().getClassLoader().getResourceAsStream(
-        "com/atanion/tobago/taglib/component/tobago.tld");
-    assertNotNull(tld);
-    TldParser parser = new TldParser();
-    TagLibraryInfo tagLibraryInfo = parser.parse(tld);
-    return tagLibraryInfo;
-  }
-*/
-
-  public void testReleaseOrdinaryTags() throws IllegalAccessException,
-      NoSuchMethodException, InvocationTargetException, IOException,
-      SAXException {
-    for (int i = 0; i < ordinaryTagList.length; i++) {
-      Tag tag = ordinaryTagList[i];
-      testRelease(tag);
-    }
-  }
 
-  public void testReleaseUIComponentTags() throws IllegalAccessException,
-      NoSuchMethodException, InvocationTargetException, IOException,
-      SAXException {
-    for (int i = 0; i < componentTagList.length; i++) {
-      Tag tag = componentTagList[i];
-      testRelease(tag);
-    }
   }
 
-/*
-  public void testSetterExist() throws NoSuchMethodException,
-      IllegalAccessException, InvocationTargetException, IOException,
-      SAXException, ClassNotFoundException, InstantiationException {
-
-    TagLibraryInfo tagLibraryInfo = getTagLibraryInfo();
-    TagInfo[] tags = tagLibraryInfo.getTags();
-
-    for (int i = 0; i < tags.length; i++) {
-      TagInfo tag = tags[i];
-      String className = tag.getTagClassName();
-      TagAttributeInfo[] attributes = tag.getAttributes();
-      for (int j = 0; j < attributes.length; j++) {
-        TagAttributeInfo attribute = attributes[j];
-        String name = attribute.getName();
-        checkSetter(className, name);
-      }
-    }
+  protected void setUp() throws Exception {
+    super.setUp();
+    tldPaths = new String[2];
+		tldPaths[0] = "META-INF/org/apache/myfaces/tobago/taglib/component/tobago.tld";
+		tldPaths[1] = "META-INF/org/apache/myfaces/tobago/taglib/extension/tobago-extension.tld";
   }
 
-*/
-  private void checkSetter(String className, String name)
-      throws IllegalAccessException, InstantiationException,
-      NoSuchMethodException, InvocationTargetException, ClassNotFoundException {
-    Class tagClass = Class.forName(className);
-    Tag tagObject = (Tag) tagClass.newInstance();
-    PropertyDescriptor propertyDescriptor
-        = PropertyUtils.getPropertyDescriptor(tagObject, name);
-    assertNotNull("setter '" + name + "' of class " + className + " has " +
-        "property descriptor.",
-        propertyDescriptor);
-    assertNotNull("setter '" + name + "' of class " + className + " exists.",
-        propertyDescriptor.getWriteMethod());
-  }
-
-  private void testRelease(Tag tag) throws NoSuchMethodException,
-      IllegalAccessException, InvocationTargetException, IOException,
-      SAXException {
-    tag.setPageContext(new MockPageContext());
-
-    HashMap initialValues = new HashMap();
-    PropertyDescriptor descriptors[] =
-        PropertyUtils.getPropertyDescriptors(tag);
-//    TagLibraryInfo tagLibraryInfo = getTagLibraryInfo();
-//    TagInfo[] tags = tagLibraryInfo.getTags();
-
-    // store initial values
-    for (int i = 0; i < descriptors.length; i++) {
-      if (isTagProperty(descriptors[i])) {
-        String name = descriptors[i].getName();
-
-        Object value = PropertyUtils.getSimpleProperty(tag, name);
-        initialValues.put(name, value);
-      }
-    }
-
-    // set new values
-    for (int i = 0; i < descriptors.length; i++) {
-      if (isTagProperty(descriptors[i])) {
-        String name = descriptors[i].getName();
-
-        Class propertyType = descriptors[i].getPropertyType();
-        Object value = null;
-        if (propertyType == String.class) {
-          value = new String("bla");
-        } else if (propertyType == Integer.TYPE) {
-          value = new Integer(42);
-        } else if (propertyType == Boolean.TYPE) {
-          value = Boolean.TRUE;
-        } else {
-          LOG.debug("Unsupported property type '" + propertyType
-              + "' for property '" + name + "'");
-        }
-        PropertyUtils.setSimpleProperty(tag, name, value);
-      }
-    }
-
-    tag.release();
-
-    // check released values
-    for (int i = 0; i < descriptors.length; i++) {
-      if (isTagProperty(descriptors[i])) {
-        String name = descriptors[i].getName();
-        // XXX: who releases id?
-        if (name.equals("id")) continue;
-        try {
-          Object newValue = PropertyUtils.getSimpleProperty(tag, name);
-          Object oldValue = initialValues.get(name);
-          String msg = "release of property '" + name + "' for tag '"
-              + tag.getClass().getName() + "' failed.";
-          assertEquals(msg, oldValue, newValue);
-          // XXX: first error stops loop
-          // if (newValue != null && !newValue.equals(oldValue)) {
-        } catch (NoSuchMethodException e1) {
-          LOG.error("", e1);
-        }
-      }
-    }
-  }
-
-  private boolean isTagProperty(PropertyDescriptor descriptor) {
-    if ("parent".equals(descriptor.getName())) {
-      return false;
-    } else {
-      return descriptor.getReadMethod() != null
-          && descriptor.getWriteMethod() != null;
-    }
-  }
 }
 

Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTestBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTestBase.java?view=diff&rev=511617&r1=511616&r2=511617
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTestBase.java
(original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/taglib/component/GenericTestBase.java
Sun Feb 25 13:18:04 2007
@@ -19,64 +19,167 @@
 
 import junit.framework.TestCase;
 
-import javax.faces.webapp.UIComponentTag;
 import javax.servlet.jsp.tagext.Tag;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
 
-public abstract class GenericTestBase extends TestCase {
-// ----------------------------------------------------------- class attributes
-
-// ----------------------------------------------------------------- attributes
+import net.sf.maventaglib.checker.Tld;
+import net.sf.maventaglib.checker.TldParser;
+import net.sf.maventaglib.checker.TagAttribute;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.beans.PropertyDescriptor;
+import java.util.HashMap;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.tobago.mock.servlet.MockPageContext;
 
-  protected UIComponentTag[] componentTagList;
-  protected Tag[] ordinaryTagList;
+public abstract class GenericTestBase extends TestCase {
+  private static final Log LOG = LogFactory.getLog(GenericTestBase.class);
 
-// --------------------------------------------------------------- constructors
+  protected Tld[] tlds;
+  protected String[] tldPaths;
 
   public GenericTestBase(String name) {
     super(name);
-    componentTagList = new UIComponentTag[]{
-      new ButtonTag(),
-      new CalendarTag(),
-      new CellTag(),
-      new SelectManyCheckboxTag(),
-      new SelectBooleanCheckboxTag(),
-      new ColumnTag(),
-      new DateTag(),
-      new FileTag(),
-      new FormTag(),
-      new GridLayoutTag(),
-      new BoxTag(),
-      new HiddenTag(),
-      new ImageTag(),
-      new InTag(),
-      new SelectReferenceTag(),
-      new LabelTag(),
-      new LinkTag(),
-      new MenuBarTag(),
-      new MessagesTag(),
-      new MessageTag(),
-      new SelectManyListboxTag(),
-      new PageTag(),
-      new PanelTag(),
-      new ProgressTag(),
-      new SelectOneRadioTag(),
-      //new RichTextEditorTag(),
-      new SheetTag(),
-      new SelectOneTag(),
-      new TabGroupTag(),
-      new TabTag(),
-      new TextAreaTag(),
-      new OutTag(),
-      new ToolBarTag(),
-      new TreeOldTag(),
-    };
-    ordinaryTagList = new Tag[]{
-      new IncludeTag(),
-      new LoadBundleTag(),
-      new ScriptTag(),
-      new StyleTag(),
-    };
   }
 
+  protected void setUp() throws Exception {
+    super.setUp();
+    tlds = new Tld[tldPaths.length];
+    for (int i = 0; i < tldPaths.length; i++) {
+      InputStream stream = getClass().getClassLoader().getResourceAsStream(tldPaths[i]);
+      tlds[i] = getTld(tldPaths[i], stream);
+      stream.close();
+    }
+  }
+
+    public void testRelease() throws IllegalAccessException,
+      NoSuchMethodException, InvocationTargetException, IOException,
+        SAXException, ClassNotFoundException, InstantiationException {
+    for (Tld tld:tlds){
+      for (net.sf.maventaglib.checker.Tag tag:tld.getTags()) {
+        Tag tagInstance = getTagInstance(tag);
+        checkRelease(tagInstance);
+      }
+    }
+  }
+
+  public void testSetterExist() throws NoSuchMethodException,
+      IllegalAccessException, InvocationTargetException, IOException,
+      SAXException, ClassNotFoundException, InstantiationException {
+
+    for (Tld tld:tlds){
+      for (net.sf.maventaglib.checker.Tag tag:tld.getTags()) {
+        Tag tagInstance = getTagInstance(tag);
+        TagAttribute[] attributes = tag.getAttributes();
+        for (TagAttribute attribute : attributes) {
+          String name = attribute.getAttributeName();
+          checkSetter(tagInstance, name);
+        }
+      }
+    }
+  }
+
+  protected Tag getTagInstance(net.sf.maventaglib.checker.Tag tag)
+      throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+    String className = tag.getTagClass();
+    Class tagClass = Class.forName(className);
+    return (Tag) tagClass.newInstance();
+  }
+
+  private void checkSetter(javax.servlet.jsp.tagext.Tag tagObject, String name)
+      throws IllegalAccessException, InstantiationException,
+      NoSuchMethodException, InvocationTargetException, ClassNotFoundException {
+    PropertyDescriptor propertyDescriptor
+        = PropertyUtils.getPropertyDescriptor(tagObject, name);
+    assertNotNull("setter '" + name + "' of class " + tagObject.getClass().getName() + "
has " +
+        "property descriptor.", propertyDescriptor);
+    assertNotNull("setter '" + name + "' of class " + tagObject.getClass().getName() + "
exists.",
+        propertyDescriptor.getWriteMethod());
+  }
+
+  private void checkRelease(javax.servlet.jsp.tagext.Tag tag) throws NoSuchMethodException,
+      IllegalAccessException, InvocationTargetException, IOException,
+      SAXException {
+    tag.setPageContext(new MockPageContext());
+
+    HashMap initialValues = new HashMap();
+    PropertyDescriptor descriptors[] =
+        PropertyUtils.getPropertyDescriptors(tag);
+
+    // store initial values
+    for (int i = 0; i < descriptors.length; i++) {
+      if (isTagProperty(descriptors[i])) {
+        String name = descriptors[i].getName();
+        Object value = PropertyUtils.getSimpleProperty(tag, name);
+        initialValues.put(name, value);
+      }
+    }
+
+    // set new values
+    for (int i = 0; i < descriptors.length; i++) {
+      if (isTagProperty(descriptors[i])) {
+        String name = descriptors[i].getName();
+        Class propertyType = descriptors[i].getPropertyType();
+        Object value = null;
+        if (propertyType == String.class) {
+          value = new String("bla");
+        } else if (propertyType == Integer.TYPE) {
+          value = new Integer(42);
+        } else if (propertyType == Boolean.TYPE) {
+          value = Boolean.TRUE;
+        } else {
+          LOG.debug("Unsupported property type '" + propertyType
+              + "' for property '" + name + "'");
+        }
+        PropertyUtils.setSimpleProperty(tag, name, value);
+      }
+    }
+
+    tag.release();
+
+    // check released values
+    for (int i = 0; i < descriptors.length; i++) {
+      if (isTagProperty(descriptors[i])) {
+        String name = descriptors[i].getName();
+        // XXX: who releases id?
+        if (name.equals("id")) continue;
+        try {
+          Object newValue = PropertyUtils.getSimpleProperty(tag, name);
+          Object oldValue = initialValues.get(name);
+          String msg = "release of property '" + name + "' for tag '"
+              + tag.getClass().getName() + "' failed.";
+          assertEquals(msg, oldValue, newValue);
+          // XXX: first error stops loop
+          // if (newValue != null && !newValue.equals(oldValue)) {
+        } catch (NoSuchMethodException e1) {
+          LOG.error("", e1);
+        }
+      }
+    }
+  }
+
+  private boolean isTagProperty(PropertyDescriptor descriptor) {
+    if ("parent".equals(descriptor.getName())) {
+      return false;
+    } else {
+      return descriptor.getReadMethod() != null
+          && descriptor.getWriteMethod() != null;
+    }
+  }
+
+  private Tld getTld(String name, InputStream stream) throws Exception {
+    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+    DocumentBuilder db = dbf.newDocumentBuilder();
+    Document doc = db.parse(stream);
+    return TldParser.parse(doc, name);
+  }
 }
 



Mime
View raw message