[jboss-cvs] JBossAS SVN: r106815 - in projects/jboss-jca/trunk/common: src and 11 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 19 09:37:40 EDT 2010


Author: maeste
Date: 2010-07-19 09:37:38 -0400 (Mon, 19 Jul 2010)
New Revision: 106815

Added:
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/OverrideElementAttribute.java
   projects/jboss-jca/trunk/common/src/test/
   projects/jboss-jca/trunk/common/src/test/java/
   projects/jboss-jca/trunk/common/src/test/java/org/
   projects/jboss-jca/trunk/common/src/test/java/org/jboss/
   projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/
   projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/
   projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/
   projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/ra/
   projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/ra/RaParserTestCase.java
   projects/jboss-jca/trunk/common/src/test/resources/
   projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-multiple-attributes.xml
   projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-no-attributes.xml
   projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-single-attribute.xml
Modified:
   projects/jboss-jca/trunk/common/build.xml
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/JbossRaParser.java
Log:
JBJCA-385: initial work on test suite

Modified: projects/jboss-jca/trunk/common/build.xml
===================================================================
--- projects/jboss-jca/trunk/common/build.xml	2010-07-19 13:30:48 UTC (rev 106814)
+++ projects/jboss-jca/trunk/common/build.xml	2010-07-19 13:37:38 UTC (rev 106815)
@@ -34,7 +34,7 @@
   <target name="compile">
     <mkdir dir="${build.common.dir}" />
 
-    <javac srcdir="src"
+    <javac srcdir="src/main"
            destdir="${build.common.dir}"
            classpathref="sjc.lib.path.id"
            debug="${javac.debug}">
@@ -83,5 +83,120 @@
       <fileset dir="${tools.dir}/api"/>
     </copy>
   </target>
+	
+	<!-- ================================= 
+	       Target: test
+	       ================================= -->
+	  <target name="test" depends="jars, prepare-test">
+	    <mkdir dir="${reports.dir}"/>
+	    <mkdir dir="${reports.dir}/common"/>
 
