[jboss-cvs] JBossAS SVN: r88041 - in projects/spring-int/trunk/facade: src and 12 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 29 23:37:48 EDT 2009


Author: marius.bogoevici
Date: 2009-04-29 23:37:47 -0400 (Wed, 29 Apr 2009)
New Revision: 88041

Added:
   projects/spring-int/trunk/facade/src/test/
   projects/spring-int/trunk/facade/src/test/java/
   projects/spring-int/trunk/facade/src/test/java/org/
   projects/spring-int/trunk/facade/src/test/java/org/jboss/
   projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/
   projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/
   projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/Adder.java
   projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/ComplexService.java
   projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/KernelControllerListableBeanFactoryTestCase.java
   projects/spring-int/trunk/facade/src/test/resources/
   projects/spring-int/trunk/facade/src/test/resources/org/
   projects/spring-int/trunk/facade/src/test/resources/org/jboss/
   projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/
   projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/
   projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/microcontainer-beans-2.xml
   projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/microcontainer-beans.xml
   projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/spring-beans.xml
Modified:
   projects/spring-int/trunk/facade/pom.xml
   projects/spring-int/trunk/facade/src/main/java/org/jboss/spring/facade/ControllerBeanFactory.java
Log:
JBSPRING-2: Unit tests, fixing a NPE issue when using the MC as a parent BeanFactory

Modified: projects/spring-int/trunk/facade/pom.xml
===================================================================
--- projects/spring-int/trunk/facade/pom.xml	2009-04-30 02:14:17 UTC (rev 88040)
+++ projects/spring-int/trunk/facade/pom.xml	2009-04-30 03:37:47 UTC (rev 88041)
@@ -46,6 +46,10 @@
       <groupId>org.springframework</groupId>
       <artifactId>spring-core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
   </dependencies>
-  
+
 </project>
\ No newline at end of file

