[jboss-cvs] JBossAS SVN: r59074 - in projects/microcontainer/trunk/spring-int/src: main/org/jboss/spring/deployment/xml resources/xml-test/org/jboss/test/spring/test tests/org/jboss/test/spring/support tests/org/jboss/test/spring/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 18 08:10:29 EST 2006


Author: alesj
Date: 2006-12-18 08:10:19 -0500 (Mon, 18 Dec 2006)
New Revision: 59074

Added:
   projects/microcontainer/trunk/spring-int/src/resources/xml-test/org/jboss/test/spring/test/InstantiateSpringTestCase.xml
   projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/InstantiateSpringTestCase.java
   projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringMIcrocontainerTest.java
   projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringMicrocontainerTestDelegate.java
Modified:
   projects/microcontainer/trunk/spring-int/src/main/org/jboss/spring/deployment/xml/SpringBeanHandler.java
   projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/support/SimpleBean.java
   projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/SpringTestSuite.java
Log:
Instantiation tests - not yet supporting collections.

Modified: projects/microcontainer/trunk/spring-int/src/main/org/jboss/spring/deployment/xml/SpringBeanHandler.java
===================================================================
--- projects/microcontainer/trunk/spring-int/src/main/org/jboss/spring/deployment/xml/SpringBeanHandler.java	2006-12-18 11:13:07 UTC (rev 59073)
+++ projects/microcontainer/trunk/spring-int/src/main/org/jboss/spring/deployment/xml/SpringBeanHandler.java	2006-12-18 13:10:19 UTC (rev 59074)
@@ -23,19 +23,18 @@
 
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
-
+import java.util.Arrays;
 import java.util.List;
-import java.util.Collections;
-import java.util.Comparator;
 
 import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
-import org.jboss.beans.metadata.plugins.AbstractLifecycleMetaData;
 import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
 import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractLifecycleMetaData;
 import org.jboss.beans.metadata.spi.ConstructorMetaData;
 import org.jboss.beans.metadata.spi.ParameterMetaData;
 import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler;
 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.spring.metadata.AbstractConstructorArg;
 import org.xml.sax.Attributes;
 
 /**
@@ -92,20 +91,41 @@
          List<ParameterMetaData> parameters = constructor.getParameters();
          if (parameters != null && parameters.size() > 1)
          {
-            Collections.sort(parameters, ParameterIndexComparator.INSTANCE);
+            orderParameters(parameters);
          }
       }
       return beanMetaData;
    }
 
-   private static class ParameterIndexComparator implements Comparator<ParameterMetaData>
+   protected void orderParameters(List<ParameterMetaData> parameters)
    {
-      static Comparator<ParameterMetaData> INSTANCE = new ParameterIndexComparator();
-
-      public int compare(ParameterMetaData pmd1, ParameterMetaData pmd2)
+      ParameterMetaData[] pmds = new ParameterMetaData[parameters.size()];
+      int i = 0;
+      for(ParameterMetaData pmd : parameters)
       {
-         return 0; // todo
+         int index = pmd.getIndex();
+         // lets first try to set those with explicit index
+         if (pmd instanceof AbstractConstructorArg && ((AbstractConstructorArg)pmd).isExplicitIndex())
+         {
+            if (pmds[index] != null)
+               throw new IllegalArgumentException("Argument with index: " + index + " already set!");
+            pmds[index] = pmd;
+         }
       }
+      int index = 0;
+      for(ParameterMetaData pmd : parameters)
+      {
+         // then just put the others in the free places
+         if ((pmd instanceof AbstractConstructorArg && ((AbstractConstructorArg)pmd).isExplicitIndex() == false))
+         {
+            while(pmds[index] != null) index++;
+            pmds[index] = pmd;
+         }
+         index++;
+      }
+      // todo clone md
+      parameters.clear();
+      parameters.addAll(Arrays.asList(pmds));
    }
 
 }

Added: projects/microcontainer/trunk/spring-int/src/resources/xml-test/org/jboss/test/spring/test/InstantiateSpringTestCase.xml
===================================================================
--- projects/microcontainer/trunk/spring-int/src/resources/xml-test/org/jboss/test/spring/test/InstantiateSpringTestCase.xml	2006-12-18 11:13:07 UTC (rev 59073)
+++ projects/microcontainer/trunk/spring-int/src/resources/xml-test/org/jboss/test/spring/test/InstantiateSpringTestCase.xml	2006-12-18 13:10:19 UTC (rev 59074)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="urn:jboss:spring-beans:2.0">
+
+   <bean id="testBean" class="org.jboss.test.spring.support.SimpleBean">
+      <constructor-arg index="2">
+         <value>SpringBean</value>
+      </constructor-arg>
+      <constructor-arg index="0">
+         <value>1</value>
+      </constructor-arg>
+      <constructor-arg index="1">
+         <value>3.1415</value>
+      </constructor-arg>
+      <!--
+         <property name="mylist">
+            <list value-type="java.lang.String">
+               <value>onel</value>
+               <value>twol</value>
+               <value>threel</value>
+            </list>
+         </property>
+         <property name="myset">
+            <set value-type="java.lang.String">
+               <value>ones</value>
+               <value>twos</value>
+               <value>ones</value>
+            </set>
+         </property>
+         <property name="map">
+            <entry>
+               <key>
+                  <value>key</value>
+               </key>
+               <value>myvalue</value>
+            </entry>
+         </property>
+      -->
+   </bean>
+
+</beans>
\ No newline at end of file

Modified: projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/support/SimpleBean.java
===================================================================
--- projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/support/SimpleBean.java	2006-12-18 11:13:07 UTC (rev 59073)
+++ projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/support/SimpleBean.java	2006-12-18 13:10:19 UTC (rev 59074)
@@ -79,4 +79,16 @@
       this.mymap = mymap;
    }
 
+   public String toString()
+   {
+      StringBuilder builder = new StringBuilder();
+      builder.append(x).append(",");
+      builder.append(y).append(",");
+      builder.append(s).append(",");
+      builder.append(mylist).append(",");
+      builder.append(myset).append(",");
+      builder.append(mymap);
+      return builder.toString();
+   }
+
 }

Added: projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/InstantiateSpringTestCase.java
===================================================================
--- projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/InstantiateSpringTestCase.java	2006-12-18 11:13:07 UTC (rev 59073)
+++ projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/InstantiateSpringTestCase.java	2006-12-18 13:10:19 UTC (rev 59074)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.spring.test;
+
+import junit.framework.Test;
+import org.jboss.test.spring.support.SimpleBean;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class InstantiateSpringTestCase extends TempSpringMicrocontainerTest
+{
+
+   public InstantiateSpringTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Setup the test
+    *
+    * @return the test
+    */
+   public static Test suite()
+   {
+      return suite(InstantiateSpringTestCase.class);
+   }
+
+   public void testDescribe() throws Exception
+   {
+      SimpleBean testBean = (SimpleBean) getBean("testBean", ControllerState.INSTANTIATED);
+      // todo - test instantiation
+      System.out.println("testBean = " + testBean);
+   }
+
+}

