[jboss-cvs] JBossAS SVN: r71970 - in projects/component-injection/trunk: src and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 10 14:39:53 EDT 2008


Author: scott.stark at jboss.org
Date: 2008-04-10 14:39:53 -0400 (Thu, 10 Apr 2008)
New Revision: 71970

Added:
   projects/component-injection/trunk/src/tests/
   projects/component-injection/trunk/src/tests/org/
   projects/component-injection/trunk/src/tests/org/jboss/
   projects/component-injection/trunk/src/tests/org/jboss/test/
   projects/component-injection/trunk/src/tests/org/jboss/test/component/
   projects/component-injection/trunk/src/tests/org/jboss/test/component/support/
   projects/component-injection/trunk/src/tests/org/jboss/test/component/test/
   projects/component-injection/trunk/src/tests/org/jboss/test/component/test/BeanContainerUsageMDTestCase.java
   projects/component-injection/trunk/src/tests/org/jboss/test/component/test/BeanContainerUsageTestCase.java
   projects/component-injection/trunk/src/tests/org/jboss/test/kernel/
   projects/component-injection/trunk/src/tests/org/jboss/test/kernel/AbstractKernelTest.java
Modified:
   projects/component-injection/trunk/.classpath
   projects/component-injection/trunk/pom.xml
Log:
Copy and update the component injection tests from the kernel

Modified: projects/component-injection/trunk/.classpath
===================================================================
--- projects/component-injection/trunk/.classpath	2008-04-10 17:36:03 UTC (rev 71969)
+++ projects/component-injection/trunk/.classpath	2008-04-10 18:39:53 UTC (rev 71970)
@@ -1,23 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-  <classpathentry kind="src" path="src/main"/>
-  <classpathentry kind="src" path="src/resources/main" excluding="**/*.java"/>
-  <classpathentry kind="output" path="target/classes"/>
-  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.0.2/activation-1.0.2.jar"/>
-  <classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.1/jaxb-api-2.1.jar" sourcepath="M2_REPO/javax/xml/bind/jaxb-api/2.1/jaxb-api-2.1-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.4.GA/jboss-common-core-2.2.4.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-common-core/2.2.4.GA/jboss-common-core-2.2.4.GA-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-dependency/2.0.0.Beta13/jboss-dependency-2.0.0.Beta13.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-kernel/2.0.0.Beta13/jboss-kernel-2.0.0.Beta13.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-mdr/2.0.0.Beta14/jboss-mdr-2.0.0.Beta14.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-reflect/2.0.0.Beta12/jboss-reflect-2.0.0.Beta12.jar" sourcepath="M2_REPO/org/jboss/jboss-reflect/2.0.0.Beta12/jboss-reflect-2.0.0.Beta12-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-test/1.0.5.GA/jboss-test-1.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-test/1.0.5.GA/jboss-test-1.0.5.GA-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/jbossxb/2.0.0.CR8/jbossxb-2.0.0.CR8.jar" sourcepath="M2_REPO/org/jboss/jbossxb/2.0.0.CR8/jbossxb-2.0.0.CR8-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar" sourcepath="M2_REPO/junit/junit/4.4/junit-4.4-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2.jar" sourcepath="M2_REPO/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar"/>
-</classpath>
\ No newline at end of file
+	<classpathentry kind="src" path="src/main"/>
+	<classpathentry kind="src" path="src/tests"/>
+	<classpathentry excluding="**/*.java" kind="src" path="src/resources/main"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.0.2/activation-1.0.2.jar"/>
+	<classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.1/jaxb-api-2.1.jar" sourcepath="M2_REPO/javax/xml/bind/jaxb-api/2.1/jaxb-api-2.1-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.4.GA/jboss-common-core-2.2.4.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-common-core/2.2.4.GA/jboss-common-core-2.2.4.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-dependency/2.0.0.Beta13/jboss-dependency-2.0.0.Beta13.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-kernel/2.0.0.Beta13/jboss-kernel-2.0.0.Beta13.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-mdr/2.0.0.Beta14/jboss-mdr-2.0.0.Beta14.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-reflect/2.0.0.Beta12/jboss-reflect-2.0.0.Beta12.jar" sourcepath="M2_REPO/org/jboss/jboss-reflect/2.0.0.Beta12/jboss-reflect-2.0.0.Beta12-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-test/1.0.5.GA/jboss-test-1.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-test/1.0.5.GA/jboss-test-1.0.5.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jbossxb/2.0.0.CR8/jbossxb-2.0.0.CR8.jar" sourcepath="M2_REPO/org/jboss/jbossxb/2.0.0.CR8/jbossxb-2.0.0.CR8-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar" sourcepath="M2_REPO/junit/junit/4.4/junit-4.4-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2.jar" sourcepath="M2_REPO/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Modified: projects/component-injection/trunk/pom.xml
===================================================================
--- projects/component-injection/trunk/pom.xml	2008-04-10 17:36:03 UTC (rev 71969)
+++ projects/component-injection/trunk/pom.xml	2008-04-10 18:39:53 UTC (rev 71970)
@@ -6,11 +6,17 @@
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>jboss-component-injection</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
   <packaging>jar</packaging>
   <name>JBoss Microcontainer Kernel</name>
   <url>http://www.jboss.com/products/jbossmc</url>
   <description>JBoss Component Injection</description>
