[jboss-cvs] JBossAS SVN: r64464 - in projects/microcontainer/trunk/kernel/src: resources/tests/xml-test/org/jboss/test/kernel/config/test and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 6 07:39:45 EDT 2007
Author: alesj
Date: 2007-08-06 07:39:45 -0400 (Mon, 06 Aug 2007)
New Revision: 64464
Added:
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromBean.xml
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromFactory.xml
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromStaticFactory.xml
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryWithNonExistingClass.xml
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateTestCase.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateXMLTestCase.java
Modified:
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/factory/GenericBeanFactory.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java
Log:
BeanFactory tests with no bean set.
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/factory/GenericBeanFactory.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/factory/GenericBeanFactory.java 2007-08-06 11:39:36 UTC (rev 64463)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/factory/GenericBeanFactory.java 2007-08-06 11:39:45 UTC (rev 64464)
@@ -86,9 +86,15 @@
public Object createBean() throws Throwable
{
ClassLoader cl = Configurator.getClassLoader(classLoader);
- BeanInfo info = configurator.getBeanInfo(bean, cl);
+ BeanInfo info = null;
+ if (bean != null)
+ info = configurator.getBeanInfo(bean, cl);
+
Joinpoint joinpoint = configurator.getConstructorJoinPoint(info, constructor, null);
Object result = joinpoint.dispatch();
+ if (info == null && result != null)
+ info = configurator.getBeanInfo(result.getClass());
+
if (properties != null && properties.size() > 0)
{
for (Object o : properties.entrySet())
Added: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromBean.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromBean.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromBean.xml 2007-08-06 11:39:45 UTC (rev 64464)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <beanfactory name="Factory" class="org.jboss.test.kernel.config.support.SimpleBean">
+ <property name="anint">123</property>
+ </beanfactory>
+</deployment>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromFactory.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromFactory.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromFactory.xml 2007-08-06 11:39:45 UTC (rev 64464)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <beanfactory name="Factory">
+ <constructor factoryMethod="createSimpleBean">
+ <factory>
+ <javabean xmlns="urn:jboss:javabean:1.0" class="org.jboss.test.kernel.config.support.SimpleBeanFactory"/>
+ </factory>
+ </constructor>
+ <property name="anint">123</property>
+ </beanfactory>
+</deployment>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromStaticFactory.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromStaticFactory.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryFromStaticFactory.xml 2007-08-06 11:39:45 UTC (rev 64464)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <beanfactory name="Factory">
+ <constructor factoryMethod="staticCreateSimpleBean" factoryClass="org.jboss.test.kernel.config.support.SimpleBeanFactory"/>
+ <property name="anint">123</property>
+ </beanfactory>
+</deployment>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryWithNonExistingClass.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryWithNonExistingClass.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testBeanFactoryWithNonExistingClass.xml 2007-08-06 11:39:45 UTC (rev 64464)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <beanfactory name="Factory" class="org.jboss.test.NoSuchClass">
+ <property name="anint">123</property>
+ </beanfactory>
+</deployment>
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java 2007-08-06 11:39:36 UTC (rev 64463)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java 2007-08-06 11:39:45 UTC (rev 64464)
@@ -45,6 +45,8 @@
suite.addTest(InstantiateTestCase.suite());
suite.addTest(InstantiateXMLTestCase.suite());
suite.addTest(InstantiateAnnotationTestCase.suite());
+ suite.addTest(GenericFactoryInstantiateTestCase.suite());
+ suite.addTest(GenericFactoryInstantiateXMLTestCase.suite());
suite.addTest(FactoryTestCase.suite());
suite.addTest(FactoryXMLTestCase.suite());
suite.addTest(FactoryAnnotationTestCase.suite());
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateTestCase.java 2007-08-06 11:39:45 UTC (rev 64464)
@@ -0,0 +1,133 @@
+/*
+* 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.kernel.config.test;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData;
+import org.jboss.beans.metadata.spi.factory.BeanFactory;
+import org.jboss.test.kernel.config.support.SimpleBean;
+import org.jboss.test.kernel.config.support.SimpleBeanFactory;
+
+/**
+ * GenericFactory Instantiation Test Case.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GenericFactoryInstantiateTestCase extends AbstractKernelConfigTest
+{
+ public static Test suite()
+ {
+ return suite(GenericFactoryInstantiateTestCase.class);
+ }
+
+ public GenericFactoryInstantiateTestCase(String name)
+ {
+ super(name);
+ }
+
+ public GenericFactoryInstantiateTestCase(String name, boolean xmltest)
+ {
+ super(name, xmltest);
+ }
+
+ protected void assertFactory(BeanFactory factory)
+ throws Throwable
+ {
+ assertNotNull(factory);
+ SimpleBean bean1 = (SimpleBean)factory.createBean();
+ assertNotNull(bean1);
+ assertEquals(123, bean1.getAnint());
+ SimpleBean bean2 = (SimpleBean)factory.createBean();
+ assertNotNull(bean2);
+ assertEquals(123, bean2.getAnint());
+ }
+
+ public void testBeanFactoryFromBean() throws Throwable
+ {
+ BeanFactory factory = configureFromBean();
+ assertFactory(factory);
+ }
+
+ protected BeanFactory configureFromBean() throws Throwable
+ {
+ GenericBeanFactoryMetaData factory = new GenericBeanFactoryMetaData("Factory", SimpleBean.class.getName());
+ factory.addBeanProperty(new AbstractPropertyMetaData("anint", 123));
+ return (BeanFactory)instantiate(factory);
+ }
+
+ public void testBeanFactoryFromFactory() throws Throwable
+ {
+ BeanFactory factory = configureFromFactory();
+ assertFactory(factory);
+ }
+
+ protected BeanFactory configureFromFactory() throws Throwable
+ {
+ GenericBeanFactoryMetaData factory = new GenericBeanFactoryMetaData("Factory");
+ AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
+ factory.setBeanConstructor(constructor);
+ constructor.setFactory(new AbstractValueMetaData(new SimpleBeanFactory()));
+ constructor.setFactoryMethod("createSimpleBean");
+ factory.addBeanProperty(new AbstractPropertyMetaData("anint", 123));
+ return (BeanFactory)instantiate(factory);
+ }
+
+ public void testBeanFactoryFromStaticFactory() throws Throwable
+ {
+ BeanFactory factory = configureFromStaticFactory();
+ assertFactory(factory);
+ }
+
+ protected BeanFactory configureFromStaticFactory() throws Throwable
+ {
+ GenericBeanFactoryMetaData factory = new GenericBeanFactoryMetaData("Factory");
+ AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
+ factory.setBeanConstructor(constructor);
+ constructor.setFactoryClass(SimpleBeanFactory.class.getName());
+ constructor.setFactoryMethod("staticCreateSimpleBean");
+ factory.addBeanProperty(new AbstractPropertyMetaData("anint", 123));
+ return (BeanFactory)instantiate(factory);
+ }
+
+ public void testBeanFactoryWithNonExistingClass() throws Throwable
+ {
+ BeanFactory factory = configureFromIllegalClass();
+ assertNotNull(factory);
+ try
+ {
+ factory.createBean();
+ }
+ catch(Exception ex)
+ {
+ assertInstanceOf(ex, ClassNotFoundException.class);
+ }
+ }
+
+ protected BeanFactory configureFromIllegalClass() throws Throwable
+ {
+ GenericBeanFactoryMetaData factory = new GenericBeanFactoryMetaData("Factory", "org.jboss.test.NoSuchClass");
+ return (BeanFactory)instantiate(factory);
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateXMLTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateXMLTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateXMLTestCase.java 2007-08-06 11:39:45 UTC (rev 64464)
@@ -0,0 +1,71 @@
+/*
+* 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.kernel.config.test;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.spi.factory.BeanFactory;
+import org.jboss.test.kernel.config.support.XMLUtil;
+
+/**
+ * GenericFactory Instantiation Test Case.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GenericFactoryInstantiateXMLTestCase extends GenericFactoryInstantiateTestCase
+{
+ public static Test suite()
+ {
+ return suite(GenericFactoryInstantiateXMLTestCase.class);
+ }
+
+ public GenericFactoryInstantiateXMLTestCase(String name)
+ {
+ super(name, true);
+ }
+
+ protected BeanFactory configureFromBean() throws Throwable
+ {
+ return configurefactory();
+ }
+
+ protected BeanFactory configureFromFactory() throws Throwable
+ {
+ return configurefactory();
+ }
+
+ protected BeanFactory configureFromStaticFactory() throws Throwable
+ {
+ return configurefactory();
+ }
+
+ protected BeanFactory configureFromIllegalClass() throws Throwable
+ {
+ return configurefactory();
+ }
+
+ protected BeanFactory configurefactory()
+ throws Throwable
+ {
+ XMLUtil util = bootstrapXML(true);
+ return (BeanFactory) util.getBean("Factory");
+ }
+}
More information about the jboss-cvs-commits
mailing list