[jboss-svn-commits] JBL Code SVN: r22793 - in labs/jbossesb/workspace/skeagh: routing/jms/src/test/java/org/jboss/esb/jms and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Sep 16 02:24:31 EDT 2008
Author: beve
Date: 2008-09-16 02:24:31 -0400 (Tue, 16 Sep 2008)
New Revision: 22793
Added:
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/FieldListAccessor.java
Modified:
labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/CreateObject.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/AnnotatedResource.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/MyInRouter.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/MyMessageTransformer.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/digest/SetPropertyTest.java
Log:
Fixed the Annotations issue.
Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java 2008-09-16 05:20:12 UTC (rev 22792)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java 2008-09-16 06:24:31 UTC (rev 22793)
@@ -20,23 +20,25 @@
*/
package org.jboss.esb.jms;
+import static org.jboss.esb.jms.JmsConstants.CONNECTION_FACTORY;
+
+import java.util.Properties;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.naming.Context;
+
import org.apache.log4j.Logger;
import org.jboss.esb.annotations.Initialize;
import org.jboss.esb.annotations.Property;
+import org.jboss.esb.annotations.Uninitialize;
import org.jboss.esb.annotations.Property.Use;
-import org.jboss.esb.annotations.Uninitialize;
import org.jboss.esb.context.InvocationContext;
-import static org.jboss.esb.jms.JmsConstants.CONNECTION_FACTORY;
import org.jboss.esb.message.Message;
import org.jboss.esb.routing.InboundRouter;
import org.jboss.esb.routing.MessageDispatcher;
import org.jboss.esb.routing.RoutingException;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.naming.Context;
-import java.util.Properties;
-
/**
* Inbound router for JMS.
*
@@ -71,6 +73,7 @@
*/
@Property(use = Use.OPTIONAL, defaultVal = "true")
private boolean extractProperties;
+
/**
* The JMS Session on which the listener is created.
*/
Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml 2008-09-16 05:20:12 UTC (rev 22792)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml 2008-09-16 06:24:31 UTC (rev 22793)
@@ -7,6 +7,7 @@
<property name="java.naming.provider.url">tcp://localhost:61717</property>
<property name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</property>
<property name="jmsDestination">jbossesb.TestQueue</property>
+ <property name="extractProperties">true</property>
<property name="queue.jbossesb.TestQueue">jbossesb.TestQueue</property>
</inRouter>
Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/CreateObject.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/CreateObject.java 2008-09-16 05:20:12 UTC (rev 22792)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/CreateObject.java 2008-09-16 06:24:31 UTC (rev 22793)
@@ -19,7 +19,15 @@
*/
package org.jboss.esb.deploy.config.digest;
-import org.jboss.esb.annotations.AnnotationConstants;
+import static org.jboss.esb.annotations.AnnotationConstants.UNASSIGNED;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
import org.jboss.esb.annotations.Property;
import org.jboss.esb.annotations.Property.Use;
import org.jboss.esb.classpath.ClassUtil;
@@ -34,15 +42,7 @@
import org.milyn.javabean.repository.BeanRepositoryManager;
import org.milyn.xml.DomUtils;
import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
/**
* Create an object and set it in the Smooks bean repository.
*
@@ -50,6 +50,8 @@
*/
public class CreateObject implements DOMVisitBefore, DOMVisitAfter
{
+ private Logger log = Logger.getLogger(CreateObject.class);
+
/**
* The name of the class.
*/
@@ -153,6 +155,8 @@
// Store the bean in the Smooks bean repository...
BeanRepositoryManager.getBeanRepository(executionContext).addBean(beanId, objectInstance);
+
+ FieldListAccessor.set(executionContext, beanId, new ArrayList<Field>());
}
finally
{
@@ -177,83 +181,95 @@
public final void visitAfter(final Element element, final ExecutionContext executionContext) throws SmooksException
{
final Object bean = BeanRepositoryManager.getBeanRepository(executionContext).getBean(beanId);
- final NodeList childNodes = element.getChildNodes();
- final int length = childNodes.getLength();
- final Map<String, String> propertiesMap = new HashMap<String, String>(length);
-
- for (int i = 0; i < length; i++)
+ List<Field> setFields = FieldListAccessor.get(executionContext, beanId);
+ try
{
- final Node node = childNodes.item(i);
- if (node.getNodeName().equals("property"))
- {
- propertiesMap.put(node.getAttributes().getNamedItem("name").getNodeValue(), node.getTextContent());
- }
+ checkFieldAnnoations(bean.getClass(), bean, setFields);
}
- checkFieldAnnoations(bean.getClass(), bean, propertiesMap);
+ finally
+ {
+ FieldListAccessor.remove(executionContext, beanId);
+ }
}
/**
* Check field annotations.
- *
- * @param hierarchyClass The Class hierarchy level to be checked.
- * @param instance The object instance.
- * @param properties The config properties.
+ * <p/>
+ * @param hierarchyClass The Class hierarchy level to be checked
+ * @param instance The object instance
+ * @param properties The config properties
+ * @param setFields List containing the fields that have been set(that existed in the config)
*/
- final void checkFieldAnnoations(final Class hierarchyClass, final Object instance, final Map<String, String> properties)
+ final void checkFieldAnnoations(final Class<?> hierarchyClass, final Object instance, final List<Field> setFields)
{
- final Set<String> propertyNameInConfig = properties.keySet();
final Class<?> superclass = hierarchyClass.getSuperclass();
if (superclass != null)
{
- checkFieldAnnoations(superclass, instance, properties);
+ checkFieldAnnoations(superclass, instance, setFields);
}
for (Field field : hierarchyClass.getDeclaredFields())
{
final Property annotation = field.getAnnotation(Property.class);
-
- // check if the fields has an annotation
if (annotation != null)
{
- // isf'name' attribute was specified use it, otherwise use the name of the field in the class.
- final String configPropertyName = AnnotationConstants.NULL_STRING.equals(annotation.name()) ? field.getName() : annotation.name();
-
- // is 'use=Required' and the field name was specified as a property in the the configuration
- if (annotation.use() == Use.REQUIRED && !propertyNameInConfig.contains(configPropertyName))
+ final boolean wasInConfig = setFields.contains(field);
+ if (annotation.use() == Use.REQUIRED && !wasInConfig)
{
+ throw new SmooksException("Configuration property '" + field.getName() + " was annotated as required but not specified in configuration file for bean: " + instance.getClass().getName());
+ }
+ // set optional 'defaultVal' value if one was specified on the annotation
+ else if (annotation.use() == Use.OPTIONAL && !wasInConfig && !annotation.defaultVal().equals(UNASSIGNED))
+ {
try
{
- // get the value of the field
- Object fieldValue = ClassUtil.getFieldValue(field, instance);
-
- if (fieldValue == null || fieldValue.equals(false))
- {
- throw new SmooksException("Configuration property '" + field.getName() + " was annotated as required but not specified in configuration file or given a 'defaultVal for bean: " + instance.getClass().getName());
- }
+ DataDecoder decoder = DataDecoder.Factory.create(field.getType());
+ Object objValue = decoder.decode(annotation.defaultVal());
+ ClassUtil.setFieldValue(field, instance, objValue);
}
- catch (IllegalAccessException e)
+ catch (final IllegalAccessException e)
{
throw new SmooksException("IllegalAccessException while trying to access field '" + field.getName() + "' on class '" + instance.getClass().getName() + "'", e);
}
}
- else if (annotation.use() == Use.OPTIONAL && !propertyNameInConfig.contains(configPropertyName))
+ }
+
+ org.jboss.esb.annotations.Properties propertiesAnno = field.getAnnotation(org.jboss.esb.annotations.Properties.class);
+ if (propertiesAnno != null)
+ {
+ removeFieldFromPropertiesField(instance, field, setFields);
+ }
+ }
+ }
+
+ /**
+ * Removes all the fieds that exist in the passed in setFields parameter.
+ * <p/>
+ * @param instance - the instance where the propretiesField exists.
+ * @param propertiesField - the properties field itself
+ * @param setFields - the list of field that are to be removed
+ */
+ private void removeFieldFromPropertiesField(final Object instance, final Field propertiesField, final List<Field> setFields)
+ {
+ try
+ {
+ if (Properties.class.isAssignableFrom(propertiesField.getType()))
+ {
+ final Properties properties = (Properties) ClassUtil.getFieldValue(propertiesField, instance);
+ if (properties != null)
{
- try
+ for (final Field field : setFields)
{
- if (!annotation.defaultVal().equals(AnnotationConstants.UNASSIGNED))
- {
- DataDecoder decoder = DataDecoder.Factory.create(field.getType());
- Object objValue = decoder.decode(annotation.defaultVal());
-
- ClassUtil.setFieldValue(field, instance, objValue);
- }
+ properties.remove(field.getName());
}
- catch (final IllegalAccessException e)
- {
- throw new SmooksException("IllegalAccessException while trying to access field '" + field.getName() + "' on class '" + instance.getClass().getName() + "'", e);
- }
+ // now set the properties instance on the calass
+ ClassUtil.setFieldValue(propertiesField, instance, properties);
}
}
}
+ catch (IllegalAccessException ignored)
+ {
+ log.error(ignored.getMessage(), ignored);
+ }
}
}
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/FieldListAccessor.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/FieldListAccessor.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/FieldListAccessor.java 2008-09-16 06:24:31 UTC (rev 22793)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.deploy.config.digest;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import org.jboss.esb.util.AssertArgument;
+import org.milyn.container.ExecutionContext;
+
+/**
+ * Helper class to access the list of Fields that have been
+ * configured.
+ *
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public final class FieldListAccessor
+{
+ private static final String PROPERTIES_KEY = "#properties:";
+
+ private FieldListAccessor()
+ {
+ }
+
+ /**
+ * Gets the list of fields for the specified beanId.
+ *
+ * @param executionContext - the Smooks execution context
+ * @param beanId - the beanId to look up
+ * @return List<Field> - a list of fields. The fields being the fields found in a configuration file
+ */
+ @SuppressWarnings("unchecked")
+ public static List<Field> get(final ExecutionContext executionContext, final String beanId)
+ {
+ AssertArgument.isNotNull(executionContext, "executionContext");
+ AssertArgument.isNotNull(beanId, "beanId");
+
+ return (List<Field>)executionContext.getAttribute(PROPERTIES_KEY + beanId);
+ }
+
+ /**
+ * Sets the list on the ExecutionContext using the beanId as an index.
+ *
+ * @param executionContext - the Smooks execution context
+ * @param beanId - the beanId to look up
+ * @param list - the list to set
+ */
+ public static void set(final ExecutionContext executionContext, final String beanId, final List<Field> list)
+ {
+ AssertArgument.isNotNull(executionContext, "executionContext");
+ AssertArgument.isNotNull(beanId, "beanId");
+ AssertArgument.isNotNull(list, "list");
+
+ executionContext.setAttribute(PROPERTIES_KEY + beanId, list);
+ }
+
+ /**
+ * Removes the list associated with the passed in beanId
+ * @param executionContext - the Smooks execution context
+ * @param beanId - the beanId to look up
+ */
+ public static void remove(final ExecutionContext executionContext, final String beanId)
+ {
+ AssertArgument.isNotNull(executionContext, "executionContext");
+ AssertArgument.isNotNull(beanId, "beanId");
+
+ executionContext.removeAttribute(PROPERTIES_KEY + beanId);
+ }
+
+}
Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java 2008-09-16 05:20:12 UTC (rev 22792)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java 2008-09-16 06:24:31 UTC (rev 22793)
@@ -19,6 +19,12 @@
*/
package org.jboss.esb.deploy.config.digest;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
import org.jboss.esb.annotations.AnnotationConstants;
import org.jboss.esb.annotations.Property;
import org.jboss.esb.classpath.ClassUtil;
@@ -31,11 +37,6 @@
import org.milyn.xml.DomUtils;
import org.w3c.dom.Element;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Properties;
-
/**
* Set the value of a property of a bean (from the Smooks bean repository).
*
@@ -93,7 +94,8 @@
{
try
{
- attemptAnnotationFieldSet(objectClass, instance, propertyName, value);
+ List<Field> fieldsList = FieldListAccessor.get(executionContext, beanId);
+ attemptAnnotationFieldSet(objectClass, instance, propertyName, value, fieldsList);
}
catch (final IllegalAccessException e)
{
@@ -112,18 +114,22 @@
* @param value the value to set the field to
* @throws IllegalAccessException if the field was not accessible.
*/
- final void attemptAnnotationFieldSet(final Class<?> clazz, final Object instance, final String configPropertyName, final String value) throws IllegalAccessException
+ final void attemptAnnotationFieldSet(
+ final Class<?> clazz,
+ final Object instance,
+ final String configPropertyName,
+ final String value,
+ final List<Field> fieldsList) throws IllegalAccessException
{
final Class<?> superclass = clazz.getSuperclass();
if (superclass != null)
{
- attemptAnnotationFieldSet(superclass, instance, configPropertyName, value);
+ attemptAnnotationFieldSet(superclass, instance, configPropertyName, value, fieldsList);
}
for (Field field : clazz.getDeclaredFields())
{
Property propertyAnno = field.getAnnotation(Property.class);
- org.jboss.esb.annotations.Properties propertiesAnno = field.getAnnotation(org.jboss.esb.annotations.Properties.class);
if (propertyAnno != null)
{
@@ -131,15 +137,17 @@
if (fieldName.equals(configPropertyName))
{
+ fieldsList.add(field);
assertValidChoice(propertyAnno.choice(), configPropertyName, value);
- setPropertyValue(field, instance, (value == null ? propertyAnno.defaultVal() : value));
+ setPropertyValue(field, instance, value == null ? propertyAnno.defaultVal() : value);
break;
}
}
- else if (propertiesAnno != null)
+
+ org.jboss.esb.annotations.Properties propertiesAnno = field.getAnnotation(org.jboss.esb.annotations.Properties.class);
+ if (propertiesAnno != null && !fieldsList.contains(field))
{
attemptPropertiesFieldSet(instance, field, configPropertyName, value);
- break;
}
}
}
Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/AnnotatedResource.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/AnnotatedResource.java 2008-09-16 05:20:12 UTC (rev 22792)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/AnnotatedResource.java 2008-09-16 06:24:31 UTC (rev 22793)
@@ -57,7 +57,7 @@
private String org;
@Property ( use = Use.OPTIONAL, defaultVal = "11" )
- private String id;
+ private int id;
public String getOrganization()
{
@@ -99,7 +99,7 @@
return password;
}
- public String getId()
+ public int getId()
{
return id;
}
Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java 2008-09-16 05:20:12 UTC (rev 22792)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java 2008-09-16 06:24:31 UTC (rev 22793)
@@ -19,23 +19,26 @@
*/
package org.jboss.esb.deploy.config;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
import org.jboss.esb.deploy.DeploymentException;
import org.jboss.esb.deploy.config.digest.DefaultConfigurationDigester;
import org.jboss.esb.deploy.config.digest.DigestUtil;
-import org.jboss.esb.service.ServiceName;
import org.jboss.esb.message.MessageTransformer;
+import org.jboss.esb.service.ServiceName;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.milyn.SmooksException;
-import java.io.IOException;
-import java.util.Map;
-import java.util.List;
-import java.net.URI;
-
/**
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
*/
@@ -50,7 +53,6 @@
}
@Test
- @Ignore
public void test_resources_01() throws IOException, DeploymentException
{
DeploymentUnit configUnit = digest("jbossesb-resources_01.xml");
@@ -64,21 +66,18 @@
}
@Test
- @Ignore
public void test_inrouters_01() throws IOException, DeploymentException
{
test_inrouters("jbossesb-inrouters_01.xml");
}
@Test
- @Ignore
public void test_outrouters_01() throws IOException, DeploymentException
{
test_outrouters("jbossesb-outrouters_01.xml");
}
@Test
- @Ignore
public void test_inandoutrouters_01() throws IOException, DeploymentException
{
DeploymentUnit configUnit = digest("jbossesb-inandoutrouters_01.xml");
@@ -185,7 +184,6 @@
}
@Test
- @Ignore
public void test_services_01() throws DeploymentException, IOException
{
DeploymentUnit configUnit = digest("jbossesb-services_01.xml");
@@ -219,6 +217,7 @@
assertEquals("Name should have been set.", "Austin", res.getName());
assertEquals("Age should have been set.", 44, res.getAge());
assertTrue("Weight should have been set.", 83.2 == res.getWeight());
+ assertEquals("Id should have been set to its defaultVal.", 11, res.getId());
assertEquals(false, res.isVisible());
}
Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/MyInRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/MyInRouter.java 2008-09-16 05:20:12 UTC (rev 22792)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/MyInRouter.java 2008-09-16 06:24:31 UTC (rev 22793)
@@ -35,7 +35,7 @@
{
private ServiceName serviceName;
- @Property (use = Use.OPTIONAL )
+ @Property (use = Use.OPTIONAL, defaultVal = "1" )
private String myparam;
@Property (use = Use.OPTIONAL )
Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/MyMessageTransformer.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/MyMessageTransformer.java 2008-09-16 05:20:12 UTC (rev 22792)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/MyMessageTransformer.java 2008-09-16 06:24:31 UTC (rev 22793)
@@ -25,6 +25,7 @@
import org.jboss.esb.annotations.Initialize;
import org.jboss.esb.annotations.Property;
import org.jboss.esb.annotations.Uninitialize;
+import org.jboss.esb.annotations.Property.Use;
import org.jboss.esb.context.AddressingContext;
import org.jboss.esb.service.ServiceName;
import junit.framework.TestCase;
@@ -36,7 +37,7 @@
{
private ServiceName serviceName;
- @Property
+ @Property ( use = Use.OPTIONAL)
private int someParam;
public static boolean initialised = false;
Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/digest/SetPropertyTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/digest/SetPropertyTest.java 2008-09-16 05:20:12 UTC (rev 22792)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/digest/SetPropertyTest.java 2008-09-16 06:24:31 UTC (rev 22793)
@@ -24,6 +24,10 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
import org.jboss.esb.deploy.config.AnnotatedResource;
import org.jboss.esb.deploy.config.AnnotatedTestPropertiesResource;
import org.jboss.esb.deploy.config.AnnotatedTestPropertiesResource2;
@@ -39,13 +43,14 @@
public class SetPropertyTest
{
private final SetProperty setProperty = new SetProperty();
+ private final List<Field> fieldsSet = new ArrayList<Field>();
@Test
public void attemptAnnotationFieldSet() throws IllegalAccessException
{
final AnnotatedResource annotatedResource = new AnnotatedResource();
final String expectedName = "Fletcher";
- setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "lastName", expectedName);
+ setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "lastName", expectedName, fieldsSet);
assertEquals( expectedName, annotatedResource.getLastName());
}
@@ -54,7 +59,7 @@
{
final AnnotatedResource annotatedResource = new AnnotatedResource();
final String expectedName = "Dr.Rosen";
- setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "userName", expectedName);
+ setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "userName", expectedName, fieldsSet);
assertEquals( expectedName, annotatedResource.getName() );
}
@@ -62,7 +67,7 @@
public void attemptAnnotationFieldSetNotAnnotated() throws IllegalAccessException
{
final AnnotatedResource annotatedResource = new AnnotatedResource();
- setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "password", "secret");
+ setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "password", "secret", fieldsSet);
assertNull("password is not annotated and should not have been set", annotatedResource.getPassword() );
}
@@ -76,9 +81,9 @@
final String propValue2 = "value2";
final String expectedName = "Dr.Rosen";
- setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , "userName", expectedName);
- setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey1, propValue1);
- setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey2, propValue2);
+ setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , "userName", expectedName, fieldsSet);
+ setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey1, propValue1, fieldsSet);
+ setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey2, propValue2, fieldsSet);
assertTrue(pojo.getProps().size() == 2 );
assertTrue("Properties did not contain key: " + propKey1, pojo.getProps().containsKey(propKey1));
@@ -98,9 +103,9 @@
final String propValue2 = "value2";
final String expectedName = "Dr.Rosen";
- setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , "userName", expectedName);
- setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey1, propValue1);
- setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey2, propValue2);
+ setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , "userName", expectedName, fieldsSet);
+ setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey1, propValue1, fieldsSet);
+ setProperty.attemptAnnotationFieldSet(pojo.getClass(), pojo , propKey2, propValue2, fieldsSet);
assertTrue(pojo.getProperties().size() == 2 );
assertTrue("Properties did not contain key: " + propKey1, pojo.getProperties().containsKey(propKey1));
@@ -115,7 +120,7 @@
{
final AnnotatedResource annotatedResource = new AnnotatedResource();
final String httpTransport = "Http";
- setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "transport", httpTransport);
+ setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "transport", httpTransport, fieldsSet);
assertEquals(httpTransport, annotatedResource.getTransport());
}
@@ -123,22 +128,22 @@
public void shouldThrowIfInvalidChoice() throws IllegalAccessException
{
final AnnotatedResource annotatedResource = new AnnotatedResource();
- setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "transport", "InvalidTransport");
+ setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "transport", "InvalidTransport", fieldsSet);
}
@Test
public void attemptAnnotationFieldSetWithDefaultValue() throws IllegalAccessException
{
final AnnotatedResource annotatedResource = new AnnotatedResource();
- setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "id", null);
- assertEquals("11", annotatedResource.getId() );
+ setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "id", null, fieldsSet);
+ assertEquals(11, annotatedResource.getId() );
}
@Test
public void attemptAnnotationFieldSetWithBooleanDefaultValue() throws IllegalAccessException
{
final AnnotatedResource annotatedResource = new AnnotatedResource();
- setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "visible2", null);
+ setProperty.attemptAnnotationFieldSet(annotatedResource.getClass(), annotatedResource , "visible2", null, fieldsSet);
assertEquals(true, annotatedResource.isVisible2());
}
More information about the jboss-svn-commits
mailing list