[jboss-cvs] JBossAS SVN: r82242 - in projects/ejb3/trunk/testsuite: src and 13 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 12 07:32:27 EST 2008


Author: wolfc
Date: 2008-12-12 07:32:27 -0500 (Fri, 12 Dec 2008)
New Revision: 82242

Added:
   projects/ejb3/trunk/testsuite/src/main/
   projects/ejb3/trunk/testsuite/src/main/java/
   projects/ejb3/trunk/testsuite/src/main/java/org/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/Hack.java
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/ant/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/ant/taskdefs/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/ant/taskdefs/optional/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/ant/taskdefs/optional/junit/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/ant/taskdefs/optional/junit/KnownIssuesXMLJUnitResultFormatter.java
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/knownissue/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/knownissue/KnownIssues.java
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/lang/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/lang/reflect/
   projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/lang/reflect/Invoker.java
Modified:
   projects/ejb3/trunk/testsuite/.classpath
   projects/ejb3/trunk/testsuite/build-test.xml
   projects/ejb3/trunk/testsuite/pom.xml
Log:
EJBTHREE-1620: allow for configuration of known issues

Modified: projects/ejb3/trunk/testsuite/.classpath
===================================================================
--- projects/ejb3/trunk/testsuite/.classpath	2008-12-12 11:45:30 UTC (rev 82241)
+++ projects/ejb3/trunk/testsuite/.classpath	2008-12-12 12:32:27 UTC (rev 82242)
@@ -1,7 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-  <classpathentry kind="src" path="src/test/java" output="eclipse-target/tests-classes"/>
-  <classpathentry kind="src" path="src/test/resources" output="eclipse-target/tests-classes" excluding="**/*.java"/>
-  <classpathentry kind="output" path="eclipse-target/classes"/>
-  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
-</classpath>
\ No newline at end of file
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="src" output="eclipse-target/tests-classes" path="src/test/java"/>
+	<classpathentry excluding="**/*.java" kind="src" output="eclipse-target/tests-classes" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="var" path="JBOSS_HOME/client/jbossall-client.jar"/>
+	<classpathentry kind="output" path="eclipse-target/classes"/>
+</classpath>

Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml	2008-12-12 11:45:30 UTC (rev 82241)
+++ projects/ejb3/trunk/testsuite/build-test.xml	2008-12-12 12:32:27 UTC (rev 82242)
@@ -4337,6 +4337,7 @@
          <sysproperty key="jbosstest.cluster.node1.jndi.url" value="${node1.jndi.url}"/>
          <sysproperty key="java.naming.provider.url" value="${test.jndi.url}"/>
 
+         <sysproperty key="knownIssuesFile" value="${resources}/known-issues.xml"/>
 
          <jvmarg line="${jvmargs}" />
          <jvmarg line="-ea" />
@@ -4345,7 +4346,8 @@
          -->
 
          <classpath>
-           
+            <pathelement path="${location.target}/jboss-ejb3-testsuite.jar"/>
+            
            <path refid="test.classpath" />
            
             <!-- 
@@ -4395,7 +4397,12 @@
          </classpath>
 
          <formatter type="plain" usefile="true"/>
-         <formatter type="xml" usefile="true" unless="test.extension"/>
+         <!-- 
+         <formatter type="xml" classname="org.jboss.ejb3.testsuite.ant.taskdefs.optional.junit.KnownIssuesXMLJunitResultFormatter"
+            usefile="true" unless="test.extension"/>
+            -->
+         <formatter type="xml" classname="org.jboss.ejb3.testsuite.Hack"
+            usefile="true" unless="test.extension"/>
          <sysproperty key="jboss-junit-configuration" value="${jboss-junit-configuration}"/>  
          <formatter type="xml" classname="org.jboss.ant.taskdefs.XMLJUnitMultipleResultFormatter" 
                     extension="-${test.extension}.xml" usefile="true" if="test.extension"/>

Modified: projects/ejb3/trunk/testsuite/pom.xml
===================================================================
--- projects/ejb3/trunk/testsuite/pom.xml	2008-12-12 11:45:30 UTC (rev 82241)
+++ projects/ejb3/trunk/testsuite/pom.xml	2008-12-12 12:32:27 UTC (rev 82242)
@@ -202,10 +202,16 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <scope>test</scope>
+      <scope>compile</scope>
     </dependency>
 
     <dependency>