+	    <junit dir="src/test"
+	           printsummary="${junit.printsummary}"
+	           haltonerror="${junit.haltonerror}"
+	           haltonfailure="${junit.haltonfailure}"
+	           fork="${junit.fork}"
+	           timeout="${junit.timeout}">
+	      
+	      <jvmarg line="${junit.jvm.options}"/>
+	      <sysproperty key="archives.dir" value="${build.common.dir}"/>
+	      <sysproperty key="java.util.logging.manager" value="org.jboss.logmanager.LogManager"/>
+	      <sysproperty key="log4j.defaultInitOverride" value="true"/>
+	      <sysproperty key="org.jboss.logging.Logger.pluginClass" value="org.jboss.logging.logmanager.LoggerPluginImpl"/>
+	      <sysproperty key="test.dir" value="${test.dir}"/>
+	      <sysproperty key="xb.builder.useUnorderedSequence" value="true"/>
+	      <sysproperty key="javax.xml.stream.XMLInputFactory" value="com.sun.xml.internal.stream.XMLInputFactoryImpl"/>
+	      
+	      <classpath>
+	        <pathelement location="${build.common.dir}/test"/>
+	        <fileset dir="${target.dir}" includes="*.jar"/>
+	        <fileset dir="${lib.dir}/common" includes="*.jar" />
+	        <fileset dir="${lib.dir}/embedded" includes="*.jar" />
+	        <fileset dir="${lib.dir}/sjc" includes="*.jar" />
+	        <fileset dir="${lib.dir}/test" includes="*.jar" />
+	      </classpath>
+	      
+	      <formatter type="plain"/>
+	      <formatter type="xml"/>
+	      
+	      <batchtest todir="${reports.dir}/common"
+	                 haltonerror="${junit.batchtest.haltonerror}"
+	                 haltonfailure="${junit.batchtest.haltonfailure}"
+	                 fork="${junit.batchtest.fork}">
+	        
+	        <fileset dir="${build.common.dir}/test">
+	          <include name="**/*TestCase.class"/>
+	        </fileset>
+	      </batchtest>
+
+	    </junit>
+	    
+	  </target>
+
+
+	  <!-- ================================= 
+	       Target: one-test
+	       ================================= -->
+	  <target name="one-test" depends="jars, prepare-test">
+	    <mkdir dir="${reports.dir}"/>
+	    <mkdir dir="${reports.dir}/common"/>
+
+	    <junit dir="src/test"
+	           printsummary="${junit.printsummary}"
+	           haltonerror="${junit.haltonerror}"
+	           haltonfailure="${junit.haltonfailure}"
+	           fork="${junit.fork}"
+	           timeout="${junit.timeout}">
+	      
+	      <jvmarg line="${junit.jvm.options}"/>
+	      <sysproperty key="archives.dir" value="${build.common.dir}"/>
+	      <sysproperty key="java.util.logging.manager" value="org.jboss.logmanager.LogManager"/>
+	      <sysproperty key="log4j.defaultInitOverride" value="true"/>
+	      <sysproperty key="org.jboss.logging.Logger.pluginClass" value="org.jboss.logging.logmanager.LoggerPluginImpl"/>
+	      <sysproperty key="test.dir" value="${test.dir}"/>
+	      <sysproperty key="xb.builder.useUnorderedSequence" value="true"/>
+	      <sysproperty key="javax.xml.stream.XMLInputFactory" value="com.sun.xml.internal.stream.XMLInputFactoryImpl"/>
+	      
+	      <classpath>
+	        <pathelement location="${build.common.dir}/test"/>
+	        <fileset dir="${target.dir}" includes="*.jar"/>
+	        <fileset dir="${lib.dir}/common" includes="*.jar" />
+	        <fileset dir="${lib.dir}/embedded" includes="*.jar" />
+	        <fileset dir="${lib.dir}/sjc" includes="*.jar" />
+	        <fileset dir="${lib.dir}/test" includes="*.jar" />
+	      </classpath>
+	      
+	      <formatter type="plain"/>
+	      <formatter type="xml"/>
+	      
+	      <test todir="${reports.dir}/common" name="${test}"
+	                 haltonerror="${junit.batchtest.haltonerror}"
+	                 haltonfailure="${junit.batchtest.haltonfailure}"
+	                 fork="${junit.batchtest.fork}"/>
+	    </junit>
+	  </target>
+
+	  <!-- ================================= 
+	       Target: prepare-test
+	       ================================= -->
+	  <target name="prepare-test">
+	    <mkdir dir="${build.common.dir}" />
+	    <mkdir dir="${build.common.dir}/test" />
+
+	    <javac srcdir="src/test"
+	           destdir="${build.common.dir}/test"
+	           classpathref="test.lib.path.id"
+	           debug="${javac.debug}"
+	           deprecation="${javac.deprecation}"
+	           optimize="${javac.optimize}">
+	      <compilerarg value="-Xlint"/>
+	    </javac> 
+
+	    <copy todir="${build.common.dir}/test">
+	      <fileset dir="src/test/resources"/>
+	    </copy>
+
+
+	  </target>	
+
 </project>

Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/JbossRaParser.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/JbossRaParser.java	2010-07-19 13:30:48 UTC (rev 106814)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/JbossRaParser.java	2010-07-19 13:37:38 UTC (rev 106815)
@@ -61,59 +61,73 @@
    @Override
    public JbossRa parse(File xmlFile) throws Exception
    {
-      XMLInputFactory inputFactory = XMLInputFactory.newInstance();
-      InputStream input = new FileInputStream(xmlFile);
-      XMLStreamReader reader = inputFactory.createXMLStreamReader(input);
-      JbossRa jbossRa = null;
+      InputStream input = null;
+      XMLStreamReader reader = null;
 
-      while (reader.hasNext())
+      try
       {
-         switch (reader.nextTag())
+         XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+         input = new FileInputStream(xmlFile);
+         reader = inputFactory.createXMLStreamReader(input);
+         JbossRa jbossRa = null;
+
+         while (reader.hasNext())
          {
-            case END_ELEMENT : {
-               // should mean we're done, so ignore it.
-               break;
-            }
-            case START_ELEMENT : {
-               if (JbossRa10.NAMESPACE.equals(reader.getNamespaceURI()))
-               {
-                  switch (Tag.forName(reader.getLocalName()))
+            switch (reader.nextTag())
+            {
+               case END_ELEMENT : {
+                  // should mean we're done, so ignore it.
+                  break;
+               }
+               case START_ELEMENT : {
+                  if (JbossRa10.NAMESPACE.equals(reader.getNamespaceURI()))
                   {
-                     case JBOSSRA : {
-                        jbossRa = parseJbossRa10(reader);
-                        break;
+                     switch (Tag.forName(reader.getLocalName()))
+                     {
+                        case JBOSSRA : {
+                           jbossRa = parseJbossRa10(reader);
+                           break;
+                        }
+                        default :
+                           throw new ParserException("Unexpected element:" + reader.getLocalName());
                      }
-                     default :
-                        throw new ParserException("Unexpected element:" + reader.getLocalName());
+
                   }
-
-               }
-               else if (JbossRa20.NAMESPACE.equals(reader.getNamespaceURI()))
-               {
-                  switch (Tag.forName(reader.getLocalName()))
+                  else if (JbossRa20.NAMESPACE.equals(reader.getNamespaceURI()))
                   {
-                     case JBOSSRA : {
-                        jbossRa = parseJbossRa20(reader, jbossRa);
-                        break;
+                     switch (Tag.forName(reader.getLocalName()))
+                     {
+                        case JBOSSRA : {
+                           jbossRa = parseJbossRa20(reader, jbossRa);
+                           break;
+                        }
+                        default :
+                           throw new ParserException("Unexpected element:" + reader.getLocalName());
                      }
-                     default :
-                        throw new ParserException("Unexpected element:" + reader.getLocalName());
                   }
+                  else
+                  {
+                     throw new ParserException(String.format("Namespace %s is not supported by %s parser",
+                           reader.getNamespaceURI(), this.getClass().getName()));
+                  }
+
+                  break;
                }
-               else
-               {
-                  throw new ParserException(String.format("Namespace %s is not supported by %s parser",
-                        reader.getNamespaceURI(), this.getClass().getName()));
-               }
-
-               break;
+               default :
+                  throw new IllegalStateException();
             }
-            default :
-               throw new IllegalStateException();
          }
+         return jbossRa;
       }
-      return jbossRa;
+      finally
+      {
+         if (reader != null)
+            reader.close();
+         if (input != null)
+            input.close();
 
+      }
+
    }
 
    private JbossRa20 parseJbossRa20(XMLStreamReader reader, JbossRa jbossRa) throws XMLStreamException, ParserException

Added: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/OverrideElementAttribute.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/OverrideElementAttribute.java	                        (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/OverrideElementAttribute.java	2010-07-19 13:37:38 UTC (rev 106815)
@@ -0,0 +1,116 @@
+/*
+ * 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.jca.common.metadata.jbossra.jbossra20;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * A OverrideElementAttribute.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public enum OverrideElementAttribute
+{
+   /**always first
+   *
+   */
+   UNKNOWN(null),
+
+   /** connection-definition attribute value
+    *
+    */
+   CONNECTION_DEFINITION("connection-definition"),
+
+   /**
+    * resourceadapter attribute value
+    */
+   RESOURCE_ADAPTER("resourceadapter"),
+
+   /**
+    * activationspec attribute value
+    */
+   ACTIVATIONSPEC("activationspec"),
+
+   /**
+    * adminobject attribute value
+    */
+   ADMINOBJECT("adminobject"),
+
+   /**
+    * authentication-mechanism ATTRIBUTE VALUE
+    */
+   AUTENTICATION_MECHANISM("authentication-mechanism");
+
+   private final String name;
+
+   /**
+    *
+    * Create a new Tag.
+    *
+    * @param name a name
+    */
+   OverrideElementAttribute(final String name)
+   {
+      this.name = name;
+   }
+
+   /**
+    * Get the local name of this element.
+    *
+    * @return the local name
+    */
+   public String getLocalName()
+   {
+      return name;
+   }
+
+   private static final Map<String, OverrideElementAttribute> MAP;
+
+   static
+   {
+      final Map<String, OverrideElementAttribute> map = new HashMap<String, OverrideElementAttribute>();
+      for (OverrideElementAttribute element : values())
+      {
+         final String name = element.getLocalName();
+         if (name != null)
+            map.put(name, element);
+      }
+      MAP = map;
+   }
+
+   /**
+   *
+   * Static method to get enum instance given localName string
+   *
+   * @param localName a string used as localname (typically tag name as defined in xsd)
+   * @return the enum instance
+   */
+   public static OverrideElementAttribute forName(String localName)
+   {
+      final OverrideElementAttribute element = MAP.get(localName);
+      return element == null ? UNKNOWN : element;
+   }
+
+}

Added: projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/ra/RaParserTestCase.java
===================================================================
--- projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/ra/RaParserTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/ra/RaParserTestCase.java	2010-07-19 13:37:38 UTC (rev 106815)
@@ -0,0 +1,72 @@
+/*
+ * 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.jca.common.metadata.ra;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class RaParserTestCase
+{
+   /**
+    * shouldParseJbossRa10WithSingleProperty
+    * @throws Exception in case of error
+    */
+   @Test
+   public void shouldParseJbossRa10WithSingleProperty() throws Exception
+   {
+      //given
+      //      File xmlFile = new File(Thread.currentThread().getContextClassLoader()
+      //            .getResource("jboss-ra-1.0-single-attribute.xml").toURI());
+      //      JbossRaParser parser = new JbossRaParser();
+      //      //when
+      //      JbossRa jbossRa = parser.parse(xmlFile);
+      //      //then
+      //      assertThat(jbossRa, instanceOf(JbossRa10.class));
+      assertTrue(true);
+   }
+
+   /**
+    *
+    * shouldParseJbossRa10WithOutProperties
+    *
+    * @throws Exception in case of error
+    */
+   @Test
+   public void shouldParseJbossRa10WithOutProperties() throws Exception
+   {
+      assertTrue(true);
+   }
+
+   /**
+    *
+    * shouldParseJbossRa10WithMultipleProperties
+    *
+    * @throws Exception in case of error
+    */
+   @Test
+   public void shouldParseJbossRa10WithMultipleProperties() throws Exception
+   {
+      assertTrue(true);
+   }
+
+}

Added: projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-multiple-attributes.xml
===================================================================
--- projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-multiple-attributes.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-multiple-attributes.xml	2010-07-19 13:37:38 UTC (rev 106815)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ns1:jboss-ra xmlns:ns1="http://www.jboss.org/schema/ra"
+ xmlns:ns2="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.jboss.org/schema/ra file:/dati/project/RH/jboss-jca/common/src/main/resources/schema/jboss-ra_1_0.xsd">
+    <ns1:ra-config-property>
+        <ns1:ra-config-property-name>ra-config-property-name0</ns1:ra-config-property-name>
+        <ns1:ra-config-property-type>ra-config-property-type0</ns1:ra-config-property-type>
+        <ns1:ra-config-property-value>ra-config-property-value0</ns1:ra-config-property-value>
+    </ns1:ra-config-property>
+    <ns1:ra-config-property>
+        <ns1:ra-config-property-name>ra-config-property-name1</ns1:ra-config-property-name>
+        <ns1:ra-config-property-type>ra-config-property-type1</ns1:ra-config-property-type>
+        <ns1:ra-config-property-value>ra-config-property-value1</ns1:ra-config-property-value>
+    </ns1:ra-config-property>
+</ns1:jboss-ra>

Added: projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-no-attributes.xml
===================================================================
--- projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-no-attributes.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-no-attributes.xml	2010-07-19 13:37:38 UTC (rev 106815)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ns1:jboss-ra xmlns:ns1="http://www.jboss.org/schema/ra"
+ xmlns:ns2="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.jboss.org/schema/ra file:/dati/project/RH/jboss-jca/common/src/main/resources/schema/jboss-ra_1_0.xsd">
+    
+</ns1:jboss-ra>

Added: projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-single-attribute.xml
===================================================================
--- projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-single-attribute.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/resources/jboss-ra-1.0-single-attribute.xml	2010-07-19 13:37:38 UTC (rev 106815)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ns1:jboss-ra xmlns:ns1="http://www.jboss.org/schema/ra"
+ xmlns:ns2="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.jboss.org/schema/ra file:/dati/project/RH/jboss-jca/common/src/main/resources/schema/jboss-ra_1_0.xsd">
+    <ns1:ra-config-property>
+        <ns1:ra-config-property-name>ra-config-property-name0</ns1:ra-config-property-name>
+        <ns1:ra-config-property-type>ra-config-property-type0</ns1:ra-config-property-type>
+        <ns1:ra-config-property-value>ra-config-property-value0</ns1:ra-config-property-value>
+    </ns1:ra-config-property>
+    
+</ns1:jboss-ra>



More information about the jboss-cvs-commits mailing list