imported testcase for [DIGESTER-163]

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/digester/trunk@1300873 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/src/test/java/org/apache/commons/digester3/binder/Digester163TestCase.java b/core/src/test/java/org/apache/commons/digester3/binder/Digester163TestCase.java
new file mode 100644
index 0000000..acdb4c0
--- /dev/null
+++ b/core/src/test/java/org/apache/commons/digester3/binder/Digester163TestCase.java
@@ -0,0 +1,121 @@
+package org.apache.commons.digester3.binder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.fail;
+import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.digester3.Digester;
+import org.apache.commons.digester3.xmlrules.FromXmlRulesModule;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test.
+ */
+public class Digester163TestCase
+{
+
+    public static final int MAX_THREADS = 4;
+
+    private DigesterLoader loader;
+
+    @Before
+    public void setUp()
+    {
+        loader = newLoader( new FromXmlRulesModule()
+        {
+
+            @Override
+            protected void loadRules()
+            {
+                loadXMLRules( getClass().getResourceAsStream( "rules.xml" ) );
+            }
+
+        } );
+    }
+
+    @Test
+    public void test()
+        throws InterruptedException
+    {
+        ThreadPoolExecutor executor = new ThreadPoolExecutor( MAX_THREADS, MAX_THREADS,
+                                                              Long.MAX_VALUE,
+                                                              TimeUnit.NANOSECONDS,
+                                                              new LinkedBlockingQueue<Runnable>() );
+        for ( int i = 0; i < MAX_THREADS * 2; i++ )
+        {
+            executor.submit( new Runnable()
+            {
+
+                public void run()
+                {
+                    Digester dig = loader.newDigester();
+                    InputStream in = null;
+                    try
+                    {
+                        in = this.getClass().getClassLoader().getResourceAsStream( "test.xml" );
+                        Entity et = dig.parse( in );
+                        assertEquals( "Author 1", et.getAuthor() );
+                    }
+                    catch ( Exception e )
+                    {
+                        fail( e.getMessage() );
+                    }
+                    finally
+                    {
+                        if ( in != null )
+                        {
+                            try
+                            {
+                                in.close();
+                            }
+                            catch ( IOException e )
+                            {
+                                // close quietly
+                            }
+                        }
+                    }
+                }
+            } );
+        }
+
+        while ( !executor.awaitTermination( 10, TimeUnit.MILLISECONDS ) )
+        {
+            if ( executor.getQueue().isEmpty() )
+            {
+                executor.shutdown();
+            }
+            if ( executor.isTerminated() )
+            {
+                break;
+            }
+        }
+    }
+
+}
diff --git a/core/src/test/java/org/apache/commons/digester3/binder/Entity.java b/core/src/test/java/org/apache/commons/digester3/binder/Entity.java
new file mode 100644
index 0000000..bb472a3
--- /dev/null
+++ b/core/src/test/java/org/apache/commons/digester3/binder/Entity.java
@@ -0,0 +1,46 @@
+package org.apache.commons.digester3.binder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Entity.
+ */
+public class Entity
+{
+
+    private String author = null;
+
+    /**
+     * @return Returns the author.
+     */
+    public String getAuthor()
+    {
+        return author;
+    }
+
+    /**
+     * @param author The author to set.
+     */
+    public void setAuthor( String author )
+    {
+        this.author = author;
+    }
+
+}
diff --git a/core/src/test/resources/org/apache/commons/digester3/binder/rules.xml b/core/src/test/resources/org/apache/commons/digester3/binder/rules.xml
new file mode 100644
index 0000000..ac04b84
--- /dev/null
+++ b/core/src/test/resources/org/apache/commons/digester3/binder/rules.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!DOCTYPE digester-rules PUBLIC "-//Apache Commons //DTD digester-rules XML V1.0//EN" "http://commons.apache.org/digester/dtds/digester-rules-3.0.dtd">
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   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"/>
+</digester-rules>
diff --git a/core/src/test/resources/org/apache/commons/digester3/binder/test.xml b/core/src/test/resources/org/apache/commons/digester3/binder/test.xml
new file mode 100644
index 0000000..ef5cc34
--- /dev/null
+++ b/core/src/test/resources/org/apache/commons/digester3/binder/test.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<root>
+  <container>
+    <header>
+      <authors>
+        <author>Author 1</author>
+      </authors>
+    </header>
+  </container>
+</root>