camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r999836 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/ components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/ components/camel-dozer/sr...
Date Wed, 22 Sep 2010 09:39:36 GMT
Author: davsclaus
Date: Wed Sep 22 09:39:36 2010
New Revision: 999836

URL: http://svn.apache.org/viewvc?rev=999836&view=rev
Log:
CAMEL-3143: Dozer is not OSGi compliant. OsgiTypeConverter is now a TypeConverterRegistry
as well.

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/DozerTest.java
      - copied, changed from r999771, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jms/JmsTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Address.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Customer.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/service/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/service/Customer.java
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/CamelContext.xml
      - copied, changed from r999771, camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jms/CamelContext.xml
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/dozer-mapping.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java
    camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java
    camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java
    camel/trunk/components/camel-dozer/src/test/resources/application-context.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=999836&r1=999835&r2=999836&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Wed
Sep 22 09:39:36 2010
@@ -872,9 +872,8 @@ public class DefaultCamelContext extends
             if (typeConverter == null) {
                 getTypeConverter();
             }
-            // type converter is usually the default one that also is the registry
-            if (typeConverter instanceof DefaultTypeConverter) {
-                typeConverterRegistry = (DefaultTypeConverter) typeConverter;
+            if (typeConverter instanceof TypeConverterRegistry) {
+                typeConverterRegistry = (TypeConverterRegistry) typeConverter;
             }
         }
         return typeConverterRegistry;

Modified: camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java?rev=999836&r1=999835&r2=999836&view=diff
==============================================================================
--- camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java
(original)
+++ camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java
Wed Sep 22 09:39:36 2010
@@ -27,6 +27,7 @@ import org.apache.camel.impl.ServiceSupp
 import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.impl.converter.TypeConverterLoader;
 import org.apache.camel.spi.Injector;