+      <groupId>org.apache.ant</groupId>
+      <artifactId>ant-junit</artifactId>
+      <version>1.7.0</version>
+    </dependency>
+    
+    <dependency>
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-core</artifactId>
       <version>1.0.0-SNAPSHOT</version>

Added: projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/Hack.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/Hack.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/Hack.java	2008-12-12 12:32:27 UTC (rev 82242)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.testsuite;
+
+import org.jboss.ejb3.testsuite.ant.taskdefs.optional.junit.KnownIssuesXMLJUnitResultFormatter;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class Hack extends KnownIssuesXMLJUnitResultFormatter
+{
+
+}

Added: projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/ant/taskdefs/optional/junit/KnownIssuesXMLJUnitResultFormatter.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/ant/taskdefs/optional/junit/KnownIssuesXMLJUnitResultFormatter.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/ant/taskdefs/optional/junit/KnownIssuesXMLJUnitResultFormatter.java	2008-12-12 12:32:27 UTC (rev 82242)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.testsuite.ant.taskdefs.optional.junit;
+
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+
+import junit.framework.Test;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitVersionHelper;
+import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter;
+import org.jboss.ejb3.testsuite.knownissue.KnownIssues;
+import org.jboss.ejb3.testsuite.lang.reflect.Invoker;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class KnownIssuesXMLJUnitResultFormatter extends XMLJUnitResultFormatter
+{
+   private static Method formatErrorMethod;
+   static {
+      formatErrorMethod = Invoker.getMethod(XMLJUnitResultFormatter.class, "formatError", String.class, Test.class, Throwable.class);
+   }
+   
+   protected Hashtable<Test, Test> failedTests;
+   private long runCount = 0, failures = 0, errors = 0;
+   
+   public KnownIssuesXMLJUnitResultFormatter()
+   {
+      super();
+      this.failedTests = Invoker.getFieldValue(this, XMLJUnitResultFormatter.class, "failedTests");
+   }
+   
+   @Override
+   public void addError(Test test, Throwable t)
+   {
+      errors++;
+      super.addError(test, t);
+   }
+   
+   @Override
+   public void addFailure(Test test, Throwable t)
+   {
+      String className = test.getClass().getCanonicalName();
+      String name = className + "." + JUnitVersionHelper.getTestCaseName(test);
+      KnownIssues.Action action = KnownIssues.getAction(name);
+      switch(action)
+      {
+         case FAIL:
+            failures++;
+            super.addFailure(test, t);
+            return;
+         case IGNORE:
+            return;
+         case SHOW:
+            formatError("known-issue", test, t);
+            // since nobody understand the above, let's paste it to stderr also
+            t.printStackTrace();
+            // it's not really a failure, so don't count it
+            return;
+      }
+      throw new RuntimeException("Illegal action encountered " + action + " on test " + name);
+   }
+   
+   @Override
+   public void endTest(Test test)
+   {
+      // formatError also calls endTest
+      if(!failedTests.contains(test))
+         runCount += test.countTestCases();
+      super.endTest(test);
+   }
+   
+   @Override
+   public void endTestSuite(JUnitTest suite) throws BuildException
+   {
+      long oldRunCount = suite.runCount();
+      assert runCount == oldRunCount : "runCount (" + runCount + ") != oldRunCount (" + oldRunCount + ")";
+      assert (failures + errors) <= runCount : "(failures + errors) > runCount";
+      suite.setCounts(runCount, failures, errors);
+      super.endTestSuite(suite);
+   }
+   
+   protected void formatError(String type, Test test, Throwable t)
+   {
+      // expose formatError the hacky way
+      Invoker.invoke(formatErrorMethod, this, type, test, t);
+   }
+   
+   @Override
+   public void startTestSuite(JUnitTest suite)
+   {
+      runCount = 0;
+      failures = 0;
+      errors = 0;
+      super.startTestSuite(suite);
+   }
+}


