[jboss-svn-commits] JBL Code SVN: r22430 - 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
Fri Sep 5 05:58:25 EDT 2008
Author: beve
Date: 2008-09-05 05:58:25 -0400 (Fri, 05 Sep 2008)
New Revision: 22430
Added:
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/digest/
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/jbossesb-resources_02.xml
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/JmsInboundRouterTest.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/SetProperty.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java
Log:
Added ConfigParam annotation setter to SetProperty. This currently only does field setting and does not support setting through setter method.
Checking into to share the code and discuss.
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-05 05:20:25 UTC (rev 22429)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java 2008-09-05 09:58:25 UTC (rev 22430)
@@ -59,7 +59,7 @@
/**
* JMS destination name.
*/
- @ConfigParam(use = Use.REQUIRED)
+ @ConfigParam(use = Use.REQUIRED, name = "jmsDestination")
private String destination;
/**
@@ -119,6 +119,11 @@
this.dispatcher = dispatcher;
}
+ public String getDestination()
+ {
+ return destination;
+ }
+
/**
* Will display the dispatcher and the properties for this instance.
* @return String - string representation of this instance.
Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java 2008-09-05 05:20:25 UTC (rev 22429)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java 2008-09-05 09:58:25 UTC (rev 22430)
@@ -72,9 +72,11 @@
assertTrue(inboundRouter instanceof JmsInboundRouter);
initialize();
- final Properties properties = ((JmsInboundRouter) inboundRouter) .getProperties();
+ JmsInboundRouter jmsRouter = (JmsInboundRouter) inboundRouter;
+ final Properties properties = jmsRouter.getProperties();
assertTrue(properties.containsKey(Context.PROVIDER_URL));
assertEquals("localhost:8080", properties.get(Context.PROVIDER_URL));
+ assertEquals("queue/A", jmsRouter.getDestination());
}
private void initialize() throws DeploymentException, IOException
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-05 05:20:25 UTC (rev 22429)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml 2008-09-05 09:58:25 UTC (rev 22430)
@@ -5,7 +5,7 @@
<inRouter name="inrouter1" class="org.jboss.esb.jms.JmsInboundRouter">
<property name="java.naming.provider.url">localhost:8080</property>
- <property name="destination">queue/A</property>
+ <property name="jmsDestination">queue/A</property>
</inRouter>
<inRouter name="noproperties" class="org.jboss.esb.jms.JmsInboundRouter">
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-05 05:20:25 UTC (rev 22429)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java 2008-09-05 09:58:25 UTC (rev 22430)
@@ -87,8 +87,11 @@
{
try
{
- Field field = getPropertyField(propertyName, objectClass);
- setPropertyValue(field, instance, value);
+ if ( !attemptAnnotationFieldSet(instance, propertyName, value) )
+ {
+ Field field = getPropertyField(propertyName, objectClass);
+ setPropertyValue(field, instance, value);
+ }
} catch (NoSuchFieldException e)
{
if (!attemptPropertiesFieldSet(instance, propertyName, value))
@@ -96,13 +99,34 @@
// Throw the original exception...
throw new SmooksException("Property '" + propertyName + "' unknown on class '" + objectClass + "' (or super class).", e);
}
- } catch (IllegalAccessException e)
+ }
+ catch (IllegalAccessException e)
{
throw new SmooksException("Property '" + propertyName + "' cannot be set on class '" + objectClass + "'.", e);
}
}
}
+ boolean attemptAnnotationFieldSet(final Object instance, final String propertyName, final String value) throws IllegalAccessException
+ {
+ boolean fieldSet = false;
+ Field[] fields = instance.getClass().getDeclaredFields();
+ for (Field field : fields)
+ {
+ org.jboss.esb.annotation.ConfigParam configParam = field.getAnnotation(org.jboss.esb.annotation.ConfigParam.class);
+ if ( configParam != null )
+ {
+ if ( configParam.name().equals(propertyName) || field.getName().equals(propertyName) )
+ {
+ setPropertyValue(field, instance, value);
+ fieldSet = true;
+ }
+ }
+ }
+ return fieldSet;
+ }
+
+
/**
* Set property value.
*
Added: 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 (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/AnnotatedResource.java 2008-09-05 09:58:25 UTC (rev 22430)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.deploy.config;
+
+import org.jboss.esb.annotation.ConfigParam;
+import org.jboss.esb.annotation.ConfigParam.Use;
+
+/**
+ * Simple pojo which uses annotations.
+ *
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class AnnotatedResource
+{
+ @ConfigParam ( use = Use.REQUIRED, name = "userName" )
+ private String name;
+
+ @ConfigParam ( use = Use.REQUIRED )
+ private String lastName;
+
+ private String password;
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ @ConfigParam ( use = Use.OPTIONAL, defaultVal = "John Doe" )
+ private int age;
+
+ @ConfigParam ( use = Use.REQUIRED )
+ private Double weight;
+
+ private String org;
+
+ public String getOrganization()
+ {
+ return org;
+ }
+
+ @ConfigParam ( use = Use.REQUIRED )
+ public void setOrganization(String org)
+ {
+ this.org = org;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public int getAge()
+ {
+ return age;
+ }
+
+ public Double getWeight()
+ {
+ return weight;
+ }
+
+ public String getLastName()
+ {
+ return lastName;
+ }
+
+}
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-05 05:20:25 UTC (rev 22429)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java 2008-09-05 09:58:25 UTC (rev 22430)
@@ -19,12 +19,15 @@
*/
package org.jboss.esb.deploy.config;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
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.junit.After;
+import org.junit.Test;
import java.io.IOException;
import java.util.Map;
@@ -34,9 +37,10 @@
/**
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
*/
-public class DefaultConfigurationDigesterTest extends TestCase
+public class DefaultConfigurationDigesterTest
{
+ @Test
public void test_validation() throws DeploymentException, IOException
{
digest("jbossesb-01.xml");
@@ -44,6 +48,7 @@
digest("jbossesb-03.xml");
}
+ @Test
public void test_resources_01() throws IOException, DeploymentException
{
DeploymentUnit configUnit = digest("jbossesb-resources_01.xml");
@@ -56,16 +61,19 @@
assertEquals(URI.create("http://acme.com"), xprotRes.getXprotResPropC());
}
+ @Test
public void test_inrouters_01() throws IOException, DeploymentException
{
test_inrouters("jbossesb-inrouters_01.xml");
}
+ @Test
public void test_outrouters_01() throws IOException, DeploymentException
{
test_outrouters("jbossesb-outrouters_01.xml");
}
+ @Test
public void test_inandoutrouters_01() throws IOException, DeploymentException
{
DeploymentUnit configUnit = digest("jbossesb-inandoutrouters_01.xml");
@@ -171,6 +179,7 @@
assertNull(transformers);
}
+ @Test
public void test_services_01() throws DeploymentException, IOException
{
DeploymentUnit configUnit = digest("jbossesb-services_01.xml");
@@ -191,14 +200,31 @@
assertEquals("propValueB", serviceB.getProp1());
}
+ @Test
+ public void annotatedResource() throws DeploymentException, IOException
+ {
+ DeploymentUnit configUnit = digest("jbossesb-resources_02.xml");
+ Map<String, Object> resources = configUnit.getResources();
+ Object object = resources.get("annotatedResource");
+ assertNotNull(object);
+ assertTrue(object instanceof AnnotatedResource);
+
+ AnnotatedResource res = (AnnotatedResource) object;
+ 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());
+ }
+
+
private DeploymentUnit digest(String config) throws IOException, DeploymentException
{
DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
return digester.digest(getClass().getResourceAsStream(config));
}
- protected void tearDown() throws Exception
+ @After
+ public void tearDown() throws Exception
{
- DigestUtil.setReportPath(null);
+ DigestUtil.setReportPath(null);
}
}
Added: 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 (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/digest/SetPropertyTest.java 2008-09-05 09:58:25 UTC (rev 22430)
@@ -0,0 +1,66 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.jboss.esb.deploy.config.AnnotatedResource;
+import org.junit.Test;
+
+/**
+ * Test for {@link SetProperty}.
+ *
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class SetPropertyTest
+{
+ private final SetProperty setProperty = new SetProperty();
+ private final AnnotatedResource annotatedResource = new AnnotatedResource();
+
+ @Test
+ public void attemptAnnotationFieldSet() throws IllegalAccessException
+ {
+ final String expectedName = "Fletcher";
+ boolean fieldSet = setProperty.attemptAnnotationFieldSet(annotatedResource , "lastName", expectedName);
+ assertTrue( fieldSet );
+ assertEquals( expectedName, annotatedResource.getLastName());
+ }
+
+ @Test
+ public void attemptAnnotationFieldSetNameSpecified() throws IllegalAccessException
+ {
+ final String expectedName = "Dr.Rosen";
+ boolean fieldSet = setProperty.attemptAnnotationFieldSet(annotatedResource , "userName", expectedName);
+ assertTrue( fieldSet );
+ assertEquals( expectedName, annotatedResource.getName() );
+ }
+
+ @Test
+ public void attemptAnnotationFieldSetNotAnnotated() throws IllegalAccessException
+ {
+ setProperty.attemptAnnotationFieldSet(annotatedResource , "password", "secret");
+ assertNull( annotatedResource.getName() );
+ }
+
+}
Added: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/jbossesb-resources_02.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/jbossesb-resources_02.xml (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/jbossesb-resources_02.xml 2008-09-05 09:58:25 UTC (rev 22430)
@@ -0,0 +1,9 @@
+<jbossesb xmlns="http://www.jboss.org/jbossesb/xsd/jbossesb-5.0.xsd">
+ <resources>
+ <resource id="annotatedResource" class="org.jboss.esb.deploy.config.AnnotatedResource">
+ <property name="userName">Austin</property>
+ <property name="age">44</property>
+ <property name="weight">83.2</property>
+ </resource>
+ </resources>
+</jbossesb>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list