You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/11/27 12:07:32 UTC

svn commit: r598590 - in /activemq/camel/trunk/components/camel-spring/src/test: data/ java/org/apache/camel/spring/ java/org/apache/camel/spring/mock/ resources/org/apache/camel/spring/mock/

Author: jstrachan
Date: Tue Nov 27 03:07:20 2007
New Revision: 598590

URL: http://svn.apache.org/viewvc?rev=598590&view=rev
Log:
added an example test case showing how you can use a bean in Spring to perform expectations and assertions

Added:
    activemq/camel/trunk/components/camel-spring/src/test/data/
    activemq/camel/trunk/components/camel-spring/src/test/data/message1.xml
      - copied unchanged from r598567, activemq/camel/trunk/examples/camel-example-spring/src/data/message1.xml
    activemq/camel/trunk/components/camel-spring/src/test/data/message2.xml
      - copied unchanged from r598567, activemq/camel/trunk/examples/camel-example-spring/src/data/message2.xml
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/ApplicationContextTestSupport.java
      - copied, changed from r598567, activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/BeanMockTest.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/MyAssertions.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/spring.xml   (with props)

Copied: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/ApplicationContextTestSupport.java (from r598567, activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/ApplicationContextTestSupport.java?p2=activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/ApplicationContextTestSupport.java&p1=activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java&r1=598567&r2=598590&rev=598590&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/ApplicationContextTestSupport.java Tue Nov 27 03:07:20 2007
@@ -16,26 +16,15 @@
  */
 package org.apache.camel.spring;
 
-import java.util.List;
-
-import org.apache.camel.CamelTemplate;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Route;
-import org.apache.camel.TestSupport;
-import org.apache.camel.CamelContext;
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.component.mock.MockEndpoint;
+import junit.framework.TestCase;
 import org.apache.camel.util.ObjectHelper;
-
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * @version $Revision: 1.1 $
  */
-public abstract class SpringTestSupport extends ContextTestSupport {
+public abstract class ApplicationContextTestSupport extends TestCase {
     protected AbstractXmlApplicationContext applicationContext;
 
     protected abstract ClassPathXmlApplicationContext createApplicationContext();
@@ -56,7 +45,7 @@
         }
     }
 
-        
+
     /**
      * Looks up the mandatory spring bean of the given name and type, failing if
      * it is not present or the correct type
@@ -71,26 +60,4 @@
             return null;
         }
     }
-
-    @Override
-    protected void assertValidContext(CamelContext context) {
-        super.assertValidContext(context);
-
-        List<Route> routes = context.getRoutes();
-        int routeCount = getExpectedRouteCount();
-        if (routeCount > 0) {
-            assertNotNull("Should have some routes defined", routes);
-            assertTrue("Should have at least one route", routes.size() >= routeCount);
-        }
-        log.debug("Camel Routes: " + routes);
-    }
-
-    protected int getExpectedRouteCount() {
-        return 1;
-    }
-
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        return SpringCamelContext.springCamelContext(applicationContext);
-    }
-}
+}
\ No newline at end of file

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/BeanMockTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/BeanMockTest.java?rev=598590&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/BeanMockTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/BeanMockTest.java Tue Nov 27 03:07:20 2007
@@ -0,0 +1,36 @@
+/**
+ *
+ * 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.spring.mock;
+
+import org.apache.camel.spring.ApplicationContextTestSupport;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class BeanMockTest extends ApplicationContextTestSupport {
+    public void testAssertionsUsingBean() throws Exception {
+        MyAssertions bean = getMandatoryBean(MyAssertions.class, "myBean");
+        bean.assertEndpointsValid();
+        System.out.println("Done asserting: " + bean);
+    }
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/mock/spring.xml");
+    }
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/BeanMockTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/MyAssertions.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/MyAssertions.java?rev=598590&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/MyAssertions.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/MyAssertions.java Tue Nov 27 03:07:20 2007
@@ -0,0 +1,50 @@
+/**
+ *
+ * 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.spring.mock;
+
+import junit.framework.Assert;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.springframework.beans.factory.InitializingBean;
+
+/**
+ * An example bean which adds some expectations on some mock endpoints and then
+ * asserts that the expectactions are met.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class MyAssertions implements InitializingBean {
+    @EndpointInject(uri="mock:matched")
+    private MockEndpoint matched;
+
+    @EndpointInject(uri="mock:notMatched")
+    private MockEndpoint notMatched;
+
+    public void afterPropertiesSet() throws Exception {
+        matched.expectedMessageCount(1);
+        notMatched.expectedMessageCount(0);
+    }
+
+    public void assertEndpointsValid() throws Exception {
+        Assert.assertNotNull("Should have a matched endpoint", matched);
+        Assert.assertNotNull("Should have a notMatched endpoint", notMatched);
+        MockEndpoint.assertIsSatisfied(matched, notMatched);
+    }
+
+
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/MyAssertions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/spring.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/spring.xml?rev=598590&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/spring.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/spring.xml Tue Nov 27 03:07:20 2007
@@ -0,0 +1,40 @@
+<?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.
+-->
+<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-2.0.xsd
+       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+    <route>
+      <from uri="file:src/test/data?noop=true"/>
+      <filter>
+        <xpath>/person/city = 'London'</xpath>
+        <to uri="mock:matched"/>
+      </filter>
+    </route>
+  </camelContext>
+
+  <bean id="myBean" class="org.apache.camel.spring.mock.MyAssertions" scope="singleton"/>
+  <!-- END SNIPPET: example -->
+
+
+</beans>

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/spring.xml
------------------------------------------------------------------------------
    svn:eol-style = native