[jboss-cvs] JBossAS SVN: r76545 - in trunk: system-jmx/src/resources/tests/org/jboss/test/system/metadata/value and 12 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 31 23:14:08 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-07-31 23:14:08 -0400 (Thu, 31 Jul 2008)
New Revision: 76545
Added:
trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceValueFactoryParameterMetaData.java
trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceValueFactoryValueMetaData.java
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/BasicValueFactory.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/Minimal.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NestedBean.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NoDefault.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NoParameter.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NullParameter.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/State.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/TypedParameters.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/TypedParametersWithValue.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/UntypedParameters.xml
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/UntypedParametersWithValue.xml
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/MockMethodInfo.java
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/MockTypeInfo.java
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ServiceValueFactoryParameterMetaDataUnitTestCase.java
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ValueFactoryParsingUnitTestCase.java
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ValueFactoryTypeAnalysisUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/
trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean1.java
trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean1MBean.java
trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean2.java
trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean2MBean.java
trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/test/
trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/test/ValueFactoryInjectionUnitTestCase.java
trunk/testsuite/src/resources/deployers/valuefactory/
trunk/testsuite/src/resources/deployers/valuefactory/jboss-beans.xml
trunk/testsuite/src/resources/deployers/valuefactory/valuefactory-service.xml
Modified:
trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataParser.java
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/test/AbstractMetaDataTest.java
trunk/testsuite/imports/sections/deployers.xml
Log:
[JBAS-5822] Add support for value-factory injection to -service.xml parsing
Modified: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataParser.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataParser.java 2008-08-01 02:22:10 UTC (rev 76544)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataParser.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -230,17 +230,12 @@
String tagName = el.getTagName();
if ("inject".equals(tagName))
{
- String dependency = el.getAttribute("bean");
- String property = null;
- Attr attr = el.getAttributeNode("property");
- if (attr != null)
- property = attr.getValue();
- ControllerState requiredState = ControllerState.INSTALLED;
- attr = el.getAttributeNode("state");
- if (attr != null)
- requiredState = new ControllerState(attr.getValue());
- value = new ServiceInjectionValueMetaData(dependency, property, requiredState);
+ value = parseInject(el);
}
+ else if ("value-factory".equals(tagName))
+ {
+ value = parseValueFactory(el);
+ }
else
{
value = new ServiceElementValueMetaData((Element) n);
@@ -526,6 +521,98 @@
return (Element) mbeans.item(0);
}
+ private ServiceValueMetaData parseInject(Element el)
+ {
+ ServiceValueMetaData value;
+ String dependency = el.getAttribute("bean");
+ String property = null;
+ Attr attr = el.getAttributeNode("property");
+ if (attr != null)
+ property = attr.getValue();
+ ControllerState requiredState = ControllerState.INSTALLED;
+ attr = el.getAttributeNode("state");
+ if (attr != null)
+ requiredState = new ControllerState(attr.getValue());
+ value = new ServiceInjectionValueMetaData(dependency, property, requiredState);
+ return value;
+ }
+
+ private ServiceValueMetaData parseValueFactory(Element el) throws DeploymentException
+ {
+ ServiceValueMetaData value;
+ String dependency = el.getAttribute("bean");
+
+ String method = el.getAttribute("method");
+
+ ControllerState requiredState = ControllerState.INSTALLED;
+ Attr attr = el.getAttributeNode("state");
+ if (attr != null)
+ requiredState = new ControllerState(attr.getValue());
+
+ List<ServiceValueFactoryParameterMetaData> parameters = new ArrayList<ServiceValueFactoryParameterMetaData>();
+ attr = el.getAttributeNode("parameter");
+ if (attr != null)
+ {
+ parameters.add(new ServiceValueFactoryParameterMetaData(attr.getValue()));
+ }
+ else
+ {
+ NodeList children = el.getChildNodes();
+ for (int j = 0; j < children.getLength(); j++)
+ {
+ // skip over non-element nodes
+ if (children.item(j).getNodeType() != Node.ELEMENT_NODE)
+ continue;
+
+ Element child = (Element) children.item(j);
+ if ("parameter".equals(child.getTagName()))
+ {
+ parameters.add(parseValueFactoryParameter(child));
+ }
+ }
+ }
+
+ ServiceTextValueMetaData defaultValue = null;
+ attr = el.getAttributeNode("default");
+ if (attr != null)
+ {
+ defaultValue = new ServiceTextValueMetaData(attr.getValue());
+ }
+ value = new ServiceValueFactoryValueMetaData(dependency, method, parameters, requiredState, defaultValue);
+ return value;
+ }
+
+ private ServiceValueFactoryParameterMetaData parseValueFactoryParameter(Element el) throws DeploymentException
+ {
+ String parameterType = null;
+ Attr attr = el.getAttributeNode("class");
+ if (attr != null)
+ parameterType = attr.getValue();
+
+ String textValue = null;
+ String valueType = null;
+
+ Node child = el.getFirstChild();
+ if (child.getNodeType() == Node.ELEMENT_NODE)
+ {
+ if ("value".equals(((Element)child).getTagName()))
+ {
+ valueType = ((Element)child).getAttribute("class");
+ textValue = child.getFirstChild().getNodeValue();
+ }
+ else if ("null".equals(((Element)child).getTagName()) == false)
+ {
+ throw new DeploymentException("Element " + ((Element)child).getTagName() + " not supported as a child of value-factory/parameter in a -service.xml");
+ }
+ }
+ else if (child.getNodeType() == Node.TEXT_NODE)
+ {
+ textValue = child.getNodeValue();
+ }
+
+ return new ServiceValueFactoryParameterMetaData(textValue, parameterType, valueType);
+ }
+
/**
* Process a dependency
*
Added: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceValueFactoryParameterMetaData.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceValueFactoryParameterMetaData.java (rev 0)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceValueFactoryParameterMetaData.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,177 @@
+/*
+ * 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.system.metadata;
+
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
+import java.lang.reflect.Constructor;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.util.Classes;
+
+/**
+ * A ServiceParameterTypeMetaData.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class ServiceValueFactoryParameterMetaData
+{
+ private final String textValue;
+ private final String valueTypeName;
+ private String parameterTypeName;
+
+ public ServiceValueFactoryParameterMetaData(String textValue)
+ {
+ this(textValue, null, null);
+ }
+
+ public ServiceValueFactoryParameterMetaData(String textValue, String parameterTypeName)
+ {
+ this(textValue, parameterTypeName, null);
+ }
+
+ public ServiceValueFactoryParameterMetaData(String textValue, String parameterTypeName, String valueTypeName)
+ {
+ this.textValue = textValue;
+ this.valueTypeName = valueTypeName;
+ this.parameterTypeName = parameterTypeName;
+ }
+
+ public String getParameterTypeName()
+ {
+ return parameterTypeName;
+ }
+
+ public void setParameterTypeName(String parameterTypeName)
+ {
+ this.parameterTypeName = parameterTypeName;
+ }
+
+ public Object getValue(ServiceValueContext valueContext) throws DeploymentException
+ {
+ if (this.parameterTypeName == null)
+ throw new IllegalStateException("Must set parameterTypeName");
+
+ String desiredType = (this.valueTypeName == null ? parameterTypeName : valueTypeName);
+
+ return getValue(valueContext.getClassloader(), this.textValue, desiredType, valueContext.getAttributeInfo().getName());
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+
+ if (obj instanceof ServiceValueFactoryParameterMetaData)
+ {
+ ServiceValueFactoryParameterMetaData other = (ServiceValueFactoryParameterMetaData) obj;
+ return safeEquals(this.textValue, other.textValue)
+ && safeEquals(this.parameterTypeName, other.parameterTypeName)
+ && safeEquals(this.valueTypeName, other.valueTypeName);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 17;
+ result += 29 * (this.textValue == null ? 0 : this.textValue.hashCode());
+ result += 29 * (this.parameterTypeName == null ? 0 : this.parameterTypeName.hashCode());
+ result += 29 * (this.valueTypeName == null ? 0 : this.valueTypeName.hashCode());
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return new StringBuilder(getClass().getSimpleName())
+ .append("{textValue=").append(textValue)
+ .append(",parameterTypeName=").append(parameterTypeName)
+ .append(",valueTypeName=").append(valueTypeName).toString();
+ }
+
+ private boolean safeEquals(Object a, Object b)
+ {
+ return (a == b || (a != null && a.equals(b)));
+ }
+
+ public static Object getValue(ClassLoader serviceValueContextClassloader, String textValue, String typeName, String targetAttributeName) throws DeploymentException
+ {
+ if (textValue == null)
+ return null;
+
+ // see if it is a primitive type first
+ Class typeClass = Classes.getPrimitiveTypeForName(typeName);
+ if (typeClass == null)
+ {
+ // nope try look up
+ try
+ {
+ typeClass = serviceValueContextClassloader.loadClass(typeName);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new DeploymentException("Class not found for attribute: " + targetAttributeName, e);
+ }
+ }
+
+ if (String.class == typeClass)
+ return textValue;
+
+ PropertyEditor editor = PropertyEditorManager.findEditor(typeClass);
+ if (editor == null)
+ {
+ try
+ {
+ // See if there is a ctor(String) for the type
+ Class[] sig = {String.class};
+ Constructor ctor = typeClass.getConstructor(sig);
+ Object[] args = {textValue};
+ return ctor.newInstance(args);
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException("No property editor for attribute: " + targetAttributeName + "; type=" + typeClass.getName());
+ }
+ }
+ else
+ {
+ // JBAS-1709, temporarily switch the TCL so that property
+ // editors have access to the actual deployment ClassLoader.
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(serviceValueContextClassloader);
+ try
+ {
+ editor.setAsText(textValue);
+ return editor.getValue();
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
+ }
+ }
+}
Added: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceValueFactoryValueMetaData.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceValueFactoryValueMetaData.java (rev 0)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceValueFactoryValueMetaData.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,317 @@
+/*
+* 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.system.metadata;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.system.microcontainer.ServiceControllerContext;
+
+/**
+ * ServiceInjectionValueMetaData.
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 1.1 $
+ */
+public class ServiceValueFactoryValueMetaData extends AbstractMetaDataVisitorNode
+ implements ServiceValueMetaData, Serializable
+{
+ private static final long serialVersionUID = 2;
+
+ /** The dependency */
+ private final Object dependency;
+
+ /** The method */
+ private final String method;
+
+ private final ServiceTextValueMetaData defaultValue;
+
+ private final List<ServiceValueFactoryParameterMetaData> parameterMetaData;
+
+ private Object[] parameterValues;
+
+ private String[] parameterTypes;
+
+ /** The required state of the dependency */
+ private final ControllerState dependentState;
+
+ /**
+ * Create a new ServiceInjectionValueMetaData.
+ *
+ * @param dependency the dependency
+ * @param method the property name
+ * @param dependentState the dependent state
+ */
+ @SuppressWarnings("unchecked")
+ public ServiceValueFactoryValueMetaData(Object dependency, String method, List<ServiceValueFactoryParameterMetaData> parameters, ControllerState dependentState, ServiceTextValueMetaData defaultValue)
+ {
+ if (dependency == null)
+ throw new IllegalArgumentException("Null dependency");
+ this.dependency = dependency;
+
+ if (method == null)
+ throw new IllegalArgumentException("Null method");
+ this.method = method;
+
+ this.parameterMetaData = (parameters == null ? Collections.EMPTY_LIST : parameters);
+
+ this.dependentState = (dependentState == null ? ControllerState.INSTALLED : dependentState);
+
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * Get the dependency.
+ *
+ * @return the dependency.
+ */
+ public Object getDependency()
+ {
+ return dependency;
+ }
+
+ /**
+ * Get the method.
+ *
+ * @return the method.
+ */
+ public String getMethod()
+ {
+ return method;
+ }
+
+ public List<ServiceValueFactoryParameterMetaData> getParameterMetaData()
+ {
+ return parameterMetaData;
+ }
+
+ /**
+ * Get the dependentState.
+ *
+ * @return the dependentState.
+ */
+ public ControllerState getDependentState()
+ {
+ return dependentState;
+ }
+
+ public ServiceTextValueMetaData getDefaultValue()
+ {
+ return defaultValue;
+ }
+
+ public Object getValue(ServiceValueContext valueContext) throws Throwable
+ {
+ KernelController controller = valueContext.getController();
+
+ ControllerState state = dependentState;
+ if (state == null)
+ state = ControllerState.INSTALLED;
+
+
+ ControllerContext factoryContext = controller.getContext(dependency, state);
+ if (factoryContext == null)
+ throw new Error("Should not be here - dependency failed! " + this);
+
+ Object result = null;
+
+ if (factoryContext instanceof InvokeDispatchContext)
+ {
+ InvokeDispatchContext idc = (InvokeDispatchContext) factoryContext;
+ result = idc.invoke(method, getParameterValues(valueContext, factoryContext), getParameterTypes(valueContext, factoryContext));
+ }
+ else
+ {
+ throw new IllegalArgumentException(
+ "Cannot use property attribute, context is not InvokeDispatchContext: " + factoryContext +
+ ", metadata: " + this);
+ }
+
+ if (result == null && this.defaultValue != null)
+ {
+ result = this.defaultValue.getValue(valueContext);
+ }
+
+ return result;
+ }
+
+ public void visit(ServiceMetaDataVisitor visitor)
+ {
+ ServiceControllerContext context = visitor.getControllerContext();
+ Object name = context.getName();
+ ControllerState whenRequired = visitor.getContextState();
+
+ DependencyItem item = new AbstractDependencyItem(name, dependency, whenRequired, dependentState);
+ visitor.addDependency(item);
+
+ visitor.visit(this);
+ }
+
+ private Object[] getParameterValues(ServiceValueContext valueContext, ControllerContext factoryContext) throws DeploymentException
+ {
+ if (parameterValues != null)
+ return parameterValues;
+
+ if (factoryContext instanceof KernelControllerContext)
+ {
+ analyzeParameters(valueContext, (KernelControllerContext) factoryContext);
+ }
+ else
+ {
+ extractParameters(valueContext);
+ }
+
+ return parameterValues;
+ }
+
+ private String[] getParameterTypes(ServiceValueContext valueContext, ControllerContext factoryContext) throws DeploymentException
+ {
+ if (parameterTypes != null)
+ return parameterTypes;
+
+ if (factoryContext instanceof KernelControllerContext)
+ analyzeParameters(valueContext, (KernelControllerContext) factoryContext);
+ else
+ extractParameters(valueContext);
+
+ return parameterTypes;
+ }
+
+ private void analyzeParameters(ServiceValueContext valueContext, KernelControllerContext factoryContext) throws DeploymentException
+ {
+ BeanInfo beanInfo = factoryContext.getBeanInfo();
+ Set<MethodInfo> allMethods = beanInfo.getMethods();
+
+ populateParameterTypes(allMethods, method, parameterMetaData);
+
+ parameterTypes = new String[parameterMetaData.size()];
+ parameterValues = new Object[parameterMetaData.size()];
+
+ for (int i = 0; i < parameterMetaData.size(); i++)
+ {
+ ServiceValueFactoryParameterMetaData metadata = parameterMetaData.get(i);
+ parameterTypes[i] = metadata.getParameterTypeName();
+ parameterValues[i] = metadata.getValue(valueContext);
+ }
+ }
+
+ private void extractParameters(ServiceValueContext valueContext) throws DeploymentException
+ {
+ parameterTypes = new String[parameterMetaData.size()];
+ parameterValues = new Object[parameterMetaData.size()];
+
+ for (int i = 0; i < parameterMetaData.size(); i++)
+ {
+ ServiceValueFactoryParameterMetaData metadata = parameterMetaData.get(i);
+ parameterTypes[i] = metadata.getParameterTypeName();
+ if (parameterTypes[i] == null)
+ {
+ parameterTypes = null;
+ parameterValues = null;
+ throw new IllegalStateException("No type available for parameter " + i
+ + " -- parameter types must be specified to invoke on mbeans");
+ }
+
+ parameterValues[i] = metadata.getValue(valueContext);
+
+ }
+ }
+
+ /**
+ * Attempts to find a method in <code>allMethods</code> whose name and parameters
+ * match the given arguments. If successful, modifies the {@link ServiceValueFactoryParameterMetaData}
+ * in the provided list to ensure any null parameterTypeName values are no longer null, but instead
+ * match the equivalent parameter in the MethodInfo.
+ * <p>
+ * If a given ServiceValueFactoryParameterMetaData has no parameterTypeName set, that is treated
+ * as meaning "matches any parameter type".
+ * </p>
+ *
+ * @param allMethods set of methods to match against
+ * @param methodName name of method to match
+ * @param parameterMetaData parameters to the method
+ *
+ * @throws IllegalArgumentException if less or more than one MethodInfo matches
+ */
+ public static void populateParameterTypes(Set<MethodInfo> allMethods, String methodName, List<ServiceValueFactoryParameterMetaData> parameterMetaData)
+ {
+ List<MethodInfo> possibleMatches = new ArrayList<MethodInfo>();
+ for (MethodInfo mi : allMethods)
+ {
+ TypeInfo[] typeInfos = mi.getParameterTypes();
+ if (methodName.equals(mi.getName()) && typeInfos.length == parameterMetaData.size())
+ {
+ boolean match = true;
+ for (int i = 0; i < typeInfos.length; i++)
+ {
+ String ourType = parameterMetaData.get(i).getParameterTypeName();
+ if (ourType != null && ourType.equals(typeInfos[i].getName()) == false)
+ {
+ match = false;
+ break;
+ }
+ }
+
+ if (match)
+ {
+ possibleMatches.add(mi);
+ }
+ }
+ }
+
+ if (possibleMatches.size() == 1)
+ {
+ MethodInfo match = possibleMatches.get(0);
+ TypeInfo[] types = match.getParameterTypes();
+ for (int i = 0; i < types.length; i++)
+ {
+ ServiceValueFactoryParameterMetaData metadata = parameterMetaData.get(i);
+ if (metadata.getParameterTypeName() == null)
+ {
+ metadata.setParameterTypeName(types[i].getName());
+ }
+ }
+ }
+ else if (possibleMatches.size() == 0)
+ {
+ throw new IllegalArgumentException("Cannot match parameters to any method.");
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot match parameters to a single method. Possible matches : " + possibleMatches);
+ }
+ }
+}
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/BasicValueFactory.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/BasicValueFactory.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/BasicValueFactory.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute"><value-factory bean="bean" method="method" parameter="parameter" default="default"/></attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/Minimal.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/Minimal.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/Minimal.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute"><value-factory bean="bean" method="method"/></attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NestedBean.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NestedBean.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NestedBean.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute">
+ <value-factory bean="bean" method="method" default="default">
+ <parameter>1</parameter>
+ <parameter><bean name="IllegalNestedBean" class="java.lang.Object"/></parameter>
+ </value-factory>
+ </attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NoDefault.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NoDefault.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NoDefault.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute"><value-factory bean="bean" method="method" parameter="parameter"/></attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NoParameter.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NoParameter.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NoParameter.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute"><value-factory bean="bean" method="method" default="default"/></attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NullParameter.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NullParameter.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/NullParameter.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute">
+ <value-factory bean="bean" method="method" default="default">
+ <parameter><null/>1</parameter>
+ <parameter>2</parameter>
+ </value-factory>
+ </attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/State.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/State.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/State.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute"><value-factory bean="bean" method="method" state="Create" parameter="parameter" default="default"/></attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/TypedParameters.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/TypedParameters.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/TypedParameters.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute">
+ <value-factory bean="bean" method="method" default="default">
+ <parameter class="java.lang.Integer">1</parameter>
+ <parameter class="java.lang.Long">2</parameter>
+ </value-factory>
+ </attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/TypedParametersWithValue.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/TypedParametersWithValue.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/TypedParametersWithValue.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute">
+ <value-factory bean="bean" method="method" default="default">
+ <parameter class="java.lang.Integer">1</parameter>
+ <parameter class="java.lang.Number"><value class="java.lang.Long">2</value></parameter>
+ </value-factory>
+ </attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/UntypedParameters.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/UntypedParameters.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/UntypedParameters.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute">
+ <value-factory bean="bean" method="method" default="default">
+ <parameter>1</parameter>
+ <parameter>2</parameter>
+ </value-factory>
+ </attribute>
+</mbean>
\ No newline at end of file
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/UntypedParametersWithValue.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/UntypedParametersWithValue.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/value/valuefactory/test/UntypedParametersWithValue.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <attribute name="Attribute">
+ <value-factory bean="bean" method="method" default="default">
+ <parameter>1</parameter>
+ <parameter><value class="java.lang.Long">2</value></parameter>
+ </value-factory>
+ </attribute>
+</mbean>
\ No newline at end of file
Modified: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/test/AbstractMetaDataTest.java
===================================================================
--- trunk/system-jmx/src/tests/org/jboss/test/system/metadata/test/AbstractMetaDataTest.java 2008-08-01 02:22:10 UTC (rev 76544)
+++ trunk/system-jmx/src/tests/org/jboss/test/system/metadata/test/AbstractMetaDataTest.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -44,6 +44,8 @@
import org.jboss.system.metadata.ServiceJavaBeanValueMetaData;
import org.jboss.system.metadata.ServiceMetaData;
import org.jboss.system.metadata.ServiceTextValueMetaData;
+import org.jboss.system.metadata.ServiceValueFactoryParameterMetaData;
+import org.jboss.system.metadata.ServiceValueFactoryValueMetaData;
import org.jboss.system.metadata.ServiceValueMetaData;
import org.jboss.test.AbstractSystemTest;
import org.jboss.test.AbstractTestDelegate;
@@ -424,6 +426,31 @@
assertEquals(requiredState, value.getDependentState());
}
+ protected void assertValueFactoryValue(ServiceValueMetaData actual, List<ServiceValueFactoryParameterMetaData> parameters, String defaultValue) throws Exception
+ {
+ assertValueFactoryValue(actual, "method", parameters, defaultValue, "bean", ControllerState.INSTALLED);
+ }
+
+ protected void assertValueFactoryValue(ServiceValueMetaData actual, List<ServiceValueFactoryParameterMetaData> parameters, String defaultValue, ControllerState state) throws Exception
+ {
+ assertValueFactoryValue(actual, "method", parameters, defaultValue, "bean", state);
+ }
+
+ protected void assertValueFactoryValue(ServiceValueMetaData actual, String method, List<ServiceValueFactoryParameterMetaData> parameters, String defaultValue, Object dependency, ControllerState requiredState) throws Exception
+ {
+ assertNotNull(actual);
+
+ ServiceValueFactoryValueMetaData value = assertInstanceOf(ServiceValueFactoryValueMetaData.class, actual);
+
+ assertEquals(method, value.getMethod());
+ assertEquals(dependency, value.getDependency());
+ assertEquals(requiredState, value.getDependentState());
+ ServiceTextValueMetaData defMetadata = value.getDefaultValue();
+ assertEquals(defaultValue, (defMetadata == null ? null : defMetadata.getText()));
+
+ assertEquals(parameters, value.getParameterMetaData());
+ }
+
protected void assertChildOfAttribute(Element element, String expected) throws Exception
{
assertNotNull(element);
Added: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/MockMethodInfo.java
===================================================================
--- trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/MockMethodInfo.java (rev 0)
+++ trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/MockMethodInfo.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,176 @@
+/*
+ * 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.test.system.metadata.value.valuefactory.test;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.reflect.spi.AnnotationValue;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.ParameterInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * A MockMethodInfo.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class MockMethodInfo implements MethodInfo
+{
+ private final String name;
+ private final TypeInfo[] parameterTypes;
+
+ public MockMethodInfo(String name, TypeInfo[] parameterTypes)
+ {
+ this.name = name;
+ this.parameterTypes = parameterTypes;
+ }
+
+ @Override
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw new Error("Can't clone", e);
+ }
+ }
+
+ public ClassInfo[] getExceptionTypes()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public TypeInfo[] getParameterTypes()
+ {
+ return parameterTypes;
+ }
+
+ public ParameterInfo[] getParameters()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public TypeInfo getReturnType()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object invoke(Object arg0, Object[] arg1) throws Throwable
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public AnnotationValue getAnnotation(String arg0)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public AnnotationValue[] getAnnotations()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T extends Annotation> T getUnderlyingAnnotation(Class<T> arg0)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Annotation[] getUnderlyingAnnotations()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isAnnotationPresent(String arg0)
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> arg0)
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String toShortString()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void toShortString(JBossStringBuilder buffer)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public ClassInfo getDeclaringClass()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getModifiers()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public boolean isPublic()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isStatic()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isVolatile()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
Added: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/MockTypeInfo.java
===================================================================
--- trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/MockTypeInfo.java (rev 0)
+++ trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/MockTypeInfo.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,157 @@
+/*
+ * 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.test.system.metadata.value.valuefactory.test;
+
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * A MockTypeInfo.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class MockTypeInfo implements TypeInfo
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ private final Class<?> clazz;
+
+ public MockTypeInfo(Class<?> clazz)
+ {
+ this.clazz = clazz;
+ }
+
+ public Object convertValue(Object obj) throws Throwable
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object convertValue(Object obj, boolean flag) throws Throwable
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object convertValue(Object obj, boolean flag, boolean flag1) throws Throwable
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public TypeInfo getArrayType()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getAttachment(String s)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T> T getAttachment(Class<T> arg0)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getName()
+ {
+ return clazz.getName();
+ }
+
+ public String getSimpleName()
+ {
+ return clazz.getSimpleName();
+ }
+
+ public Class<?> getType()
+ {
+ return clazz;
+ }
+
+ public TypeInfoFactory getTypeInfoFactory()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isAnnotation()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isArray()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isAssignableFrom(TypeInfo typeinfo)
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isCollection()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isEnum()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isMap()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isPrimitive()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Object newArrayInstance(int i) throws Throwable
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setAttachment(String s, Object obj)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ServiceValueFactoryParameterMetaDataUnitTestCase.java
===================================================================
--- trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ServiceValueFactoryParameterMetaDataUnitTestCase.java (rev 0)
+++ trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ServiceValueFactoryParameterMetaDataUnitTestCase.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,109 @@
+/*
+ * 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.test.system.metadata.value.valuefactory.test;
+
+import static org.jboss.system.metadata.ServiceValueFactoryParameterMetaData.getValue;
+
+import org.jboss.deployers.spi.DeploymentException;
+
+import junit.framework.TestCase;
+
+/**
+ * A ServiceValueFactoryParameterMetaDataUnitTestCase.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class ServiceValueFactoryParameterMetaDataUnitTestCase extends TestCase
+{
+ private static final String ONE = "1";
+ private static final String TRUE = "TRUE";
+ private static final String BOOL = "boolean";
+ private static final String BOOLEAN = "java.lang.Boolean";
+ private static final String INT = "int";
+ private static final String INTEGER = "java.lang.Integer";
+ private static final String STRING = "java.lang.String";
+ private static final String HASH_MAP = "java.util.HashMap";
+ private static final String ATTR = "Attr";
+
+ /**
+ * Create a new ServiceValueFactoryParameterMetaDataUnitTestCase.
+ *
+ * @param name
+ */
+ public ServiceValueFactoryParameterMetaDataUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetValueNull() throws Exception
+ {
+ assertNull(getValue(Thread.currentThread().getContextClassLoader(), null, STRING, ATTR));
+ }
+
+ public void testGetValueInt() throws Exception
+ {
+ assertEquals(1, getValue(Thread.currentThread().getContextClassLoader(), ONE, INT, ATTR));
+ }
+
+ public void testGetValueInteger() throws Exception
+ {
+ assertEquals(new Integer(1), getValue(Thread.currentThread().getContextClassLoader(), ONE, INTEGER, ATTR));
+ }
+
+ public void testGetValueBool() throws Exception
+ {
+ assertEquals(true, getValue(Thread.currentThread().getContextClassLoader(), TRUE, BOOL, ATTR));
+ }
+
+ public void testGetValueBoolean() throws Exception
+ {
+ assertEquals(Boolean.TRUE, getValue(Thread.currentThread().getContextClassLoader(), TRUE, BOOLEAN, ATTR));
+ }
+
+ public void testGetValueString() throws Exception
+ {
+ assertEquals(ONE, getValue(Thread.currentThread().getContextClassLoader(), ONE, STRING, ATTR));
+ }
+
+ public void testGetValueNoPropertyEditor()
+ {
+ try
+ {
+ getValue(Thread.currentThread().getContextClassLoader(), ONE, HASH_MAP, ATTR);
+ fail("Should not have a property editor for HashMap");
+ }
+ catch (DeploymentException expected) {}
+ }
+
+ public void testGetValueUnknownType()
+ {
+ try
+ {
+ getValue(Thread.currentThread().getContextClassLoader(), ONE, "com.foo.Bar", ATTR);
+ fail("Should not succeed with bogus type");
+ }
+ catch (DeploymentException expected) {}
+ }
+
+}
Added: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ValueFactoryParsingUnitTestCase.java
===================================================================
--- trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ValueFactoryParsingUnitTestCase.java (rev 0)
+++ trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ValueFactoryParsingUnitTestCase.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,140 @@
+/*
+* 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.system.metadata.value.valuefactory.test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.system.metadata.ServiceValueFactoryParameterMetaData;
+import org.jboss.system.metadata.ServiceValueMetaData;
+import org.jboss.test.system.metadata.value.AbstractValueTest;
+
+/**
+ * Tests handling of a value-factory element inside an attribute.
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 1.1 $
+ */
+public class ValueFactoryParsingUnitTestCase extends AbstractValueTest
+{
+ private static final String PARAMETER = "parameter";
+ private static final String DEFAULT = "default";
+ private static final String ONE = "1";
+ private static final String TWO = "2";
+ private static final String NUMBER = "java.lang.Number";
+ private static final String INTEGER = "java.lang.Integer";
+ private static final String LONG = "java.lang.Long";
+ private static final ServiceValueFactoryParameterMetaData PARAMETER_MD = new ServiceValueFactoryParameterMetaData(PARAMETER, null, null);
+ private static final List<ServiceValueFactoryParameterMetaData> SIMPLE_LIST = Arrays.asList(PARAMETER_MD);
+
+ public ValueFactoryParsingUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testBasicValueFactory() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ assertValueFactoryValue(value, SIMPLE_LIST, DEFAULT);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testMinimal() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ assertValueFactoryValue(value, Collections.EMPTY_LIST, null);
+ }
+
+ public void testNestedBean() throws Exception
+ {
+ try
+ {
+ unmarshallSingleValue();
+ fail("Should not be able to handle a nested bean element");
+ }
+ catch (DeploymentException expected) {}
+ }
+
+ public void testNoDefault() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ assertValueFactoryValue(value, SIMPLE_LIST, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testNoParameter() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ assertValueFactoryValue(value, Collections.EMPTY_LIST, DEFAULT);
+ }
+
+ public void testNullParameter() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(null, null, null);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, null, null);
+ assertValueFactoryValue(value, Arrays.asList(one, two), DEFAULT);
+ }
+
+ public void testState() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ assertValueFactoryValue(value, SIMPLE_LIST, DEFAULT, ControllerState.CREATE);
+ }
+
+ public void testTypedParameters() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, INTEGER, null);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, LONG, null);
+ assertValueFactoryValue(value, Arrays.asList(one, two), DEFAULT);
+ }
+
+ public void testTypedParametersWithValue() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, INTEGER, null);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, NUMBER, LONG);
+
+ assertValueFactoryValue(value, Arrays.asList(one, two), DEFAULT);
+ }
+
+ public void testUntypedParameters() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, null, null);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, null, null);
+ assertValueFactoryValue(value, Arrays.asList(one, two), DEFAULT);
+ }
+
+ public void testUntypedParametersWithValue() throws Exception
+ {
+ ServiceValueMetaData value = unmarshallSingleValue();
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, null, null);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, null, LONG);
+
+ assertValueFactoryValue(value, Arrays.asList(one, two), DEFAULT);
+ }
+}
Added: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ValueFactoryTypeAnalysisUnitTestCase.java
===================================================================
--- trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ValueFactoryTypeAnalysisUnitTestCase.java (rev 0)
+++ trunk/system-jmx/src/tests/org/jboss/test/system/metadata/value/valuefactory/test/ValueFactoryTypeAnalysisUnitTestCase.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,254 @@
+/*
+ * 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.test.system.metadata.value.valuefactory.test;
+
+import static org.jboss.system.metadata.ServiceValueFactoryValueMetaData.populateParameterTypes;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.system.metadata.ServiceValueFactoryParameterMetaData;
+import org.jboss.system.metadata.ServiceValueFactoryValueMetaData;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests of {@link ServiceValueFactoryValueMetaData#populateParameterTypes(java.util.Set, String, java.util.List)}.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class ValueFactoryTypeAnalysisUnitTestCase extends TestCase
+{
+ private static final String METHOD = "method";
+ private static final String OTHER_METHOD = "other";
+ private static final String ONE = "1";
+ private static final String TWO = "2";
+ private static final String INTEGER = "java.lang.Integer";
+ private static final String LONG = "java.lang.Long";
+ private static final TypeInfo OBJECT_TYPE = new MockTypeInfo(Object.class);
+ private static final TypeInfo STRING_TYPE = new MockTypeInfo(String.class);
+ private static final TypeInfo INTEGER_TYPE = new MockTypeInfo(Integer.class);
+ private static final TypeInfo LONG_TYPE = new MockTypeInfo(Long.class);
+
+ private Set<MethodInfo> allMethods = new HashSet<MethodInfo>();
+ /**
+ * Create a new ValueFactoryTypeAnalysisUnitTestCase.
+ *
+ * @param name
+ */
+ public ValueFactoryTypeAnalysisUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ allMethods.clear();
+
+ super.tearDown();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testNoArgsMatch()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[0]);
+ allMethods.add(mi);
+
+ populateParameterTypes(allMethods, METHOD, Collections.EMPTY_LIST);
+ }
+
+ public void testFullySpecifiedMatch()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE, LONG_TYPE } );
+ allMethods.add(mi);
+
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, INTEGER);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, LONG);
+ populateParameterTypes(allMethods, METHOD, Arrays.asList(one, two));
+
+ assertEquals(INTEGER, one.getParameterTypeName());
+ assertEquals(LONG, two.getParameterTypeName());
+ }
+
+ public void testPartialMatch()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE, LONG_TYPE } );
+ allMethods.add(mi);
+ mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE } );
+ allMethods.add(mi);
+
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, null);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, LONG);
+ populateParameterTypes(allMethods, METHOD, Arrays.asList(one, two));
+
+ assertEquals(INTEGER, one.getParameterTypeName());
+ assertEquals(LONG, two.getParameterTypeName());
+ }
+
+ public void testUnpecifiedMatch()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE, LONG_TYPE } );
+ allMethods.add(mi);
+ mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE } );
+ allMethods.add(mi);
+
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, null);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, null);
+ populateParameterTypes(allMethods, METHOD, Arrays.asList(one, two));
+
+ assertEquals(INTEGER, one.getParameterTypeName());
+ assertEquals(LONG, two.getParameterTypeName());
+ }
+
+ public void testFullySpecifiedMismatch()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE, INTEGER_TYPE } );
+ allMethods.add(mi);
+
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, INTEGER);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, LONG);
+
+ try
+ {
+ populateParameterTypes(allMethods, METHOD, Arrays.asList(one, two));
+ fail("Should have thrown exception due to mismatch");
+ }
+ catch (IllegalArgumentException good) {}
+ }
+
+ public void testPartialMismatch()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE, INTEGER_TYPE } );
+ allMethods.add(mi);
+
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, null);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, LONG);
+
+ try
+ {
+ populateParameterTypes(allMethods, METHOD, Arrays.asList(one, two));
+ fail("Should have thrown exception due to mismatch");
+ }
+ catch (IllegalArgumentException good) {}
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testNameMismatch()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[0]);
+ allMethods.add(mi);
+
+ try
+ {
+ populateParameterTypes(allMethods, OTHER_METHOD, Collections.EMPTY_LIST);
+ fail("Should have thrown exception due to mismatch");
+ }
+ catch (IllegalArgumentException good) {}
+ }
+
+ public void testZeroParamsToOneParam()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[0]);
+ allMethods.add(mi);
+
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE);
+
+ try
+ {
+ populateParameterTypes(allMethods, METHOD, Arrays.asList(one));
+ fail("Should have thrown exception due to mismatch");
+ }
+ catch (IllegalArgumentException good) {}
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testOneParamToZeroParams()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[] { OBJECT_TYPE });
+ allMethods.add(mi);
+
+ try
+ {
+ populateParameterTypes(allMethods, METHOD, Collections.EMPTY_LIST);
+ fail("Should have thrown exception due to mismatch");
+ }
+ catch (IllegalArgumentException good) {}
+ }
+
+ public void testTwoParamsToOneParam()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE, LONG_TYPE } );
+ allMethods.add(mi);
+
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, INTEGER);
+
+ try
+ {
+ populateParameterTypes(allMethods, METHOD, Arrays.asList(one));
+ fail("Should have thrown exception due to mismatch");
+ }
+ catch (IllegalArgumentException good) {}
+ }
+
+ public void testOneParamToTwoParams()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[] { INTEGER_TYPE });
+ allMethods.add(mi);
+
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, INTEGER);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, INTEGER);
+
+ try
+ {
+ populateParameterTypes(allMethods, METHOD, Arrays.asList(one, two));
+ fail("Should have thrown exception due to mismatch");
+ }
+ catch (IllegalArgumentException good) {}
+ }
+
+ public void testDoubleMatch()
+ {
+ MethodInfo mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE, LONG_TYPE } );
+ allMethods.add(mi);
+ mi = new MockMethodInfo(METHOD, new TypeInfo[]{ INTEGER_TYPE, STRING_TYPE } );
+ allMethods.add(mi);
+
+ ServiceValueFactoryParameterMetaData one = new ServiceValueFactoryParameterMetaData(ONE, null);
+ ServiceValueFactoryParameterMetaData two = new ServiceValueFactoryParameterMetaData(TWO, null);
+
+ try
+ {
+ populateParameterTypes(allMethods, METHOD, Arrays.asList(one, two));
+ fail("Should have thrown exception due to mismatch");
+ }
+ catch (IllegalArgumentException good) {}
+ }
+
+}
Modified: trunk/testsuite/imports/sections/deployers.xml
===================================================================
--- trunk/testsuite/imports/sections/deployers.xml 2008-08-01 02:22:10 UTC (rev 76544)
+++ trunk/testsuite/imports/sections/deployers.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -174,6 +174,19 @@
<copy todir="${build.lib}/unpacked-mbean1-not.asar">
<fileset dir="${build.lib}/unpacked-mbean1.sar"/>
</copy>
+
+ <!-- JBAS-5822 -->
+ <jar destfile="${build.lib}/testdeployers-valuefactory.sar">
+ <metainf dir="${build.resources}/deployers/valuefactory">
+ <include name="jboss-beans.xml"/>
+ </metainf>
+ <fileset dir="${build.resources}/deployers/valuefactory">
+ <include name="*-service.xml"/>
+ </fileset>
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/test/deployers/valuefactory/**"/>
+ </fileset>
+ </jar>
<!-- EAR -->
<jar destfile="${build.lib}/testdeployers-ear1.ear">
Added: trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean1.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean1.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean1.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,46 @@
+/*
+ * 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.test.deployers.valuefactory;
+
+/**
+ * A MBean1.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class MBean1 implements MBean1MBean
+{
+ public int add(int a, Integer b)
+ {
+ int result = a;
+ if (b != null)
+ result += b.intValue();
+
+ return result;
+ }
+
+ public Integer noReturn()
+ {
+ return null;
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean1MBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean1MBean.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean1MBean.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,8 @@
+package org.jboss.test.deployers.valuefactory;
+
+public interface MBean1MBean
+{
+
+ int add(int a, Integer b);
+ Integer noReturn();
+}
\ No newline at end of file
Added: trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean2.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean2.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean2.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,64 @@
+/*
+ * 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.test.deployers.valuefactory;
+
+/**
+ * A MBean2.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class MBean2 implements MBean2MBean
+{
+ private int fromMBean;
+ private int fromPojo;
+ private int fromDefault;
+
+ public int getFromMBean()
+ {
+ return fromMBean;
+ }
+ public void setFromMBean(int fromMBean)
+ {
+ this.fromMBean = fromMBean;
+ }
+
+ public int getFromPojo()
+ {
+ return fromPojo;
+ }
+ public void setFromPojo(int fromPojo)
+ {
+ this.fromPojo = fromPojo;
+ }
+
+ public int getFromDefault()
+ {
+ return fromDefault;
+ }
+ public void setFromDefault(int fromDefault)
+ {
+ this.fromDefault = fromDefault;
+ }
+
+}
Added: trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean2MBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean2MBean.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/MBean2MBean.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,18 @@
+package org.jboss.test.deployers.valuefactory;
+
+public interface MBean2MBean
+{
+
+ public abstract int getFromMBean();
+
+ public abstract void setFromMBean(int fromMBean);
+
+ public abstract int getFromPojo();
+
+ public abstract void setFromPojo(int fromPojo);
+
+ public abstract int getFromDefault();
+
+ public abstract void setFromDefault(int fromDefault);
+
+}
\ No newline at end of file
Added: trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/test/ValueFactoryInjectionUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/test/ValueFactoryInjectionUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/deployers/valuefactory/test/ValueFactoryInjectionUnitTestCase.java 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,66 @@
+/*
+ * 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.deployers.valuefactory.test;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+
+/**
+ * A test that deploys app sars.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 58276 $
+ */
+public class ValueFactoryInjectionUnitTestCase extends JBossTestCase
+{
+ private static final String valueFactoryDeployment = "testdeployers-valuefactory.sar";
+ private static final String targetObject = "jboss.test:service=ValueFactoryInjectionTestTarget";
+
+ public ValueFactoryInjectionUnitTestCase(String test)
+ {
+ super(test);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(ValueFactoryInjectionUnitTestCase.class, valueFactoryDeployment);
+ }
+
+ public void testValueFactoryInjection() throws Exception
+ {
+ ObjectName oname = new ObjectName(targetObject);
+ MBeanServerConnection adaptor = this.getServer();
+ Integer val = (Integer) adaptor.getAttribute(oname, "FromPojo");
+ assertNotNull(val);
+ assertEquals(3, val.intValue());
+ val = (Integer) adaptor.getAttribute(oname, "FromMBean");
+ assertNotNull(val);
+ assertEquals(7, val.intValue());
+ val = (Integer) adaptor.getAttribute(oname, "FromDefault");
+ assertNotNull(val);
+ assertEquals(5, val.intValue());
+ }
+}
Added: trunk/testsuite/src/resources/deployers/valuefactory/jboss-beans.xml
===================================================================
--- trunk/testsuite/src/resources/deployers/valuefactory/jboss-beans.xml (rev 0)
+++ trunk/testsuite/src/resources/deployers/valuefactory/jboss-beans.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="ValueFactoryInjectionTestSource" class="org.jboss.test.deployers.valuefactory.MBean1"/>
+</deployment>
\ No newline at end of file
Added: trunk/testsuite/src/resources/deployers/valuefactory/valuefactory-service.xml
===================================================================
--- trunk/testsuite/src/resources/deployers/valuefactory/valuefactory-service.xml (rev 0)
+++ trunk/testsuite/src/resources/deployers/valuefactory/valuefactory-service.xml 2008-08-01 03:14:08 UTC (rev 76545)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+
+ <mbean code="org.jboss.test.deployers.valuefactory.MBean1"
+ name="jboss.test:service=ValueFactoryInjectionTestSource"/>
+
+ <mbean code="org.jboss.test.deployers.valuefactory.MBean2"
+ name="jboss.test:service=ValueFactoryInjectionTestTarget">
+
+ <attribute name="FromPojo">
+ <value-factory bean="ValueFactoryInjectionTestSource" method="add">
+ <parameter>1</parameter>
+ <parameter>2</parameter>
+ </value-factory>
+ </attribute>
+
+ <attribute name="FromMBean">
+ <value-factory bean="jboss.test:service=ValueFactoryInjectionTestSource" method="add">
+ <parameter class="int">3</parameter>
+ <parameter class="java.lang.Integer">4</parameter>
+ </value-factory>
+ </attribute>
+
+ <attribute name="FromDefault">
+ <value-factory bean="ValueFactoryInjectionTestSource" method="noReturn" default="5"/>
+ </attribute>
+
+ </mbean>
+
+</server>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list