+import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.osgi.framework.BundleContext;
@@ -34,14 +35,14 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
-public class OsgiTypeConverter extends ServiceSupport implements TypeConverter, ServiceTrackerCustomizer
{
+public class OsgiTypeConverter extends ServiceSupport implements TypeConverter, TypeConverterRegistry,
ServiceTrackerCustomizer {
 
     private static final Log LOG = LogFactory.getLog(OsgiTypeConverter.class);
 
     private final BundleContext bundleContext;
     private final Injector injector;
     private final ServiceTracker tracker;
-    private volatile DefaultTypeConverter registry;
+    private volatile DefaultTypeConverter delegate;
 
     public OsgiTypeConverter(BundleContext bundleContext, Injector injector) {
         this.bundleContext = bundleContext;
@@ -52,7 +53,7 @@ public class OsgiTypeConverter extends S
     public Object addingService(ServiceReference serviceReference) {
         TypeConverterLoader loader = (TypeConverterLoader) bundleContext.getService(serviceReference);
         try {
-            loader.load(getRegistry());
+            loader.load(getDelegate());
         } catch (Throwable t) {
             LOG.debug("Error while loading type converter", t);
         }
@@ -63,7 +64,7 @@ public class OsgiTypeConverter extends S
     }
 
     public void removedService(ServiceReference serviceReference, Object o) {
-        this.registry = null;
+        this.delegate = null;
     }
 
     @Override
@@ -74,39 +75,60 @@ public class OsgiTypeConverter extends S
     @Override
     protected void doStop() throws Exception {
         this.tracker.close();
-        this.registry = null;
+        this.delegate = null;
     }
 
     public <T> T convertTo(Class<T> type, Object value) {
-        return getRegistry().convertTo(type, value);
+        return getDelegate().convertTo(type, value);
     }
 
     public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
-        return getRegistry().convertTo(type, exchange, value);
+        return getDelegate().convertTo(type, exchange, value);
     }
 
     public <T> T mandatoryConvertTo(Class<T> type, Object value) throws NoTypeConversionAvailableException
{
-        return getRegistry().mandatoryConvertTo(type, value);
+        return getDelegate().mandatoryConvertTo(type, value);
     }
 
     public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object
value) throws NoTypeConversionAvailableException {
-        return getRegistry().mandatoryConvertTo(type, exchange, value);
+        return getDelegate().mandatoryConvertTo(type, exchange, value);
     }
 
-    public DefaultTypeConverter getRegistry() {
-        if (registry == null) {
+    public void addTypeConverter(Class<?> toType, Class<?> fromType, TypeConverter
typeConverter) {
+        getDelegate().addTypeConverter(toType, fromType, typeConverter);
+    }
+
+    public void addFallbackTypeConverter(TypeConverter typeConverter, boolean canPromote)
{
+        getDelegate().addFallbackTypeConverter(typeConverter, canPromote);
+    }
+
+    public TypeConverter lookup(Class<?> toType, Class<?> fromType) {
+        return getDelegate().lookup(toType, fromType);
+    }
+
+    public void setInjector(Injector injector) {
+        getDelegate().setInjector(injector);
+    }
+
+    public Injector getInjector() {
+        return getDelegate().getInjector();
+    }
+
+    public DefaultTypeConverter getDelegate() {
+        if (delegate == null) {
             synchronized (this) {
-                if (registry != null) {
-                    return registry;
+                if (delegate != null) {
+                    return delegate;
                 } else {
-                    registry = createRegistry();
+                    delegate = createRegistry();
                 }
             }
         }
-        return registry;
+        return delegate;
     }
 
     protected DefaultTypeConverter createRegistry() {
+        // base the osgi type converter on the default type converter
         DefaultTypeConverter reg = new DefaultTypeConverter(new DefaultPackageScanClassResolver()
{
             @Override
             public Set<ClassLoader> getClassLoaders() {
@@ -126,5 +148,4 @@ public class OsgiTypeConverter extends S
         return reg;
     }
 
-
 }

Modified: camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java?rev=999836&r1=999835&r2=999836&view=diff
==============================================================================
--- camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
(original)
+++ camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
Wed Sep 22 09:39:36 2010
@@ -16,7 +16,10 @@
  */
 package org.apache.camel.converter.dozer;
 
+import java.net.URL;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
@@ -28,13 +31,14 @@ import org.apache.commons.logging.LogFac
 import org.dozer.DozerBeanMapper;
 import org.dozer.Mapper;
 import org.dozer.classmap.ClassMap;
-import org.dozer.loader.CustomMappingsLoader;
-import org.dozer.loader.LoadMappingsResult;
+import org.dozer.classmap.MappingFileData;
+import org.dozer.loader.xml.MappingFileReader;
+import org.dozer.loader.xml.XMLParserFactory;
 
 /**
  * <code>DozerTypeConverterLoader</code> provides the mechanism for registering
  * a Dozer {@link Mapper} as {@link TypeConverter} for a {@link CamelContext}.
- * <p>
+ * <p/>
  * While a mapper can be explicitly supplied as a parameter the
  * {@link CamelContext}'s registry will also be searched for {@link Mapper}
  * instances. A {@link DozerTypeConverter} is created to wrap each
@@ -61,7 +65,7 @@ public class DozerTypeConverterLoader im
      * register as a {@link TypeConverter} with the context
      *
      * @param camelContext the context to register the
-     *            {@link DozerTypeConverter} in
+     *                     {@link DozerTypeConverter} in
      */
     public DozerTypeConverterLoader(CamelContext camelContext) {
         init(camelContext, null);
@@ -73,8 +77,8 @@ public class DozerTypeConverterLoader im
      * with the given context. It will also search the context for
      *
      * @param camelContext the context to register the
-     *            {@link DozerTypeConverter} in
-     * @param mapper the DozerMapperBean to be wrapped as a type converter.
+     *                     {@link DozerTypeConverter} in
+     * @param mapper       the DozerMapperBean to be wrapped as a type converter.
      */
     public DozerTypeConverterLoader(CamelContext camelContext, DozerBeanMapper mapper) {
         init(camelContext, mapper);
@@ -85,8 +89,8 @@ public class DozerTypeConverterLoader im
      * with the {@link CamelContext}.
      *
      * @param camelContext the context to register the
-     *            {@link DozerTypeConverter} in
-     * @param mapper the DozerMapperBean to be wrapped as a type converter.
+     *                     {@link DozerTypeConverter} in
+     * @param mapper       the DozerMapperBean to be wrapped as a type converter.
      */
     public void init(CamelContext camelContext, DozerBeanMapper mapper) {
         this.camelContext = camelContext;
@@ -94,29 +98,39 @@ public class DozerTypeConverterLoader im
         if (mapper != null) {
             mappers.put("parameter", mapper);
         }
-        if (mappers.size() > 0) {
-            log.warn("Loaded %d dozer mappers from Camel's registry. Dozer is most efficient
when there is a single mapper instance. Consider amalgamating instances.");
+        if (mappers.size() > 1) {
+            log.warn("Loaded " + mappers.size() + " Dozer mappers from Camel registry."
+                    + " Dozer is most efficient when there is a single mapper instance. Consider
amalgamating instances.");
+        } else if (mappers.size() == 0) {
+            log.warn("No Dozer mappers found in Camel registry. You should add Dozer mappers
as beans to the registry of the type: " + DozerBeanMapper.class.getName());
         }
 
         TypeConverterRegistry registry = camelContext.getTypeConverterRegistry();
         for (DozerBeanMapper dozer : mappers.values()) {
-            Map<String, ClassMap> all = loadMappings(dozer);
+            List<ClassMap> all = loadMappings(camelContext, dozer);
             DozerTypeConverter converter = new DozerTypeConverter(dozer);
-            for (ClassMap map : all.values()) {
+            for (ClassMap map : all) {
+                if (log.isInfoEnabled()) {
+                    log.info("Added " + map.getSrcClassName() + " -> " + map.getDestClassName()
+ " as type converter to: " + registry);
+                }
                 registry.addTypeConverter(map.getSrcClassToMap(), map.getDestClassToMap(),
converter);
                 registry.addTypeConverter(map.getDestClassToMap(), map.getSrcClassToMap(),
converter);
             }
         }
     }
 
-    private Map<String, ClassMap> loadMappings(DozerBeanMapper mapper) {
-        // TODO: This is a little wasteful as dozer has already parsed this
-        // information, if does not expose it though so it must be done again.
-        // Create a patch for Dozer to expose this.
-        CustomMappingsLoader customMappingsLoader = new CustomMappingsLoader();
-        LoadMappingsResult loadMappingsResult = customMappingsLoader.load(mapper.getMappingFiles());
-        Map<String, ClassMap> all = loadMappingsResult.getCustomMappings().getAll();
-        return all;
+    private List<ClassMap> loadMappings(CamelContext camelContext, DozerBeanMapper
mapper) {
+        List<ClassMap> answer = new ArrayList<ClassMap>();
+
+        // load the class map using the class resolver so we can load from classpath in OSGi
+        MappingFileReader reader = new MappingFileReader(XMLParserFactory.getInstance());
+        for (String name : mapper.getMappingFiles()) {
+            URL url = camelContext.getClassResolver().loadResourceAsURL(name);
+            MappingFileData data = reader.read(url);
+            answer.addAll(data.getClassMaps());
+        }
+
+        return answer;
     }
 
     public CamelContext getCamelContext() {

Modified: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java?rev=999836&r1=999835&r2=999836&view=diff
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java
(original)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/DozerTypeConverterTest.java
Wed Sep 22 09:39:36 2010
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.converter.dozer;
 
-import java.util.concurrent.TimeUnit;
-
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.converter.dozer.service.Customer;
@@ -33,14 +31,12 @@ public class DozerTypeConverterTest exte
     @Override
     public void setUp() throws Exception {
         super.setUp();
-
         new DozerTypeConverterLoader(context, createMapper());
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
-
             @Override
             public void configure() throws Exception {
                 from("direct:service-in").bean(new CustomerProcessor()).to("mock:verify-model");
@@ -52,14 +48,14 @@ public class DozerTypeConverterTest exte
     public void verifyCamelConversionViaDozer() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:verify-model");
         mock.expectedMessageCount(1);
+
         template.sendBody("direct:service-in", createServiceCustomer());
-        mock.await(5, TimeUnit.SECONDS);
-        mock.assertIsSatisfied();
+
+        assertMockEndpointsSatisfied();
     }
 
     @Test
     public void verifyCustomerMapping() throws Exception {
-
         Mapper mapper = DozerTestArtifactsFactory.createMapper();
         Customer service = createServiceCustomer();
         org.apache.camel.converter.dozer.model.Customer model = mapper.map(service, org.apache.camel.converter.dozer.model.Customer.class);
@@ -67,5 +63,4 @@ public class DozerTypeConverterTest exte
         assertEquals(service, roundTrip);
     }
 
-
 }

Modified: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java?rev=999836&r1=999835&r2=999836&view=diff
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java
(original)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/SpringDozerTypeConverterTest.java
Wed Sep 22 09:39:36 2010
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.converter.dozer;
 
-import java.util.concurrent.TimeUnit;
-
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelSpringTestSupport;
 import org.junit.Test;
@@ -37,8 +35,9 @@ public class SpringDozerTypeConverterTes
     public void verifyCamelConversionViaDozer() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:verify-model");
         mock.expectedMessageCount(1);
+
         template.sendBody("direct:service-in", createServiceCustomer());
-        mock.await(5, TimeUnit.SECONDS);
-        mock.assertIsSatisfied();
+
+        assertMockEndpointsSatisfied();
     }
 }

Modified: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java?rev=999836&r1=999835&r2=999836&view=diff
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java
(original)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Address.java
Wed Sep 22 09:39:36 2010
@@ -23,14 +23,12 @@ import org.apache.commons.lang.builder.T
 public class Address {
 
     private String zipCode;
-
     private String streetName;
 
     public Address() {
     }
 
     public Address(String zipCode, String streetName) {
-
         this.zipCode = zipCode;
         this.streetName = streetName;
     }

Modified: camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java?rev=999836&r1=999835&r2=999836&view=diff
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java
(original)
+++ camel/trunk/components/camel-dozer/src/test/java/org/apache/camel/converter/dozer/model/Customer.java
Wed Sep 22 09:39:36 2010
@@ -21,10 +21,9 @@ import org.apache.commons.lang.builder.H
 import org.apache.commons.lang.builder.ToStringBuilder;
 
 public class Customer {
-    private String firstName;
 
+    private String firstName;
     private String lastName;
-
     private Address address;
 
     public Customer() {
@@ -75,5 +74,4 @@ public class Customer {
         return ToStringBuilder.reflectionToString(this);
     }
 
-
 }

Modified: camel/trunk/components/camel-dozer/src/test/resources/application-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dozer/src/test/resources/application-context.xml?rev=999836&r1=999835&r2=999836&view=diff
==============================================================================
--- camel/trunk/components/camel-dozer/src/test/resources/application-context.xml (original)
+++ camel/trunk/components/camel-dozer/src/test/resources/application-context.xml Wed Sep
22 09:39:36 2010
@@ -16,25 +16,26 @@
   limitations under the License.
 -->
 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-  http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
-  
-  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-    <route>
-      <from uri="direct:service-in" />
-      <to uri="bean:customer-processor" />
-      <to uri="mock:verify-model" />
-    </route>
-  </camelContext>
-  
-  <bean id="customer-processor"  class="org.apache.camel.converter.dozer.CustomerProcessor"
/>
-  <bean id="dozerConverterLoader"  class="org.apache.camel.converter.dozer.DozerTypeConverterLoader"
/>
-  
-  <bean id="mapper" class="org.dozer.DozerBeanMapper">
-    <property name="mappingFiles">
-      <list>
-        <value>mapping.xml</value>
-      </list>
-    </property>
-  </bean>
+       xsi:schemaLocation="
+            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+            http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+        <route>
+            <from uri="direct:service-in"/>
+            <to uri="bean:customer-processor"/>
+            <to uri="mock:verify-model"/>
+        </route>
+    </camelContext>
+
+    <bean id="customer-processor" class="org.apache.camel.converter.dozer.CustomerProcessor"/>
+    <bean id="dozerConverterLoader" class="org.apache.camel.converter.dozer.DozerTypeConverterLoader"/>
+
+    <bean id="mapper" class="org.dozer.DozerBeanMapper">
+        <property name="mappingFiles">
+            <list>
+                <value>mapping.xml</value>
+            </list>
+        </property>
+    </bean>
 </beans>
\ No newline at end of file

Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/DozerTest.java
(from r999771, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jms/JmsTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/DozerTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/DozerTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jms/JmsTest.java&r1=999771&r2=999836&rev=999836&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jms/JmsTest.java
(original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/DozerTest.java
Wed Sep 22 09:39:36 2010
@@ -14,9 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.itest.osgi.jms;
+package org.apache.camel.itest.osgi.dozer;
 
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport;
+import org.apache.camel.itest.osgi.dozer.service.Customer;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
@@ -35,18 +38,33 @@ import static org.ops4j.pax.exam.contain
  * @version $Revision$
  */
 @RunWith(JUnit4TestRunner.class)
-public class JmsTest extends OSGiIntegrationSpringTestSupport {
+@Ignore("Dozer does not work in OSGi")
+public class DozerTest extends OSGiIntegrationSpringTestSupport {
 
     @Override
     protected OsgiBundleXmlApplicationContext createApplicationContext() {
-        return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/jms/CamelContext.xml"});
+        return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/dozer/CamelContext.xml"});
     }
 
     @Test
-    public void testJms() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+    public void testDozer() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        // should be the model customer
+        mock.message(0).body().isInstanceOf(org.apache.camel.itest.osgi.dozer.model.Customer.class);
+        // and assert the model contains the expected data
+        mock.message(0).simple("${body.firstName} == Homer");
+        mock.message(0).simple("${body.lastName} == Simpson");
+        mock.message(0).simple("${body.address.streetMame} == 'Somestreet 123'");
+        mock.message(0).simple("${body.address.zipCode} == 26000");
+
+        Customer serviceCustomer = new Customer();
+        serviceCustomer.setFirstName("Homer");
+        serviceCustomer.setLastName("Simpson");
+        serviceCustomer.setStreet("Somestreet 123");
+        serviceCustomer.setZip("26000");
 
-        template.sendBody("activemq:queue:foo", "Hello World");
+        template.sendBody("direct:start", serviceCustomer);
 
         assertMockEndpointsSatisfied();
     }
@@ -60,12 +78,9 @@ public class JmsTest extends OSGiIntegra
             // this is how you set the default log level when using pax logging (logProfile)
             org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
 
-            // using the features to install AMQ
-            scanFeatures("mvn:org.apache.activemq/activemq-karaf/5.4.0/xml/features", "activemq"),
-
             // using the features to install the camel components
             scanFeatures(getCamelKarafFeatureUrl(),
-                          "camel-core", "camel-spring", "camel-test", "camel-jms"),
+                          "camel-core", "camel-spring", "camel-test", "camel-dozer"),
 
             workingDirectory("target/paxrunner/"),
 

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Address.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Address.java?rev=999836&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Address.java
(added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Address.java
Wed Sep 22 09:39:36 2010
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.itest.osgi.dozer.model;
+
+/**
+ * @version $Revision$
+ */
+public class Address {
+
+    private String zipCode;
+    private String streetName;
+
+    public String getZipCode() {
+        return zipCode;
+    }
+
+    public void setZipCode(String zipCode) {
+        this.zipCode = zipCode;
+    }
+
+    public String getStreetName() {
+        return streetName;
+    }
+
+    public void setStreetName(String streetName) {
+        this.streetName = streetName;
+    }
+
+}

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Customer.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Customer.java?rev=999836&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Customer.java
(added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/model/Customer.java
Wed Sep 22 09:39:36 2010
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.itest.osgi.dozer.model;
+
+/**
+ * @version $Revision$
+ */
+public class Customer {
+
+    private String firstName;
+    private String lastName;
+    private Address address;
+
+    public Customer() {
+    }
+
+    public Customer(String firstName, String lastName, Address address) {
+        this.firstName = firstName;
+        this.lastName = lastName;
+        this.address = address;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public Address getAddress() {
+        return address;
+    }
+
+    public void setAddress(Address address) {
+        this.address = address;
+    }
+
+}

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/service/Customer.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/service/Customer.java?rev=999836&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/service/Customer.java
(added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/dozer/service/Customer.java
Wed Sep 22 09:39:36 2010
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.itest.osgi.dozer.service;
+
+/**
+ * @version $Revision$
+ */
+public class Customer {
+
+    private String firstName;
+    private String lastName;
+    private String street;
+    private String zip;
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public String getStreet() {
+        return street;
+    }
+
+    public void setStreet(String street) {
+        this.street = street;
+    }
+
+    public String getZip() {
+        return zip;
+    }
+
+    public void setZip(String zip) {
+        this.zip = zip;
+    }
+
+}

Copied: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/CamelContext.xml
(from r999771, camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jms/CamelContext.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/CamelContext.xml?p2=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/CamelContext.xml&p1=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jms/CamelContext.xml&r1=999771&r2=999836&rev=999836&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jms/CamelContext.xml
(original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/CamelContext.xml
Wed Sep 22 09:39:36 2010
@@ -25,16 +25,20 @@
 
     <camelContext xmlns="http://camel.apache.org/schema/spring">
         <camel:route>
-            <camel:from uri="activemq:queue:foo"/>
+            <camel:from uri="direct:start"/>
+            <!-- convert the body to the model which should involve Dozer -->
+            <camel:convertBodyTo type="org.apache.camel.itest.osgi.dozer.model.Customer"/>
             <camel:to uri="mock:result"/>
         </camel:route>
     </camelContext>
 
-    <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
-        <property name="connectionFactory">
-            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
-                <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
-            </bean>
+    <bean id="dozerConverterLoader" class="org.apache.camel.converter.dozer.DozerTypeConverterLoader"/>
+
+    <bean id="mapper" class="org.dozer.DozerBeanMapper">
+        <property name="mappingFiles">
+            <list>
+                <value>org/apache/camel/itest/osgi/dozer/dozer-mapping.xml</value>
+            </list>
         </property>
     </bean>
 

Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/dozer-mapping.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/dozer-mapping.xml?rev=999836&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/dozer-mapping.xml
(added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/dozer/dozer-mapping.xml
Wed Sep 22 09:39:36 2010
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://dozer.sourceforge.net  http://dozer.sourceforge.net/schema/beanmapping.xsd">
+  <mapping>
+    <class-a>org.apache.camel.itest.osgi.dozer.service.Customer</class-a>
+    <class-b>org.apache.camel.itest.osgi.dozer.model.Customer</class-b>
+    <field>
+      <a>street</a>
+      <b>address.streetName</b>
+    </field>
+    <field>
+      <a>zip</a>
+      <b>address.zipCode</b>
+    </field>
+  </mapping>
+</mappings>
\ No newline at end of file



Mime
View raw message