Property changes on: projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/ant/taskdefs/optional/junit/KnownIssuesXMLJUnitResultFormatter.java
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/knownissue/KnownIssues.java (from rev 82240, branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/JBossWithKnownIssuesTestCase.java)
===================================================================
--- projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/knownissue/KnownIssues.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/knownissue/KnownIssues.java	2008-12-12 12:32:27 UTC (rev 82242)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.testsuite.knownissue;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * 
+ * Per default all known issues will fail. To override specify
+ * a known issues properties file via -DknownIssues=filename.
+ * 
+ * This file contains the action to take when a known issue is encountered.
+ * 
+ * The following actions are allowed:
+ * - fail : fail the test (set this when an issue is resolved)
+ * - ignore : do nothing
+ * - show : show the issue on System.err
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision$
+ */
+public abstract class KnownIssues
+{
+   public static enum Action
+   {
+      FAIL,
+      IGNORE,
+      SHOW
+   };
+   
+   private static Properties actions = null;
+   
+   private KnownIssues()
+   {
+   }
+   
+   public static Action getAction(String issue)
+   {
+      Properties actions = getActions();
+      if(actions == null)
+         return Action.FAIL;
+      String action = actions.getProperty(issue);
+      if(action == null)
+         return Action.FAIL;
+      action = action.toUpperCase();
+      return Action.valueOf(action);
+   }
+   
+   private static Properties getActions()
+   {
+      if(actions != null)
+         return actions;
+      
+      actions = new Properties();
+      String fileName = System.getProperty("knownIssuesFile");
+      if(fileName == null || fileName.length() == 0)
+         return actions;
+      
+      try
+      {
+         File file = new File(fileName);
+         FileInputStream in = new FileInputStream(file.getAbsolutePath());
+         try
+         {
+            if(fileName.endsWith(".xml"))
+               actions.loadFromXML(in);
+            else
+               actions.load(in);
+         }
+         finally
+         {
+            in.close();
+         }
+         return actions;
+      }
+      catch(IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}

Added: projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/lang/reflect/Invoker.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/lang/reflect/Invoker.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/main/java/org/jboss/ejb3/testsuite/lang/reflect/Invoker.java	2008-12-12 12:32:27 UTC (rev 82242)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.testsuite.lang.reflect;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+/**
+ * Kick a class in the privates. :-)
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class Invoker
+{
+   public static Field getField(Class<?> cls, String fieldName)
+   {
+      try
+      {
+         Field field = cls.getDeclaredField(fieldName);
+         field.setAccessible(true);
+         return field;
+      }
+      catch (SecurityException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (NoSuchFieldException e)
+      {
+         throw new RuntimeException("No such field, choices are " + Arrays.toString(cls.getDeclaredFields()), e);
+      }
+   }
+   
+   /**
+    * Get the contents of a (private) field.
+    * 
+    * Slow!
+    * 
+    * @param <R>
+    * @param obj
+    * @param cls
+    * @param name
+    * @return
+    */
+   @SuppressWarnings("unchecked")
+   public static <R> R getFieldValue(Object obj, Class<?> cls, String name)
+   {
+      assert cls.isAssignableFrom(obj.getClass()) : "obj " + obj + " is not of a sub-class of " + cls;
+      Field field = getField(cls, name);
+      return (R) getFieldValue(field, obj);
+   }
+   
+   /**
+    * @param field
+    * @param obj
+    * @return
+    */
+   @SuppressWarnings("unchecked")
+   public static <R> R getFieldValue(Field field, Object obj)
+   {
+      try
+      {
+         return (R) field.get(obj);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public static Method getMethod(Class<?> cls, String methodName, Class<?>... parameterTypes)
+   {
+      try
+      {
+         Method method = cls.getDeclaredMethod(methodName, parameterTypes);
+         method.setAccessible(true);
+         return method;
+      }
+      catch (SecurityException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (NoSuchMethodException e)
+      {
+         throw new RuntimeException("No such method, choices are " + Arrays.toString(cls.getDeclaredMethods()), e);
+      }
+   }
+   
+   public static Object invoke(Method method, Object obj, Object... args)
+   {
+      try
+      {
+         return method.invoke(obj, args);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (InvocationTargetException e)
+      {
+         try
+         {
+            throw e.getTargetException();
+         }
+         catch(Error error)
+         {
+            throw error;
+         }
+         catch(RuntimeException re)
+         {
+            throw re;
+         }
+         catch(Throwable th)
+         {
+            throw new RuntimeException(th);
+         }
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list