[jboss-cvs] JBossAS SVN: r71812 - in projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment: test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 8 23:00:00 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-04-08 23:00:00 -0400 (Tue, 08 Apr 2008)
New Revision: 71812
Added:
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BaseContext.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanContext.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanContextFactory.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/InstanceInterceptor.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/TestInjectionMetaData.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/TestInjectionTargetMetaData.java
Modified:
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanPool.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/BeanContainerUsageMDTestCase.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/BeanContainerUsageTestCase.java
Log:
Update bean container factory test with bean context usecase
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BaseContext.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BaseContext.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BaseContext.java 2008-04-09 03:00:00 UTC (rev 71812)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.kernel.deployment.support.container;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class BaseContext <B, C extends BeanContainer<B>>
+ implements BeanContext<C>
+{
+ protected static Logger log = Logger.getLogger(BaseContext.class);
+ protected C container;
+ protected B bean;
+
+ protected List<Object> interceptorInstances = new ArrayList();
+
+ public BaseContext(C container)
+ {
+ this.container = container;
+ log.info("ctor, container: "+container);
+ }
+
+ public C getContainer()
+ {
+ return container;
+ }
+
+ public B getInstance()
+ {
+ return bean;
+ }
+ public void setInstance(B bean)
+ {
+ this.bean = bean;
+ log.info("setInstance, bean: "+bean);
+ }
+
+
+ public HashMap<Class, Object> getInterceptorInstances()
+ {
+ return null;
+ }
+ public List getInterceptors()
+ {
+ return interceptorInstances;
+ }
+
+ public void initialiseInterceptorInstances()
+ {
+ }
+ public void addInterceptor(Object interceptor)
+ {
+ interceptorInstances.add(interceptor);
+ log.info("addInterceptor, "+interceptor);
+ }
+ public void removeInterceptor(Object interceptor)
+ {
+ interceptorInstances.remove(interceptor);
+ log.info("removeInterceptor, "+interceptor);
+ }
+ public void remove()
+ {
+ // TODO Auto-generated method stub
+
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanContext.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanContext.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanContext.java 2008-04-09 03:00:00 UTC (rev 71812)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.kernel.deployment.support.container;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public interface BeanContext<C extends BeanContainer>
+{
+ Object getInstance();
+
+ C getContainer();
+
+ void initialiseInterceptorInstances();
+
+ void remove();
+
+ //EJBContext getEJBContext();
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanContextFactory.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanContextFactory.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanContextFactory.java 2008-04-09 03:00:00 UTC (rev 71812)
@@ -0,0 +1,256 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.kernel.deployment.support.container;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.beans.info.spi.BeanAccessMode;
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.beans.metadata.plugins.builder.ParameterMetaDataBuilderImpl;
+import org.jboss.beans.metadata.plugins.factory.GenericBeanFactory;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
+import org.jboss.logging.Logger;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class BeanContextFactory<T> implements BeanMetaDataFactory, KernelControllerContextAware
+{
+ private static final Logger log = Logger.getLogger(BeanContextFactory.class);
+ private String baseName;
+ private String beanClass;
+ private BeanContainer<T> container;
+ private Set<TestInjectionMetaData> beanInjectionMD;
+ private KernelConfigurator configurator;
+ private Map<String, Set<TestInjectionMetaData>> interceptorInjectionMD =
+ new HashMap<String, Set<TestInjectionMetaData>>();
+ private List<String> interceptorNames;
+ private List<Object> interceptors = new ArrayList<Object>();
+
+ public String getBaseName()
+ {
+ return baseName;
+ }
+ public void setBaseName(String baseName)
+ {
+ this.baseName = baseName;
+ }
+
+ public String getBeanClass()
+ {
+ return beanClass;
+ }
+ public void setBeanClass(String beanClass)
+ {
+ this.beanClass = beanClass;
+ }
+ public BeanContainer<T> getContainer()
+ {
+ return container;
+ }
+ public void setContainer(BeanContainer<T> container)
+ {
+ this.container = container;
+ }
+ public Set<TestInjectionMetaData> getBeanInjectionMD()
+ {
+ return beanInjectionMD;
+ }
+ public void setBeanInjectionMD(Set<TestInjectionMetaData> beanInjectionMD)
+ {
+ this.beanInjectionMD = beanInjectionMD;
+ }
+ public Map<String, Set<TestInjectionMetaData>> getInterceptorInjectionMD()
+ {
+ return interceptorInjectionMD;
+ }
+ public void setInterceptorInjectionMD(
+ Map<String, Set<TestInjectionMetaData>> interceptorInjectionMD)
+ {
+ this.interceptorInjectionMD = interceptorInjectionMD;
+ }
+ public List<String> getInterceptorNames()
+ {
+ return interceptorNames;
+ }
+ public void setInterceptorNames(List<String> interceptorNames)
+ {
+ this.interceptorNames = interceptorNames;
+ }
+
+ public void setKernelControllerContext(KernelControllerContext context)
+ throws Exception
+ {
+ if(context != null)
+ {
+ configurator = context.getKernel().getConfigurator();
+ }
+ }
+ public void unsetKernelControllerContext(KernelControllerContext context)
+ throws Exception
+ {
+ configurator = null;
+ }
+
+ /**
+ * Create the beans that make up the bean component
+ */
+ public List<BeanMetaData> getBeans()
+ {
+ ArrayList<BeanMetaData> beans = new ArrayList<BeanMetaData>();
+ try
+ {
+ // Create the BeanContext factory
+ String contextName = baseName +"#ContextFactory";
+ AbstractBeanMetaData contextMetaData = new AbstractBeanMetaData(contextName, GenericBeanFactory.class.getName());
+ BeanMetaDataBuilder contextBuilder = BeanMetaDataBuilder.createBuilder(contextMetaData);
+ contextBuilder.setAccessMode(BeanAccessMode.ALL);
+ ValueMetaData injectKernelConfigurator = contextBuilder.createInject(KernelConstants.KERNEL_CONFIGURATOR_NAME);
+ contextBuilder.addConstructorParameter(KernelConfigurator.class.getName(), injectKernelConfigurator);
+ contextBuilder.addPropertyMetaData("bean", BaseContext.class.getName());
+ // The BaseContext ctor
+ AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
+ ParameterMetaDataBuilderImpl<AbstractConstructorMetaData> constructorBuilder = new ParameterMetaDataBuilderImpl<AbstractConstructorMetaData>(constructor);
+ constructorBuilder.addParameterMetaData(BeanContainer.class.getName(), container);
+ contextBuilder.addPropertyMetaData("constructor", constructor);
+ // BaseContext properties
+ Set<PropertyMetaData> contextProperties = new HashSet<PropertyMetaData>();
+ // BaseContext.instance
+ String beanName = baseName+"#BeanInstance";
+ ValueMetaData beanInstance = contextBuilder.createInject(beanName);
+ PropertyMetaData instancePMD = new AbstractPropertyMetaData("instance", beanInstance);
+ contextProperties.add(instancePMD);
+
+ PropertyMap propertyMap = new PropertyMap();
+ for (PropertyMetaData property : contextProperties)
+ {
+ propertyMap.put(property.getName(), property.getValue());
+ }
+ contextBuilder.addPropertyMetaData("properties", propertyMap);
+ BeanMetaData beanContext = contextBuilder.getBeanMetaData();
+ beans.add(beanContext);
+
+ // Create the instance bean
+ BeanMetaDataBuilder beanBuilder = BeanMetaDataBuilder.createBuilder(beanName, beanClass);
+ beanBuilder.setAccessMode(BeanAccessMode.ALL);
+ // For every injection target get the associated property
+ if(beanInjectionMD != null)
+ {
+ addDependencyInjection(beanClass, beanInjectionMD, beanBuilder);
+ }
+ beans.add(beanBuilder.getBeanMetaData());
+
+ // Create the interceptors
+ int count = interceptorNames != null ? interceptorNames.size() : 0;
+ for(int n = 0; n < count; n ++)
+ {
+ String name = baseName + "#Interceptor:"+n;
+ String iclass = interceptorNames.get(n);
+ BeanMetaDataBuilder ibuilder = BeanMetaDataBuilder.createBuilder(name, iclass);
+ ibuilder.addInstall("addInterceptor", contextName);
+ ibuilder.addUninstall("removeInterceptor", contextName);
+ Set<TestInjectionMetaData> injectMDs = interceptorInjectionMD.get(iclass);
+ if(injectMDs != null)
+ addDependencyInjection(beanClass, injectMDs, beanBuilder);
+ BeanMetaData interceptor = ibuilder.getBeanMetaData();
+ beans.add(interceptor);
+ }
+ }
+ catch(Throwable t)
+ {
+ log.error("Failed to create component beans", t);
+ throw new RuntimeException(t);
+ }
+ log.info("getBeans returning: "+beans);
+ return beans;
+ }
+
+ private void addDependencyInjection(String clazzName,
+ Set<TestInjectionMetaData> injectMDs,
+ BeanMetaDataBuilder beanBuilder)
+ throws Throwable
+ {
+ ClassLoader loader = getClass().getClassLoader();
+ BeanInfo beanInfo = configurator.getBeanInfo(clazzName, loader);
+ for(TestInjectionMetaData injectMD : injectMDs)
+ {
+ if(injectMD.getInjectionTargets() != null)
+ {
+ for(TestInjectionTargetMetaData targetMD : injectMD.getInjectionTargets())
+ {
+ ValueMetaData injectValue = beanBuilder.createInject(injectMD.getResolvedJndiName());
+ String targetName = targetMD.getInjectionTargetName();
+ PropertyInfo pinfo = beanInfo.getProperty(targetName);
+ if(pinfo != null)
+ {
+ beanBuilder.addPropertyMetaData(targetName, injectValue);
+ }
+ else
+ {
+ log.warn("No property found for injection target:"+targetName+", on bean: "+beanClass);
+ }
+ }
+ }
+ }
+ }
+ private class PropertyMap extends HashMap<String, ValueMetaData> implements MetaDataVisitorNode
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -4295725682462294630L;
+
+ public void initialVisit(MetaDataVisitor visitor)
+ {
+ visitor.initialVisit(this);
+ }
+
+ public void describeVisit(MetaDataVisitor vistor)
+ {
+ vistor.describeVisit(this);
+ }
+
+ public Iterator<? extends MetaDataVisitorNode> getChildren()
+ {
+ return values().iterator();
+ }
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanPool.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanPool.java 2008-04-08 23:02:03 UTC (rev 71811)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/BeanPool.java 2008-04-09 03:00:00 UTC (rev 71812)
@@ -97,6 +97,12 @@
public void destroyBean(T bean)
throws Throwable
{
+ bean = (T) factory.createBean();
pool.put(bean);
}
+ public void releaseBean(T bean)
+ throws Throwable
+ {
+ pool.put(bean);
+ }
}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/InstanceInterceptor.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/InstanceInterceptor.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/InstanceInterceptor.java 2008-04-09 03:00:00 UTC (rev 71812)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.kernel.deployment.support.container;
+
+import java.lang.reflect.Method;
+
+
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class InstanceInterceptor
+{
+ private BeanPool<BeanContext<?>> pool;
+
+ public Object invoke(Object...args)
+ throws Throwable
+ {
+ BeanContext<?> ctx = pool.createBean();
+ Object bean = ctx.getInstance();
+
+ boolean discard = false;
+ Object value = null;
+
+ try
+ {
+ String name = (String) args[0];
+ Class<?>[] paramTypes = {};
+ Method m = bean.getClass().getMethod(name, paramTypes);
+ Object[] empty = {};
+ value = m.invoke(bean, empty);
+ return value;
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ finally
+ {
+ if (discard)
+ pool.destroyBean(ctx);
+ else pool.releaseBean(ctx);
+ }
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/TestInjectionMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/TestInjectionMetaData.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/TestInjectionMetaData.java 2008-04-09 03:00:00 UTC (rev 71812)
@@ -0,0 +1,160 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.kernel.deployment.support.container;
+
+import java.util.Set;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class TestInjectionMetaData
+{
+ /** The mapped name */
+ private String mappedName;
+ private String resolvedJndiName;
+ private boolean ignoreDependency;
+
+ /** The injection targets */
+ private Set<TestInjectionTargetMetaData> injectionTargets;
+
+ /**
+ * Create a new ResourceInjectionMetaData.
+ */
+ public TestInjectionMetaData()
+ {
+ // For serialization
+ }
+
+ /**
+ * Get the jndiName.
+ *
+ * @return the jndiName.
+ */
+ public String getJndiName()
+ {
+ return getMappedName();
+ }
+
+ /**
+ * Set the jndiName.
+ *
+ * @param jndiName the jndiName.
+ * @throws IllegalArgumentException for a null jndiName
+ */
+ public void setJndiName(String jndiName)
+ {
+ setMappedName(jndiName);
+ }
+
+ /**
+ * Get the mappedName.
+ *
+ * @return the mappedName.
+ */
+ public String getMappedName()
+ {
+ return mappedName;
+ }
+
+ /**
+ * Set the mappedName.
+ *
+ * @param mappedName the mappedName.
+ * @throws IllegalArgumentException for a null mappedName
+ */
+ public void setMappedName(String mappedName)
+ {
+ if (mappedName == null)
+ throw new IllegalArgumentException("Null mappedName");
+ this.mappedName = mappedName;
+ }
+
+ /**
+ * An unmanaged runtime jndi name for the resource. Used by deployers to
+ * propagate resolved resource location.
+ *
+ * @return
+ */
+ public String getResolvedJndiName()
+ {
+ return resolvedJndiName;
+ }
+ public void setResolvedJndiName(String resolvedJndiName)
+ {
+ this.resolvedJndiName = resolvedJndiName;
+ }
+
+ /**
+ * Get the injectionTargets.
+ *
+ * @return the injectionTargets.
+ */
+ public Set<TestInjectionTargetMetaData> getInjectionTargets()
+ {
+ return injectionTargets;
+ }
+
+ /**
+ * Set the injectionTargets.
+ *
+ * @param injectionTargets the injectionTargets.
+ * @throws IllegalArgumentException for a null injectionTargets
+ */
+ public void setInjectionTargets(Set<TestInjectionTargetMetaData> injectionTargets)
+ {
+ if (injectionTargets == null)
+ throw new IllegalArgumentException("Null injectionTargets");
+ this.injectionTargets = injectionTargets;
+ }
+
+ /**
+ * Get the ignoreDependency.
+ *
+ * @return the ignoreDependency.
+ */
+ public boolean getIgnoreDependency()
+ {
+ return ignoreDependency;
+ }
+
+ /**
+ * Set the ignoreDependency.
+ *
+ * @param ignoreDependency the ignoreDependency.
+ * @throws IllegalArgumentException for a null ignoreDependency
+ */
+ public void setIgnoreDependency(boolean flag)
+ {
+ this.ignoreDependency = flag;
+ }
+
+ /**
+ * Get whether the dependency is ignored
+ *
+ * @return true when the dependency is ignored
+ */
+ public boolean isDependencyIgnored()
+ {
+ return ignoreDependency;
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/TestInjectionTargetMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/TestInjectionTargetMetaData.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/container/TestInjectionTargetMetaData.java 2008-04-09 03:00:00 UTC (rev 71812)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.kernel.deployment.support.container;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class TestInjectionTargetMetaData
+{
+ /** The injection target class */
+ private String injectionTargetClass;
+
+ /** The injection target name */
+ private String injectionTargetName;
+
+ /**
+ * Create a new ResourceInjectionTargetMetaData.
+ */
+ public TestInjectionTargetMetaData()
+ {
+ }
+
+ /**
+ * Get the injectionTargetClass.
+ *
+ * @return the injectionTargetClass.
+ */
+ public String getInjectionTargetClass()
+ {
+ return injectionTargetClass;
+ }
+
+ /**
+ * Set the injectionTargetClass.
+ *
+ * @param injectionTargetClass the injectionTargetClass.
+ * @throws IllegalArgumentException for a null injectionTargetClass
+ */
+ //@JBossXmlNsPrefix(prefix="jee")
+ public void setInjectionTargetClass(String injectionTargetClass)
+ {
+ if (injectionTargetClass == null)
+ throw new IllegalArgumentException("Null injectionTargetClass");
+ this.injectionTargetClass = injectionTargetClass;
+ }
+
+ /**
+ * Get the injectionTargetName.
+ *
+ * @return the injectionTargetName.
+ */
+ public String getInjectionTargetName()
+ {
+ return injectionTargetName;
+ }
+
+ /**
+ * Set the injectionTargetName.
+ *
+ * @param injectionTargetName the injectionTargetName.
+ * @throws IllegalArgumentException for a null injectionTargetName
+ */
+ //@JBossXmlNsPrefix(prefix="jee")
+ public void setInjectionTargetName(String injectionTargetName)
+ {
+ if (injectionTargetName == null)
+ throw new IllegalArgumentException("Null injectionTargetName");
+ this.injectionTargetName = injectionTargetName;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((injectionTargetClass == null) ? 0 : injectionTargetClass.hashCode());
+ result = PRIME * result + ((injectionTargetName == null) ? 0 : injectionTargetName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final TestInjectionTargetMetaData other = (TestInjectionTargetMetaData) obj;
+ if (injectionTargetClass == null)
+ {
+ if (other.injectionTargetClass != null)
+ return false;
+ }
+ else if (!injectionTargetClass.equals(other.injectionTargetClass))
+ return false;
+ if (injectionTargetName == null)
+ {
+ if (other.injectionTargetName != null)
+ return false;
+ }
+ else if (!injectionTargetName.equals(other.injectionTargetName))
+ return false;
+ return true;
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/BeanContainerUsageMDTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/BeanContainerUsageMDTestCase.java 2008-04-08 23:02:03 UTC (rev 71811)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/BeanContainerUsageMDTestCase.java 2008-04-09 03:00:00 UTC (rev 71812)
@@ -22,6 +22,7 @@
package org.jboss.test.kernel.deployment.test;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -34,12 +35,18 @@
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.BeanMetaData;
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.kernel.plugins.deployment.AbstractKernelDeployment;
import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.test.kernel.deployment.support.container.Bean1Type;
+import org.jboss.test.kernel.deployment.support.container.BeanContainer;
+import org.jboss.test.kernel.deployment.support.container.BeanContextFactory;
+import org.jboss.test.kernel.deployment.support.container.InstanceInterceptor;
/**
* Programatic version of the BeanContainerUsageTestCase tests
@@ -186,4 +193,62 @@
}
return deployment;
}
+ /**
+ * MetaData version of testComponentBeanFactory
+ *
+ * @return
+ */
+ 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.setBaseName("ComponentBeanFactory");
+ 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);
+ */
+ beanFactories.add(contextFactory);
+ 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");
+ }
+ }
}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/BeanContainerUsageTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/BeanContainerUsageTestCase.java 2008-04-08 23:02:03 UTC (rev 71811)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/BeanContainerUsageTestCase.java 2008-04-09 03:00:00 UTC (rev 71812)
@@ -24,9 +24,15 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import junit.framework.Test;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.spi.factory.BeanFactory;
import org.jboss.dependency.spi.ControllerMode;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.kernel.Kernel;
@@ -35,9 +41,11 @@
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.kernel.spi.deployment.KernelDeployment;
import org.jboss.test.kernel.AbstractKernelTest;
+import org.jboss.test.kernel.deployment.support.container.BaseContext;
import org.jboss.test.kernel.deployment.support.container.Bean1Type;
import org.jboss.test.kernel.deployment.support.container.Bean2Type;
import org.jboss.test.kernel.deployment.support.container.BeanContainer;
+import org.jboss.test.kernel.deployment.support.container.BeanContextFactory;
import org.jboss.test.kernel.deployment.support.container.BeanPool;
/**
@@ -109,10 +117,52 @@
deployer.shutdown();
}
+ public void testComponentBeanFactory()
+ throws Throwable
+ {
+ bootstrap();
+ /*BeanContextFactory<Bean1Type> contextFactory = (BeanContextFactory<Bean1Type>) bean;
+ assertEquals(Bean1Type.class.getName(), contextFactory.getBeanClass());
+ assertNotNull(bean);
+ contextFactory.
+ */
+ BeanFactory factory = (BeanFactory) getBean("ComponentBeanFactory#ContextFactory");
+ getLog().info("ComponentBeanFactory#ContextFactory bean: "+factory);
+ assertNotNull(factory);
+
+ BaseContext <Bean1Type, BeanContainer<Bean1Type>> context =
+ (BaseContext <Bean1Type, BeanContainer<Bean1Type>>) factory.createBean();
+ getLog().info("ComponentBeanFactory#ContextFactory.createBean result: "+context);
+ assertNotNull(context);
+ Bean1Type bean1 = context.getInstance();
+ getLog().info("BeanContext.instance: "+bean1);
+ HashMap<Class, Object> interceptors1 = context.getInterceptorInstances();
+ getLog().info("BeanContext.interceptorInstances: "+interceptors1);
+
+ Bean1Type bean11 = (Bean1Type) getBean("ComponentBeanFactory#BeanInstance");
+ getLog().info("ComponentBeanFactory#BeanInstance bean: "+bean11);
+ assertNotNull(bean11);
+ assertTrue(bean1 == bean11);
+
+ deployer.shutdown();
+ }
+
+ /**
+ * There is no xml version of ?
+ * @return
+ */
protected KernelDeployment getDeploymentForDependencyInjectionOfBean()
{
return null;
}
+ /**
+ * There is no xml based version of testComponentBeanFactory
+ * @return
+ */
+ protected KernelDeployment getComponentBeanFactory()
+ {
+ return null;
+ }
/**
* Either deploy a test specific xml descriptor, or obtain a test
@@ -162,7 +212,15 @@
KernelController controller = kernel.getController();
KernelControllerContext context = (KernelControllerContext) controller.getContext(name, state);
if (context == null)
+ {
+ getLog().error("Bean not found " + name + " at state " + state);
+ List<ControllerState> 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;
}
More information about the jboss-cvs-commits
mailing list