Modified: projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/SpringTestSuite.java
===================================================================
--- projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/SpringTestSuite.java	2006-12-18 11:13:07 UTC (rev 59073)
+++ projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/SpringTestSuite.java	2006-12-18 13:10:19 UTC (rev 59074)
@@ -41,6 +41,7 @@
       TestSuite suite = new TestSuite("Spring Tests");
 
       suite.addTest(DescribeSpringTestCase.suite());
+      suite.addTest(InstantiateSpringTestCase.suite());
 
       return suite;
    }

Added: projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringMIcrocontainerTest.java
===================================================================
--- projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringMIcrocontainerTest.java	2006-12-18 11:13:07 UTC (rev 59073)
+++ projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringMIcrocontainerTest.java	2006-12-18 13:10:19 UTC (rev 59074)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.spring.test;
+
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TempSpringMicrocontainerTest extends MicrocontainerTest
+{
+
+   public TempSpringMicrocontainerTest(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Setup the test delegate
+    *
+    * @param clazz the class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+   {
+      return new TempSpringMicrocontainerTestDelegate(clazz);
+   }
+
+}

Added: projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringMicrocontainerTestDelegate.java
===================================================================
--- projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringMicrocontainerTestDelegate.java	2006-12-18 11:13:07 UTC (rev 59073)
+++ projects/microcontainer/trunk/spring-int/src/tests/org/jboss/test/spring/test/TempSpringMicrocontainerTestDelegate.java	2006-12-18 13:10:19 UTC (rev 59074)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.spring.test;
+
+import org.jboss.spring.deployment.xml.SpringSchemaInitializer;
+import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TempSpringMicrocontainerTestDelegate extends MicrocontainerTestDelegate
+{
+
+   public TempSpringMicrocontainerTestDelegate(Class clazz) throws Exception
+   {
+      super(clazz);
+   }
+
+   public void setUp() throws Exception
+   {
+      SchemaBindingResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+      DefaultSchemaResolver defaultSchemaResolver = (DefaultSchemaResolver) resolver;
+      defaultSchemaResolver.addSchemaInitializer("urn:jboss:spring-beans:2.0", new SpringSchemaInitializer());
+      defaultSchemaResolver.addSchemaLocation("urn:jboss:spring-beans:2.0", "mc-spring-beans_2_0.xsd");
+      super.setUp();
+   }
+
+}




More information about the jboss-cvs-commits mailing list