Modified: projects/spring-int/trunk/facade/src/main/java/org/jboss/spring/facade/ControllerBeanFactory.java
===================================================================
--- projects/spring-int/trunk/facade/src/main/java/org/jboss/spring/facade/ControllerBeanFactory.java	2009-04-30 02:14:17 UTC (rev 88040)
+++ projects/spring-int/trunk/facade/src/main/java/org/jboss/spring/facade/ControllerBeanFactory.java	2009-04-30 03:37:47 UTC (rev 88041)
@@ -46,6 +46,7 @@
  * BeanFactory facade over MC's Controller.
  *
  * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
  */
 public class ControllerBeanFactory implements BeanFactory
 {
@@ -94,7 +95,10 @@
    @SuppressWarnings("unchecked")
    public Object getBean(String name, Class clazz) throws BeansException
    {
-      return getExactBean(name, clazz);
+      if (clazz == null)
+        return getBean(name);
+      else
+        return getBeanWithType(name, clazz);
    }
 
    /**
@@ -106,10 +110,10 @@
     * @return exact bean
     * @throws BeansException for any error
     */
-   protected <T> T getExactBean(String name, Class<T> clazz) throws BeansException
+   protected <T> T getBeanWithType(String name, Class<T> clazz) throws BeansException
    {
       Object result = getBean(name);
-      if (clazz.isInstance(result) == false)
+      if (!clazz.isInstance(result))
          throw new BeanNotOfRequiredTypeException(name, clazz, result.getClass());
 
       return clazz.cast(result);
@@ -118,7 +122,7 @@
    @SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter"})
    public Object getBean(String name, Object[] parameters) throws BeansException
    {
-      AbstractBeanFactory result = getExactBean(name, AbstractBeanFactory.class);
+      AbstractBeanFactory result = getBeanWithType(name, AbstractBeanFactory.class);
       ConstructorMetaData cmd = result.getConstructor();
 
       BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("Temp");
@@ -147,7 +151,7 @@
 
    public boolean isSingleton(String name) throws NoSuchBeanDefinitionException
    {
-      return isPrototype(name) == false;
+      return !isPrototype(name);
    }
 
    public boolean isPrototype(String name) throws NoSuchBeanDefinitionException

Added: projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/Adder.java
===================================================================
--- projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/Adder.java	                        (rev 0)
+++ projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/Adder.java	2009-04-30 03:37:47 UTC (rev 88041)
@@ -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.spring.facade;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public class Adder
+{
+    public int add(int x, int y)
+    {
+        return x + y;    
+    }
+}

Added: projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/ComplexService.java
===================================================================
--- projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/ComplexService.java	                        (rev 0)
+++ projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/ComplexService.java	2009-04-30 03:37:47 UTC (rev 88041)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.spring.facade;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public class ComplexService
+{
+    private Adder adder;
+
+    public void setAdder(Adder adder)
+    {
+        this.adder = adder;
+    }
+
+    public String processNumbers (int i, int j)
+    {
+        return "Result is: " + adder.add(i, j);  
+    }
+}

Added: projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/KernelControllerListableBeanFactoryTestCase.java
===================================================================
--- projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/KernelControllerListableBeanFactoryTestCase.java	                        (rev 0)
+++ projects/spring-int/trunk/facade/src/test/java/org/jboss/spring/facade/KernelControllerListableBeanFactoryTestCase.java	2009-04-30 03:37:47 UTC (rev 88041)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.spring.facade;
+
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.xml.XmlBeanFactory;
+import org.springframework.core.io.UrlResource;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public class KernelControllerListableBeanFactoryTestCase
+{               
+
+    @Test
+    public void testKernelControllerAssignableAsParentBeanFactory() throws Throwable
+    {
+        BasicBootstrap bootstrap = new BasicBootstrap();
+        bootstrap.run();
+        BasicXMLDeployer deployer = new BasicXMLDeployer(bootstrap.getKernel());
+        BeanFactory parentBeanFactory = new KernelControllerListableBeanFactory(bootstrap.getKernel().getController());
+        deployer.deploy(KernelControllerListableBeanFactory.class.getResource("microcontainer-beans.xml"));
+        BeanFactory beanFactory = new XmlBeanFactory(new UrlResource(KernelControllerListableBeanFactory.class.getResource("spring-beans.xml")), parentBeanFactory);
+        ComplexService service = (ComplexService) beanFactory.getBean("service");
+        Assert.assertEquals("Result is: 2", service.processNumbers(1, 1));
+        deployer.shutdown();
+    }
+
+    @Test(expected = BeanCreationException.class)
+    public void testConfigurationFailsIfParentBeanMissing() throws Throwable
+    {
+        BasicBootstrap bootstrap = new BasicBootstrap();
+        bootstrap.run();
+        BasicXMLDeployer deployer = new BasicXMLDeployer(bootstrap.getKernel());
+        BeanFactory parentBeanFactory = new KernelControllerListableBeanFactory(bootstrap.getKernel().getController());
+        deployer.deploy(KernelControllerListableBeanFactory.class.getResource("microcontainer-beans-2.xml"));
+        BeanFactory beanFactory = new XmlBeanFactory(new UrlResource(KernelControllerListableBeanFactory.class.getResource("spring-beans.xml")), parentBeanFactory);
+        ComplexService service = (ComplexService) beanFactory.getBean("service");
+        Assert.assertEquals("Result is: 2", service.processNumbers(1, 1));
+        deployer.shutdown();
+    }
+    
+}

Added: projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/microcontainer-beans-2.xml
===================================================================
--- projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/microcontainer-beans-2.xml	                        (rev 0)
+++ projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/microcontainer-beans-2.xml	2009-04-30 03:37:47 UTC (rev 88041)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+        
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+            xmlns="urn:jboss:bean-deployer:2.0">
+
+
+    <bean name="adder2" class="org.jboss.spring.facade.Adder"/>
+
+</deployment>
+

Added: projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/microcontainer-beans.xml
===================================================================
--- projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/microcontainer-beans.xml	                        (rev 0)
+++ projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/microcontainer-beans.xml	2009-04-30 03:37:47 UTC (rev 88041)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+            xmlns="urn:jboss:bean-deployer:2.0">
+
+
+    <bean name="adder" class="org.jboss.spring.facade.Adder"/>
+
+</deployment>
+

Added: projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/spring-beans.xml
===================================================================
--- projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/spring-beans.xml	                        (rev 0)
+++ projects/spring-int/trunk/facade/src/test/resources/org/jboss/spring/facade/spring-beans.xml	2009-04-30 03:37:47 UTC (rev 88041)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+        
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+     <bean id="service" class="org.jboss.spring.facade.ComplexService">
+         <property name="adder" ref="adder"/>
+     </bean>
+</beans>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list