commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1301174 - in /commons/proper/digester/trunk/core/src/test: java/org/apache/commons/digester3/binder/Digester163TestCase.java resources/org/apache/commons/digester3/binder/rules.xml resources/org/apache/commons/digester3/binder/test.xml
Date Thu, 15 Mar 2012 20:04:56 GMT
Author: simonetripodi
Date: Thu Mar 15 20:04:56 2012
New Revision: 1301174

URL: http://svn.apache.org/viewvc?rev=1301174&view=rev
Log:
added (occasionally) failing test related to [DIGESTER-163]

Modified:
    commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/binder/Digester163TestCase.java
    commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/rules.xml
    commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/test.xml

Modified: commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/binder/Digester163TestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/binder/Digester163TestCase.java?rev=1301174&r1=1301173&r2=1301174&view=diff
==============================================================================
--- commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/binder/Digester163TestCase.java
(original)
+++ commons/proper/digester/trunk/core/src/test/java/org/apache/commons/digester3/binder/Digester163TestCase.java
Thu Mar 15 20:04:56 2012
@@ -24,7 +24,7 @@ import static junit.framework.Assert.fai
 import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
 
 import java.io.IOException;
-import java.io.InputStream;
+import java.net.URL;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
@@ -33,6 +33,7 @@ import org.apache.commons.digester3.Dige
 import org.apache.commons.digester3.xmlrules.FromXmlRulesModule;
 import org.junit.Before;
 import org.junit.Test;
+import org.xml.sax.SAXException;
 
 /**
  * Test.
@@ -47,19 +48,30 @@ public class Digester163TestCase
     @Before
     public void before()
     {
+        final URL url = getClass().getResource( "rules.xml" );
         loader = newLoader( new FromXmlRulesModule()
         {
-
             @Override
             protected void loadRules()
             {
-                loadXMLRules( getClass().getResourceAsStream( "rules.xml" ) );
+                loadXMLRules( url );
             }
 
         } );
     }
 
     @Test
+    public void testSingle()
+        throws IOException, SAXException
+    {
+        Digester dig = loader.newDigester();
+        URL url = Digester163TestCase.class.getResource( "test.xml" );
+        // lets parse - result does not matter here
+        Entity et = dig.parse( url );
+        assertEquals( "Author 1", et.getAuthor() );
+    }
+
+    @Test
     public void test()
         throws InterruptedException
     {
@@ -68,43 +80,24 @@ public class Digester163TestCase
                                                               Long.MAX_VALUE,
                                                               TimeUnit.NANOSECONDS,
                                                               new LinkedBlockingQueue<Runnable>()
);
+        final URL url = Digester163TestCase.class.getResource( "test.xml" );
         final LinkedBlockingQueue<Exception> exceptions = new LinkedBlockingQueue<Exception>();
         for ( int i = 0; i < MAX_THREADS * 2; i++ )
         {
             executor.submit( new Runnable()
             {
-
                 public void run()
                 {
-
-                    Digester dig = null;
-                    InputStream in = null;
                     try
                     {
-                        dig = loader.newDigester();
-                        in = Digester163TestCase.class.getResourceAsStream( "test.xml" );
-                        Entity et = dig.parse( in );
-                        assertEquals( "Author 1", et.getAuthor() );
+                        Digester dig = loader.newDigester();
+                        // lets parse - result does not matter here
+                        dig.parse( url );
                     }
                     catch ( Exception e )
                     {
                         exceptions.add( e );
                     }
-                    finally
-                    {
-                        if ( in != null )
-                        {
-                            try
-                            {
-                                in.close();
-                            }
-                            catch ( IOException e )
-                            {
-                                // close quietly
-                            }
-                        }
-                    }
-
                 }
             } );
         }
@@ -121,12 +114,20 @@ public class Digester163TestCase
             }
         }
 
-        Exception e = exceptions.poll();
+        Exception e = exceptions.peek();
         if ( e != null )
         {
-            e.printStackTrace();
-            fail( "Throwable caught -> " + e.getMessage() != null ? e.getMessage() : ""
);
+            while ( true )
+            {
+                e = exceptions.poll();
+                if ( e == null )
+                {
+                    break;
+                }
+                e.printStackTrace();
+            }
+            fail( "Caught " + exceptions.size() + " exceptions." );
         }
-
     }
+
 }

Modified: commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/rules.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/rules.xml?rev=1301174&r1=1301173&r2=1301174&view=diff
==============================================================================
--- commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/rules.xml
(original)
+++ commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/rules.xml
Thu Mar 15 20:04:56 2012
@@ -17,7 +17,10 @@
    limitations under the License.
 -->
 <digester-rules>
-  <object-create-rule classname="org.apache.commons.digester3.binder.Entity" pattern="container"/>
-  <!-- author -->
-  <call-method-rule methodname="setAuthor" paramcount="1" pattern="container/header/authors/author"/>
+  <pattern value="employee">
+    <object-create-rule classname="org.apache.commons.digester3.binder.Entity" />
+    <pattern value="name">
+      <call-method-rule methodname="setAuthor" paramcount="1" paramtypes="java.lang.String"
usingElementBodyAsArgument="true" />
+    </pattern>
+  </pattern>  
 </digester-rules>

Modified: commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/test.xml
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/test.xml?rev=1301174&r1=1301173&r2=1301174&view=diff
==============================================================================
--- commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/test.xml
(original)
+++ commons/proper/digester/trunk/core/src/test/resources/org/apache/commons/digester3/binder/test.xml
Thu Mar 15 20:04:56 2012
@@ -15,10 +15,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 -->
-<container>
-  <header>
-    <authors>
-      <author>Author 1</author>
-    </authors>
-  </header>
-</container>
+<employee>
+  <name>Author 1</name>
+</employee> 



Mime
View raw message