-
+  <scm>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/component-injection/trunk/</connection>
+    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/component-injection/trunk/</developerConnection>
+    <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/component-injection/trunk/</url>
+  </scm>
+  
   <!-- Properties -->
   <properties>
     <version.junit>4.4</version.junit>

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/test/BeanContainerUsageMDTestCase.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/test/BeanContainerUsageMDTestCase.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/test/BeanContainerUsageMDTestCase.java	2008-04-10 18:39:53 UTC (rev 71970)
@@ -0,0 +1,354 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * 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.component.test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Test;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.factory.GenericBeanFactoryMetaData;
+import org.jboss.component.plugin.GenericComponentFactory;
+import org.jboss.component.spi.ComponentFactory;
+import org.jboss.component.spi.ComponentInstance;
+import org.jboss.component.spi.ComponentVisitor;
+import org.jboss.kernel.plugins.deployment.AbstractKernelDeployment;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.test.component.support.container.BaseContext;
+import org.jboss.test.component.support.container.Bean1Type;
+import org.jboss.test.component.support.container.BeanContainer;
+import org.jboss.test.component.support.container.BeanContextFactory;
+import org.jboss.test.component.support.container.InstanceInterceptor;
+
+
+/**
+ * Programatic version of the BeanContainerUsageTestCase tests
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 71929 $
+ */
+public class BeanContainerUsageMDTestCase extends BeanContainerUsageTestCase
+{
+   public static Test suite()
+   {
+      return suite(BeanContainerUsageMDTestCase.class);
+   }
+
+   public BeanContainerUsageMDTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Test of the ComponentFactory usecase
+    * 
+    * @see {@link GenericComponentFactory}
+    * @see {@link ComponentFactory}
+    * @throws Throwable
+    */
+   @SuppressWarnings("unchecked")
+   public void testComponentBeanFactory()
+      throws Throwable
+   {
+      bootstrap();
+      // Lookup the ComponentFactory implementation
+      ComponentFactory<BaseContext<Bean1Type, BeanContainer<Bean1Type>>> factory =
+         (ComponentFactory<BaseContext<Bean1Type, BeanContainer<Bean1Type>>>) getBean("ComponentBeanFactory");
+      getLog().info("ComponentBeanFactory bean: "+factory);
+      // Create a component instance
+      ComponentInstance<BaseContext<Bean1Type, BeanContainer<Bean1Type>>> contextInstance =
+         factory.createComponents("ComponentBeanFactory");
+      // Validate the component bean names
+      List<String> beanNames = contextInstance.getComponentNames();
+      getLog().info("createComponents(ComponentBeanFactory): "+beanNames);
+
+      HashSet<String> expectedBeanNames = new HashSet<String>();
+      expectedBeanNames.add("ComponentBeanFactory at ContextFactory#1");
+      expectedBeanNames.add("ComponentBeanFactory at BeanInstance#1");
+      expectedBeanNames.add("ComponentBeanFactory at Interceptor:0#1");
+      assertEquals(expectedBeanNames, new HashSet<String>(beanNames));
+      long compID = contextInstance.getComponentID();
+      assertEquals(1, compID);
+      BaseContext<Bean1Type, BeanContainer<Bean1Type>> context = contextInstance.getContext();
+      assertNotNull(context);
+      String contextName = contextInstance.getContextName();
+      assertEquals("ComponentBeanFactory at ContextFactory#1", contextName);
+      Object contextBean = getBean("ComponentBeanFactory at ContextFactory#1");
+      assertTrue(contextBean == context);
+      Bean1Type bean1 = (Bean1Type) getBean("ComponentBeanFactory at BeanInstance#1");
+      assertTrue(bean1 == context.getInstance());
+   
+      Object interceptor = getBean("ComponentBeanFactory at Interceptor:0#1");
+      assertNotNull(interceptor);
+      List expectedInterceptors = new ArrayList();
+      expectedInterceptors.add(interceptor);
+      List interceptors = context.getInterceptors();
+      assertEquals(interceptors, expectedInterceptors);
+
+      factory.destroyComponents(contextInstance);
+      expectedBeanNames.clear();
+      expectedBeanNames.add("ComponentBeanFactory");
+      // Only the ComponentBeanFactory should exist
+      assertBeansExist(expectedBeanNames);
+      contextInstance = null;
+
+      // Create a second component instance
+      ComponentInstance<BaseContext<Bean1Type, BeanContainer<Bean1Type>>> contextInstance2 =
+         factory.createComponents("ComponentBeanFactory");
+      // Validate the component bean names
+      List<String> beanNames2 = contextInstance2.getComponentNames();
+      getLog().info("createComponents(ComponentBeanFactory): "+beanNames2);
+      expectedBeanNames = new HashSet<String>();
+      expectedBeanNames.add("ComponentBeanFactory at ContextFactory#2");
+      expectedBeanNames.add("ComponentBeanFactory at BeanInstance#2");
+      expectedBeanNames.add("ComponentBeanFactory at Interceptor:0#2");
+      assertEquals(expectedBeanNames, new HashSet<String>(beanNames2));
+      compID = contextInstance2.getComponentID();
+      assertEquals(2, compID);
+      BaseContext<Bean1Type, BeanContainer<Bean1Type>> context2 = contextInstance2.getContext();
+      assertNotNull(context2);
+      String contextName2 = contextInstance2.getContextName();
+      assertEquals("ComponentBeanFactory at ContextFactory#2", contextName2);
+      Object contextBean2 = getBean("ComponentBeanFactory at ContextFactory#2");
+      assertTrue(contextBean2 == context2);
+      Bean1Type bean2 = (Bean1Type) getBean("ComponentBeanFactory at BeanInstance#2");
+      assertTrue(bean2 == context2.getInstance());
+      assertTrue(bean2 != bean1);
+ 
+      Object interceptor2 = getBean("ComponentBeanFactory at Interceptor:0#2");
+      assertNotNull(interceptor2);
+      List expectedInterceptors2 = new ArrayList();
+      expectedInterceptors2.add(interceptor2);
+      List interceptors2 = context2.getInterceptors();
+      assertEquals(interceptors2, expectedInterceptors2);
+
+      factory.destroyComponents(contextInstance2);
+      expectedBeanNames.clear();
+      expectedBeanNames.add("ComponentBeanFactory");
+      // Only the ComponentBeanFactory should exist
+      assertBeansExist(expectedBeanNames);
+
+      shutdown();
+   }
+
+   /*
+   <beanfactory name="Bean1TypeFactory" class="org.jboss.test.kernel.deployment.support.container.Bean1Type"/>
+   <bean name="Bean1TypePool" class="org.jboss.test.kernel.deployment.support.container.BeanPool">
+      <property name="factory"><inject bean="Bean1TypeFactory"/></property>
+   </bean>
+   <bean name="BeanContainer1Type" class="org.jboss.test.kernel.deployment.support.container.BeanContainer">
+      <property name="pool"><inject bean="Bean1TypePool"/></property>
+   </bean>
+   <beanfactory name="Bean2TypeFactory" class="org.jboss.test.kernel.deployment.support.container.Bean2Type">
+      <property name="bean1"><value-factory bean="Bean1TypePool" method="createBean" /></property>
+   </beanfactory>
+   <bean name="Bean2TypePool" class="org.jboss.test.kernel.deployment.support.container.BeanPool">
+      <property name="factory"><inject bean="Bean2TypeFactory"/></property>
+   </bean>
+   <bean name="BeanContainer2Type" class="org.jboss.test.kernel.deployment.support.container.BeanContainer">
+      <property name="pool"><inject bean="Bean2TypePool"/></property>
+   </bean>
+    */
+   protected KernelDeployment getDeploymentForDependencyInjectionOfBean()
+   {
+      AbstractKernelDeployment deployment = new AbstractKernelDeployment();
+      deployment.setName("DependencyInjectionOfBean");
+      ArrayList<BeanMetaDataFactory> beanFactories = new ArrayList<BeanMetaDataFactory>();
+      // Bean1TypeFactory
+      GenericBeanFactoryMetaData Bean1TypeFactory = new GenericBeanFactoryMetaData("Bean1TypeFactory",
+            "org.jboss.test.kernel.deployment.support.container.Bean1Type");
+      beanFactories.add(Bean1TypeFactory);
+      // Bean1TypePool
+      AbstractBeanMetaData Bean1TypePool = new AbstractBeanMetaData("Bean1TypePool",
+            "org.jboss.test.kernel.deployment.support.container.BeanPool");
+      Set<PropertyMetaData> Bean1TypePool_propertys = new HashSet<PropertyMetaData>();
+      Bean1TypePool_propertys.add(new AbstractPropertyMetaData("factory",
+            new AbstractDependencyValueMetaData("Bean1TypeFactory")));
+      Bean1TypePool.setProperties(Bean1TypePool_propertys);
+      beanFactories.add(Bean1TypePool);
+      // BeanContainer1Type
+      AbstractBeanMetaData BeanContainer1Type = new AbstractBeanMetaData("BeanContainer1Type",
+         "org.jboss.test.kernel.deployment.support.container.BeanContainer");
+      Set<PropertyMetaData> BeanContainer1Type_propertys = new HashSet<PropertyMetaData>();
+      BeanContainer1Type_propertys.add(new AbstractPropertyMetaData("pool",
+            new AbstractDependencyValueMetaData("Bean1TypePool")));
+      BeanContainer1Type.setProperties(BeanContainer1Type_propertys);
+      beanFactories.add(BeanContainer1Type);
+
+      // Bean2TypeFactory
+      GenericBeanFactoryMetaData Bean2TypeFactory = new GenericBeanFactoryMetaData("Bean2TypeFactory",
+      "org.jboss.test.kernel.deployment.support.container.Bean2Type");
+      Set<PropertyMetaData> Bean2TypeFactory_propertys = new HashSet<PropertyMetaData>();
+      AbstractValueFactoryMetaData bean1CreateMethod = new AbstractValueFactoryMetaData("Bean1TypePool", "createBean"); 
+      Bean2TypeFactory_propertys.add(new AbstractPropertyMetaData("bean1", bean1CreateMethod));
+      Bean2TypeFactory.setProperties(Bean2TypeFactory_propertys);
+      beanFactories.add(Bean2TypeFactory);
+      // Bean2TypePool
+      AbstractBeanMetaData Bean2TypePool = new AbstractBeanMetaData("Bean2TypePool",
+            "org.jboss.test.kernel.deployment.support.container.BeanPool");
+      Set<PropertyMetaData> Bean2TypePool_propertys = new HashSet<PropertyMetaData>();
+      Bean2TypePool_propertys.add(new AbstractPropertyMetaData("factory",
+            new AbstractDependencyValueMetaData("Bean2TypeFactory")));
+      Bean2TypePool.setProperties(Bean2TypePool_propertys);
+      beanFactories.add(Bean2TypePool);
+      // BeanContainer2Type
+      AbstractBeanMetaData BeanContainer2Type = new AbstractBeanMetaData("BeanContainer2Type",
+         "org.jboss.test.kernel.deployment.support.container.BeanContainer");
+      Set<PropertyMetaData> BeanContainer2Type_propertys = new HashSet<PropertyMetaData>();
+      BeanContainer2Type_propertys.add(new AbstractPropertyMetaData("pool",
+            new AbstractDependencyValueMetaData("Bean2TypePool")));
+      BeanContainer2Type.setProperties(BeanContainer2Type_propertys);
+      beanFactories.add(BeanContainer2Type);
+
+      deployment.setBeanFactories(beanFactories);
+
+      return deployment;
+   }
+   /*
+   <beanfactory name="Bean1TypeFactory" class="org.jboss.test.kernel.deployment.support.container.Bean1Type"/>
+   <bean name="Bean1TypePool" class="org.jboss.test.kernel.deployment.support.container.BeanPool">
+      <constructor>
+         <parameter>3</parameter>
+      </constructor>
+      <property name="factory"><inject bean="Bean1TypeFactory"/></property>
+   </bean>
+   <bean name="BeanContainer1Type" class="org.jboss.test.kernel.deployment.support.container.BeanContainer">
+      <property name="pool"><inject bean="Bean1TypePool"/></property>
+   </bean>
+   <beanfactory name="Bean2TypeFactory" class="org.jboss.test.kernel.deployment.support.container.Bean2Type">
+      <property name="bean1"><value-factory bean="Bean1TypePool" method="createBean" /></property>
+   </beanfactory>
+   <bean name="Bean2TypePool" class="org.jboss.test.kernel.deployment.support.container.BeanPool">
+      <constructor>
+         <parameter>4</parameter>
+      </constructor>
+      <property name="factory"><inject bean="Bean2TypeFactory"/></property>
+   </bean>
+   <bean name="BeanContainer2Type" class="org.jboss.test.kernel.deployment.support.container.BeanContainer">
+      <property name="pool"><inject bean="Bean2TypePool"/></property>
+   </bean>
+   */
+   protected KernelDeployment getDeploymentForDependencyInjectionOfBeanWithMismatchedPoolSizes()
+   {
+      KernelDeployment deployment = getDeploymentForDependencyInjectionOfBean();
+      // Update the pool ctors
+      List<BeanMetaDataFactory> beanFactories = deployment.getBeanFactories();
+      for(BeanMetaDataFactory bmdf : beanFactories)
+      {
+         if(bmdf instanceof AbstractBeanMetaData)
+         {
+            AbstractBeanMetaData abmd = (AbstractBeanMetaData) bmdf;
+            if(abmd.getName().equals("Bean1TypePool"))
+            {
+               AbstractConstructorMetaData ctor = new AbstractConstructorMetaData();
+               ArrayList<ParameterMetaData> params = new ArrayList<ParameterMetaData>();
+               params.add(new AbstractParameterMetaData(int.class.getName(), "3"));
+               ctor.setParameters(params);
+               abmd.setConstructor(ctor);
+            }
+            else if(abmd.getName().equals("Bean2TypePool"))
+            {
+               AbstractConstructorMetaData ctor = new AbstractConstructorMetaData();
+               ArrayList<ParameterMetaData> params = new ArrayList<ParameterMetaData>();
+               params.add(new AbstractParameterMetaData(int.class.getName(), "4"));
+               ctor.setParameters(params);
+               abmd.setConstructor(ctor);
+            }
+         }
+      }
+      return deployment;
+   }
+   /**
+    * MetaData version of testComponentBeanFactory
+    * 
+    * @return the kernel deployment
+    */
+   @SuppressWarnings("unchecked")
+   protected KernelDeployment getDeploymentForComponentBeanFactory()
+   {
+      AbstractKernelDeployment deployment = new AbstractKernelDeployment();
+      deployment.setName("ComponentBeanFactory");
+      ArrayList<BeanMetaDataFactory> beanFactories = new ArrayList<BeanMetaDataFactory>();
+      // Bean context factory for Bean1Type
+      BeanContainer<Bean1Type> container = new BeanContainer<Bean1Type>();
+      BeanContextFactory<Bean1Type> contextFactory = new BeanContextFactory<Bean1Type>();
+      contextFactory.setBeanClass(Bean1Type.class.getName());
+      contextFactory.setContainer(container);
+      String[] interceptorNames = {InstanceInterceptor.class.getName()};
+      contextFactory.setInterceptorNames(Arrays.asList(interceptorNames));
+      /*
+      BeanMetaDataFactory contextFactoryMD = installBeanInstance("ComponentBeanFactory", contextFactory);
+      beanFactories.add(contextFactoryMD);
+      */
+      ComponentVisitor visitor = null;
+      GenericComponentFactory componentFactory = new GenericComponentFactory(contextFactory, visitor);
+      BeanMetaDataFactory componentFactoryMD = installBeanInstance("ComponentBeanFactory", componentFactory);
+      beanFactories.add(componentFactoryMD);
+      deployment.setBeanFactories(beanFactories);
+
+      return deployment;
+   }
+
+   protected BeanMetaDataFactory installBeanInstance(String name, Object bean)
+   {
+      AbstractBeanMetaData beanMD = new AbstractBeanMetaData(name, bean.getClass().getName());
+      beanMD.setConstructor(new AlreadyInstantiated(bean));
+      return beanMD;
+   }
+
+   public static class AlreadyInstantiated extends AbstractConstructorMetaData
+   {
+      private static final long serialVersionUID = 1L;
+      
+      private Object bean;
+
+      public class Factory
+      {
+
+         public Object create()
+         {
+            return bean;
+         }
+      }
+
+      public AlreadyInstantiated(Object bean)
+      {
+         this.bean = bean;
+         this.setFactory(new AbstractValueMetaData(new Factory()));
+         this.setFactoryClass(Factory.class.getName());
+         this.setFactoryMethod("create");
+      }
+   }
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/component/test/BeanContainerUsageTestCase.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/component/test/BeanContainerUsageTestCase.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/component/test/BeanContainerUsageTestCase.java	2008-04-10 18:39:53 UTC (rev 71970)
@@ -0,0 +1,219 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.component.test;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.ControllerStateModel;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.test.component.support.container.Bean1Type;
+import org.jboss.test.component.support.container.Bean2Type;
+import org.jboss.test.component.support.container.BeanContainer;
+import org.jboss.test.component.support.container.BeanPool;
+import org.jboss.test.kernel.AbstractKernelTest;
+
+/**
+ * Bean Container Test Case.
+ * 
+ * @author <a href="scott.stark at jboss.com">Scott Stark</a>
+ * @version $Revision: 71929 $
+ */
+public class BeanContainerUsageTestCase extends AbstractKernelTest
+{
+   private Kernel kernel;
+   private BasicXMLDeployer deployer;
+
+   public static Test suite()
+   {
+      return suite(BeanContainerUsageTestCase.class);
+   }
+
+   public BeanContainerUsageTestCase(String name)
+   {
+      super(name);
+   }
+
+   @SuppressWarnings("unchecked")
+   public void testDependencyInjectionOfBean() throws Throwable
+   {
+      bootstrap();
+      // ???? BeanContainer<Bean1Type> container1 = (BeanContainer<Bean1Type>) getBean("BeanContainer1Type");
+      getBean("BeanContainer1Type");
+      BeanPool<Bean1Type> pool1 = (BeanPool<Bean1Type>) getBean("Bean1TypePool");
+      BeanContainer<Bean2Type> container2 = (BeanContainer<Bean2Type>) getBean("BeanContainer2Type");
+      Bean2Type bean21 = container2.getBean();
+      getLog().debug("bean21: "+bean21);
+      Bean1Type bean11 = bean21.getBean1();
+      assertEquals(0, pool1.size());
+      getLog().debug("bean11: "+bean11);
+      assertNotNull(bean11);
+      // Create another Bean2Type instance
+      Bean2Type bean22 = container2.getBean();
+      getLog().debug("bean22: "+bean22);
+      assertTrue(bean22 != bean21);
+      // The injected bean should not be the same as injected into bean21
+      Bean1Type bean12 = bean22.getBean1();
+      getLog().debug("bean12: "+bean12);
+      assertNotNull(bean12);
+      assertTrue(bean12 != bean11);
+
+      // Create another bean 2 type, should fail
+      Bean2Type bean23 = container2.getBean();
+      getLog().debug("bean23: "+bean23);
+      Bean1Type bean13Injected = bean23.getBean1();
+      getLog().debug("bean13Injected: "+bean13Injected);
+      assertNotNull(bean13Injected);
+      deployer.shutdown();
+   }
+   @SuppressWarnings("unchecked")
+   public void testDependencyInjectionOfBeanWithMismatchedPoolSizes()
+      throws Throwable
+   {
+      bootstrap();
+      BeanContainer<Bean2Type> container2 = (BeanContainer<Bean2Type>) getBean("BeanContainer2Type");
+      try
+      {
+         fail("Should not have been able to create a Bean2Type: " + container2.getBean());
+      }
+      catch(IllegalStateException e)
+      {
+         getLog().info("Saw expected IllegalStateException");
+      }
+      deployer.shutdown();
+   }
+
+   /**
+    * There is no xml version of ?
+    * @return ???
+    */
+   protected KernelDeployment getDeploymentForDependencyInjectionOfBean()
+   {
+      return null;
+   }
+
+   /**
+    * Either deploy a test specific xml descriptor, or obtain a test
+    * specific KernelDeployment by looking for a method
+    * "getDeploymentFor"+ getName().substring(4);
+    */
+   protected Kernel bootstrap() throws Throwable
+   {
+      kernel = super.bootstrap();
+      deployer = new BasicXMLDeployer(kernel, ControllerMode.AUTOMATIC);
+      String testName = "getDeploymentFor"+ getName().substring(4);
+      KernelDeployment deployment = null;
+      try
+      {
+         Method getDeployment = getClass().getDeclaredMethod(testName, null);
+         deployment = (KernelDeployment) getDeployment.invoke(this, null);
+      }
+      catch(NoSuchMethodException e)
+      {
+         getLog().debug("Ignoring: "+e);
+      }
+
+      if(deployment == null)
+      {
+         String xmlName = getClass().getName() + "_" + super.getName();
+         xmlName = xmlName.replace('.', '/') + ".xml";
+         URL url = getClass().getClassLoader().getResource(xmlName);
+         if (url != null)
+            deployer.deploy(url);
+         else
+            getLog().debug("No test specific deployment " + xmlName);
+      }
+      else
+      {
+         deployer.deploy(deployment);
+      }
+      deployer.validate();
+      return kernel;
+   }
+   protected void shutdown()
+   {
+      deployer.shutdown();
+   }
+   protected void assertNoBeansExist()
+   {
+      KernelController controller = kernel.getController();
+      ControllerStateModel states = controller.getStates();
+      int beanCount = 0;
+      for(ControllerState s : states)
+      {
+         Set<ControllerContext> ctxs = controller.getContextsByState(s);
+         beanCount += ctxs.size();
+      }
+      assertEquals(0, beanCount);
+   }
+   protected void assertBeansExist(Set<String> names)
+   {
+      HashSet<String> unexpectedBeanNames = new HashSet<String>();
+      KernelController controller = kernel.getController();
+      ControllerStateModel states = controller.getStates();
+      for(ControllerState s : states)
+      {
+         Set<ControllerContext> ctxs = controller.getContextsByState(s);
+         for(ControllerContext ctx : ctxs)
+         {
+            String name = ctx.getName().toString();
+            if(names.contains(name) == false)
+               unexpectedBeanNames.add(name);
+         }
+      }
+      assertEquals(Collections.emptySet(), unexpectedBeanNames);
+   }
+   protected Object getBean(final Object name)
+   {
+      KernelControllerContext context = getControllerContext(name, ControllerState.INSTALLED);
+      return context.getTarget();
+   }
+   protected KernelControllerContext getControllerContext(final Object name, final ControllerState state)
+   {
+      KernelController controller = kernel.getController();
+      KernelControllerContext context = (KernelControllerContext) controller.getContext(name, state);
+      if (context == null)
+      {
+         getLog().error("Bean not found " + name + " at state " + state);
+         ControllerStateModel states = controller.getStates();
+         for(ControllerState s : states)
+         {
+            getLog().info(s+": "+controller.getContextsByState(s));
+         }
+         throw new IllegalStateException("Bean not found " + name + " at state " + state);
+      }
+      return context;
+   }
+
+}

Added: projects/component-injection/trunk/src/tests/org/jboss/test/kernel/AbstractKernelTest.java
===================================================================
--- projects/component-injection/trunk/src/tests/org/jboss/test/kernel/AbstractKernelTest.java	                        (rev 0)
+++ projects/component-injection/trunk/src/tests/org/jboss/test/kernel/AbstractKernelTest.java	2008-04-10 18:39:53 UTC (rev 71970)
@@ -0,0 +1,146 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.registry.AbstractKernelRegistryEntry;
+import org.jboss.kernel.spi.registry.KernelRegistryEntry;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.util.NestedRuntimeException;
+
+/**
+ * An abstract kernel test.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 71345 $
+ */
+public class AbstractKernelTest extends AbstractTestCaseWithSetup
+{
+   private static DateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US);
+   private Locale locale;
+
+   public AbstractKernelTest(String name)
+   {
+      super(name);
+   }
+
+   protected void setUp() throws Exception
+   {
+      // set locales
+      locale = Locale.getDefault();
+      setLocale(Locale.US);
+
+      super.setUp();
+   }
+
+   protected void setLocale(Locale locale)
+   {
+      SecurityManager sm = suspendSecurity();
+      try
+      {
+         Locale.setDefault(locale);
+      }
+      finally
+      {
+         resumeSecurity(sm);
+      }
+   }
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+
+      // reset locale
+      setLocale(locale);
+      locale = null;
+   }
+
+   protected Kernel bootstrap() throws Throwable
+   {
+      BasicBootstrap bootstrap = new BasicBootstrap();
+      bootstrap.run();
+      configureLoggingAfterBootstrap();
+      return bootstrap.getKernel();
+   }
+   
+   protected static void assertEqualsRegistryTarget(KernelRegistryEntry e1, KernelRegistryEntry e2)
+   {
+      assertEquals(e1.getTarget(), e2.getTarget());
+   }
+
+   protected static KernelRegistryEntry makeEntry(Object o)
+   {
+      return new AbstractKernelRegistryEntry(o);
+   }
+
+   protected Date createDate(String date)
+   {
+      Locale locale = Locale.getDefault();
+      try
+      {
+         setLocale(Locale.US);
+         return dateFormat.parse(date);
+      }
+      catch (Exception e)
+      {
+         throw new NestedRuntimeException(e);
+      }
+      finally
+      {
+         setLocale(locale);   
+      }
+   }
+
+   protected Date createDate(int year, int month, int day)
+   {
+      Calendar calender = Calendar.getInstance();
+      calender.clear();
+      calender.set(year, month-1, day, 0, 0, 0);
+      return calender.getTime();
+   }
+
+   protected void configureLoggingAfterBootstrap()
+   {
+   }
+   
+   /**
+    * Default setup with security manager enabled
+    * 
+    * @param clazz the class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
+      delegate.enableSecurity = true;
+      return delegate;
+   }
+}




More information about the jboss-cvs-commits mailing list