camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r761582 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/ test/java/org/apache/camel/component/event/ test/resources/org/apache/camel/component/event/
Date Fri, 03 Apr 2009 09:37:54 GMT
Author: davsclaus
Date: Fri Apr  3 09:37:54 2009
New Revision: 761582

URL: http://svn.apache.org/viewvc?rev=761582&view=rev
Log:
MR-159: package tag should be normalized in case end users inserts new lines or the likes.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/event/MistypedPackageTest.java
      - copied, changed from r761528, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/event/EventRouteTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
      - copied, changed from r761528, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/event/camelContext.xml
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=761582&r1=761581&r2=761582&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Fri Apr  3 09:37:54 2009
@@ -53,6 +53,7 @@
 import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.util.ProcessorDefinitionHelper;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.DisposableBean;
@@ -541,12 +542,23 @@
     }
 
     /**
-     * Strategy method to try find {@link RouteBuilder} instances on the
-     * classpath
+     * Strategy method to try find {@link RouteBuilder} instances on the classpath
      */
     protected void findRouteBuilders() throws Exception {
+        List<String> packages = new ArrayList<String>();
+
         if (getPackages() != null && getPackages().length > 0) {
-            RouteBuilderFinder finder = new RouteBuilderFinder(getContext(), getPackages(),
getContextClassLoaderOnStart(),
+
+            // normalize packages as end user can have inserted spaces or \n or the likes
+            for (String name : getPackages()) {
+                name = ObjectHelper.normalizeClassName(name);
+                if (ObjectHelper.isNotEmpty(name)) {
+                    packages.add(name);
+                }
+            }
+            String[] normalized = packages.toArray(new String[packages.size()]);
+
+            RouteBuilderFinder finder = new RouteBuilderFinder(getContext(), normalized,
getContextClassLoaderOnStart(),
                     getBeanPostProcessor(), getContext().getPackageScanClassResolver());
             finder.appendBuilders(getAdditionalBuilders());
         }

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/event/MistypedPackageTest.java
(from r761528, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/event/EventRouteTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/event/MistypedPackageTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/event/MistypedPackageTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/event/EventRouteTest.java&r1=761528&r2=761582&rev=761582&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/event/EventRouteTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/event/MistypedPackageTest.java
Fri Apr  3 09:37:54 2009
@@ -26,34 +26,9 @@
 /**
  * @version $Revision$
  */
-public class EventRouteTest extends SpringTestSupport {
-    protected Object expectedBody = "Hello there!";
-    protected String uri = "spring-event:default";
-
-    public void testSendingCamelExchangeToEndpointResultsInValidApplicationEventAfterTheRefreshEvent()
throws Exception {
-        MockEndpoint result = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
-        result.expectedMessageCount(2);
-
-        template.sendBodyAndHeader(uri, expectedBody, "cheese", 123);
-
-        result.assertIsSatisfied();
-
-        // lets test we receive the context refreshed event
-        Exchange exchange = result.getReceivedExchanges().get(0);
-        Object body = exchange.getIn().getBody(ContextRefreshedEvent.class);
-        log.info("Received body: " + body);
-        assertNotNull(body);
-
-        // lets test we receive the camel event
-        exchange = result.getReceivedExchanges().get(1);
-        body = exchange.getIn().getBody();
-        log.info("Received body: " + body);
-        CamelEvent event = assertIsInstanceOf(CamelEvent.class, body);
-        Object actualBody = event.getExchange().getIn().getBody();
-        assertEquals("Received event body", expectedBody, actualBody);
-    }
+public class MistypedPackageTest extends EventRouteTest {
 
     protected AbstractXmlApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext("org/apache/camel/component/event/camelContext.xml");
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/event/mistypedPackage.xml");
     }
-}
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
(from r761528, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/event/camelContext.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/event/camelContext.xml&r1=761528&r2=761582&rev=761582&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/event/camelContext.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
Fri Apr  3 09:37:54 2009
@@ -22,13 +22,16 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-  <camelContext xmlns="http://camel.apache.org/schema/spring">
-    <package>org.apache.camel.component.event</package>
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
 
-    <route>
-      <from uri="spring-event:default"/>
-      <to uri="mock:result"/>
-    </route>
-  </camelContext>
+        <!-- to test that if end users have \n or the likes when they define a package
-->
+        <package>org.apache.camel.component.event
+        </package>
+
+        <route>
+            <from uri="spring-event:default"/>
+            <to uri="mock:result"/>
+        </route>
+    </camelContext>
 
 </beans>



Mime
View raw message