You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/06/14 08:10:07 UTC

svn commit: r784509 - in /camel/trunk/components/camel-test: ./ src/main/java/org/apache/camel/test/junit4/

Author: ningjiang
Date: Sun Jun 14 06:10:06 2009
New Revision: 784509

URL: http://svn.apache.org/viewvc?rev=784509&view=rev
Log:
CAMEL-1704 added JUnit4 version of CamelTestSupport and CamelSpringTestSupport

Added:
    camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/
    camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java   (with props)
    camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java   (with props)
    camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java   (with props)
Modified:
    camel/trunk/components/camel-test/pom.xml

Modified: camel/trunk/components/camel-test/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/pom.xml?rev=784509&r1=784508&r2=784509&view=diff
==============================================================================
--- camel/trunk/components/camel-test/pom.xml (original)
+++ camel/trunk/components/camel-test/pom.xml Sun Jun 14 06:10:06 2009
@@ -47,6 +47,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
+      <version>4.6</version>
     </dependency>
 
     <!-- optional dependencies for running tests -->

Added: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java?rev=784509&view=auto
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java (added)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java Sun Jun 14 06:10:06 2009
@@ -0,0 +1,90 @@
+/**
+ * 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.test.junit4;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.After;
+import org.junit.Before;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public abstract class CamelSpringTestSupport extends CamelTestSupport {
+    protected AbstractXmlApplicationContext applicationContext;
+
+    protected abstract AbstractXmlApplicationContext createApplicationContext();
+
+    @Before
+    public void setUp() throws Exception {
+        applicationContext = createApplicationContext();
+        assertNotNull("Should have created a valid spring context", applicationContext);
+
+        super.setUp();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+        if (applicationContext != null) {
+            applicationContext.destroy();
+        }
+    }
+
+
+    /**
+     * Looks up the mandatory spring bean of the given name and type, failing if
+     * it is not present or the correct type
+     */
+    public <T> T getMandatoryBean(Class<T> type, String name) {
+        Object value = applicationContext.getBean(name);
+        assertNotNull("No spring bean found for name <" + name + ">", value);
+        if (type.isInstance(value)) {
+            return type.cast(value);
+        } else {
+            fail("Spring bean <" + name + "> is not an instanceof " + type.getName() + " but is of type " + ObjectHelper.className(value));
+            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);
+    }
+}

Propchange: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java?rev=784509&view=auto
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java (added)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java Sun Jun 14 06:10:06 2009
@@ -0,0 +1,350 @@
+/**
+ * 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.test.junit4;
+
+import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Message;
+import org.apache.camel.Predicate;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.Service;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.management.JmxSystemPropertyKeys;
+import org.apache.camel.spi.Language;
+import org.apache.camel.spring.CamelBeanPostProcessor;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * A useful base class which creates a {@link org.apache.camel.CamelContext} with some routes
+ * along with a {@link org.apache.camel.ProducerTemplate} for use in the test case
+ *
+ * @version $Revision$
+ */
+public abstract class CamelTestSupport extends TestSupport {    
+    protected CamelContext context;
+    protected ProducerTemplate template;
+    private boolean useRouteBuilder = true;
+    private Service camelContextService;
+
+    public boolean isUseRouteBuilder() {
+        return useRouteBuilder;
+    }
+
+    public void setUseRouteBuilder(boolean useRouteBuilder) {
+        this.useRouteBuilder = useRouteBuilder;
+    }
+
+    public Service getCamelContextService() {
+        return camelContextService;
+    }
+
+    /**
+     * Allows a service to be registered a separate lifecycle service to start
+     * and stop the context; such as for Spring when the ApplicationContext is
+     * started and stopped, rather than directly stopping the CamelContext
+     */
+    public void setCamelContextService(Service camelContextService) {
+        this.camelContextService = camelContextService;
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        context = createCamelContext();
+        assertValidContext(context);
+
+        template = context.createProducerTemplate();
+
+        postProcessTest();
+        
+        if (isUseRouteBuilder()) {
+            RouteBuilder[] builders = createRouteBuilders();
+            for (RouteBuilder builder : builders) {
+                log.debug("Using created route builder: " + builder);
+                context.addRoutes(builder);
+            }
+            startCamelContext();
+            log.debug("Routing Rules are: " + context.getRoutes());
+        } else {
+            log.debug("Using route builder from the created context: " + context);
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        
+        if (template != null) {
+            template.stop();
+        }
+        stopCamelContext();
+    }
+    
+    /**
+     * Lets post process this test instance to process any Camel annotations.
+     * Note that using Spring Test or Guice is a more powerful approach.
+     */
+    protected void postProcessTest() throws Exception {
+        CamelBeanPostProcessor processor = new CamelBeanPostProcessor();
+        processor.setCamelContext(context);
+        processor.postProcessBeforeInitialization(this, "this");
+    }
+
+    protected void stopCamelContext() throws Exception {
+        if (camelContextService != null) {
+            camelContextService.stop();
+        } else {
+            if (context != null) {
+                context.stop();
+            }
+        }
+    }
+
+    protected void startCamelContext() throws Exception {
+        if (camelContextService != null) {
+            camelContextService.start();
+        } else {
+            if (context instanceof DefaultCamelContext) {
+                DefaultCamelContext defaultCamelContext = (DefaultCamelContext) context;
+                if (!defaultCamelContext.isStarted()) {
+                    defaultCamelContext.start();
+                }
+            } else {
+                context.start();
+            }
+        }
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        return new DefaultCamelContext(createRegistry());
+    }
+
+    protected JndiRegistry createRegistry() throws Exception {
+        return new JndiRegistry(createJndiContext());
+    }
+
+    protected Context createJndiContext() throws Exception {
+        Properties properties = new Properties();
+
+        // jndi.properties is optional
+        InputStream in = getClass().getClassLoader().getResourceAsStream("jndi.properties");
+        if (in != null) {
+            log.debug("Using jndi.properties from classpath root");
+            properties.load(in);
+        }
+        return new InitialContext(new Hashtable(properties));
+    }
+
+    /**
+     * Factory method which derived classes can use to create a {@link org.apache.camel.builder.RouteBuilder}
+     * to define the routes for testing
+     */
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                // no routes added by default
+            }
+        };
+    }
+
+    /**
+     * Factory method which derived classes can use to create an array of
+     * {@link org.apache.camel.builder.RouteBuilder}s to define the routes for testing
+     *
+     * @see #createRouteBuilder()
+     */
+    protected RouteBuilder[] createRouteBuilders() throws Exception {
+        return new RouteBuilder[]{createRouteBuilder()};
+    }
+
+    /**
+     * Resolves a mandatory endpoint for the given URI or an exception is thrown
+     *
+     * @param uri the Camel <a href="">URI</a> to use to create or resolve an endpoint
+     * @return the endpoint
+     */
+    protected Endpoint resolveMandatoryEndpoint(String uri) {
+        return resolveMandatoryEndpoint(context, uri);
+    }
+
+    /**
+     * Resolves a mandatory endpoint for the given URI and expected type or an exception is thrown
+     *
+     * @param uri the Camel <a href="">URI</a> to use to create or resolve an endpoint
+     * @return the endpoint
+     */
+    protected <T extends Endpoint> T resolveMandatoryEndpoint(String uri, Class<T> endpointType) {
+        return resolveMandatoryEndpoint(context, uri, endpointType);
+    }
+
+    /**
+     * Resolves the mandatory Mock endpoint using a URI of the form <code>mock:someName</code>
+     *
+     * @param uri the URI which typically starts with "mock:" and has some name
+     * @return the mandatory mock endpoint or an exception is thrown if it could not be resolved
+     */
+    protected MockEndpoint getMockEndpoint(String uri) {
+        return resolveMandatoryEndpoint(uri, MockEndpoint.class);
+    }
+
+    /**
+     * Sends a message to the given endpoint URI with the body value
+     *
+     * @param endpointUri the URI of the endpoint to send to
+     * @param body        the body for the message
+     */
+    protected void sendBody(String endpointUri, final Object body) {
+        template.send(endpointUri, new Processor() {
+            public void process(Exchange exchange) {
+                Message in = exchange.getIn();
+                in.setBody(body);                
+            }
+        });
+    }
+
+    /**
+     * Sends a message to the given endpoint URI with the body value and specified headers
+     *
+     * @param endpointUri the URI of the endpoint to send to
+     * @param body        the body for the message
+     * @param headers     any headers to set on the message
+     */
+    protected void sendBody(String endpointUri, final Object body, final Map<String, Object> headers) {
+        template.send(endpointUri, new Processor() {
+            public void process(Exchange exchange) {
+                Message in = exchange.getIn();
+                in.setBody(body);                
+                for (Map.Entry<String, Object> entry : headers.entrySet()) {
+                    in.setHeader(entry.getKey(), entry.getValue());
+                }
+            }
+        });
+    }
+
+    /**
+     * Sends messages to the given endpoint for each of the specified bodies
+     *
+     * @param endpointUri the endpoint URI to send to
+     * @param bodies      the bodies to send, one per message
+     */
+    protected void sendBodies(String endpointUri, Object... bodies) {
+        for (Object body : bodies) {
+            sendBody(endpointUri, body);
+        }
+    }
+
+    /**
+     * Creates an exchange with the given body
+     */
+    protected Exchange createExchangeWithBody(Object body) {
+        return createExchangeWithBody(context, body);
+    }
+
+    /**
+     * Asserts that the given language name and expression evaluates to the
+     * given value on a specific exchange
+     */
+    protected void assertExpression(Exchange exchange, String languageName, String expressionText, Object expectedValue) {
+        Language language = assertResolveLanguage(languageName);
+
+        Expression expression = language.createExpression(expressionText);
+        assertNotNull("No Expression could be created for text: " + expressionText + " language: " + language, expression);
+
+        assertExpression(expression, exchange, expectedValue);
+    }
+
+    /**
+     * Asserts that the given language name and predicate expression evaluates
+     * to the expected value on the message exchange
+     */
+    protected void assertPredicate(String languageName, String expressionText, Exchange exchange, boolean expected) {
+        Language language = assertResolveLanguage(languageName);
+
+        Predicate predicate = language.createPredicate(expressionText);
+        assertNotNull("No Predicate could be created for text: " + expressionText + " language: " + language, predicate);
+
+        assertPredicate(predicate, exchange, expected);
+    }
+
+    /**
+     * Asserts that the language name can be resolved
+     */
+    protected Language assertResolveLanguage(String languageName) {
+        Language language = context.resolveLanguage(languageName);
+        assertNotNull("No language found for name: " + languageName, language);
+        return language;
+    }
+
+    /**
+     * Asserts that all the expectations of the Mock endpoints are valid
+     */
+    protected void assertMockEndpointsSatisfied() throws InterruptedException {
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    protected void assertValidContext(CamelContext context) {
+        assertNotNull("No context found!", context);
+    }
+
+    protected <T> List<T> getSingletonEndpoints(Class<T> type) {
+        return CamelContextHelper.getSingletonEndpoints(context, type);
+    }
+
+    protected <T extends Endpoint> T getMandatoryEndpoint(String uri, Class<T> type) {
+        T endpoint = context.getEndpoint(uri, type);
+        assertNotNull("No endpoint found for uri: " + uri, endpoint);
+        return endpoint;
+    }
+
+    protected Endpoint getMandatoryEndpoint(String uri) {
+        Endpoint endpoint = context.getEndpoint(uri);
+        assertNotNull("No endpoint found for uri: " + uri, endpoint);
+        return endpoint;
+    }
+
+    /**
+     * Disables the JMX agent. Must be called before the {@link #setUp()} method.
+     */
+    protected void disableJMX() {
+        System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
+    }
+
+    /**
+     * Enables the JMX agent. Must be called before the {@link #setUp()} method.
+     */
+    protected void enableJMX() {
+        System.setProperty(JmxSystemPropertyKeys.DISABLED, "false");
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java?rev=784509&view=auto
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java (added)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java Sun Jun 14 06:10:06 2009
@@ -0,0 +1,447 @@
+/**
+ * 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.test.junit4;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Channel;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.Predicate;
+import org.apache.camel.Processor;
+import org.apache.camel.Route;
+import org.apache.camel.builder.Builder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.ValueBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.processor.DelegateProcessor;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.PredicateAssertHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+
+/**
+ * A bunch of useful testing methods
+ *
+ * @version $Revision$
+ */
+public abstract class TestSupport extends Assert {
+    private static final Log LOG = LogFactory.getLog(TestSupport.class);    
+    protected transient Log log = LogFactory.getLog(getClass());    
+    
+    // Builder methods for expressions used when testing
+    // -------------------------------------------------------------------------
+
+    /**
+     * Returns a value builder for the given header
+     */
+    public static ValueBuilder header(String name) {
+        return Builder.header(name);
+    }
+
+    /**
+     * Returns a value builder for the given property
+     */
+    public static ValueBuilder property(String name) {
+        return Builder.property(name);
+    }    
+    
+    /**
+     * Returns a predicate and value builder for the inbound body on an exchange
+     */
+    public static ValueBuilder body() {
+        return Builder.body();
+    }
+
+    /**
+     * Returns a predicate and value builder for the inbound message body as a
+     * specific type
+     */
+    public static <T> ValueBuilder bodyAs(Class<T> type) {
+        return Builder.bodyAs(type);
+    }
+
+    /**
+     * Returns a predicate and value builder for the outbound body on an
+     * exchange
+     */
+    public static ValueBuilder outBody() {
+        return Builder.outBody();
+    }
+
+    /**
+     * Returns a predicate and value builder for the outbound message body as a
+     * specific type
+     */
+    public static <T> ValueBuilder outBodyAs(Class<T> type) {
+        return Builder.outBodyAs(type);
+    }
+
+    /**
+     * Returns a predicate and value builder for the fault body on an
+     * exchange
+     */
+    public static ValueBuilder faultBody() {
+        return Builder.faultBody();
+    }
+
+    /**
+     * Returns a predicate and value builder for the fault message body as a
+     * specific type
+     */
+    public static <T> ValueBuilder faultBodyAs(Class<T> type) {
+        return Builder.faultBodyAs(type);
+    }
+
+    /**
+     * Returns a value builder for the given system property
+     */
+    public static ValueBuilder systemProperty(String name) {
+        return Builder.systemProperty(name);
+    }
+
+    /**
+     * Returns a value builder for the given system property
+     */
+    public static ValueBuilder systemProperty(String name, String defaultValue) {
+        return Builder.systemProperty(name, defaultValue);
+    }
+
+    // Assertions
+    // -----------------------------------------------------------------------
+
+    public static <T> T assertIsInstanceOf(Class<T> expectedType, Object value) {
+        assertNotNull("Expected an instance of type: " + expectedType.getName() + " but was null", value);
+        assertTrue("object should be a " + expectedType.getName() + " but was: " + value + " with type: "
+                   + value.getClass().getName(), expectedType.isInstance(value));
+        return expectedType.cast(value);
+    }
+
+    public static void assertEndpointUri(Endpoint endpoint, String uri) {
+        assertNotNull("Endpoint is null when expecting endpoint for: " + uri, endpoint);
+        assertEquals("Endoint uri for: " + endpoint, uri, endpoint.getEndpointUri());
+    }
+
+    /**
+     * Asserts the In message on the exchange contains the expected value
+     */
+    public static Object assertInMessageHeader(Exchange exchange, String name, Object expected) {
+        return assertMessageHeader(exchange.getIn(), name, expected);
+    }
+
+    /**
+     * Asserts the Out message on the exchange contains the expected value
+     */
+    public static Object assertOutMessageHeader(Exchange exchange, String name, Object expected) {
+        return assertMessageHeader(exchange.getOut(), name, expected);
+    }
+
+    /**
+     * Asserts that the given exchange has an OUT message of the given body value
+     *
+     * @param exchange the exchange which should have an OUT message
+     * @param expected the expected value of the OUT message
+     * @throws InvalidPayloadException is thrown if the payload is not the expected class type
+     */
+    public static void assertInMessageBodyEquals(Exchange exchange, Object expected) throws InvalidPayloadException {
+        assertNotNull("Should have a response exchange!", exchange);
+
+        Object actual;
+        if (expected == null) {
+            actual = ExchangeHelper.getMandatoryInBody(exchange);
+            assertEquals("in body of: " + exchange, expected, actual);
+        } else {
+            actual = ExchangeHelper.getMandatoryInBody(exchange, expected.getClass());
+        }
+        assertEquals("in body of: " + exchange, expected, actual);
+
+        LOG.debug("Received response: " + exchange + " with in: " + exchange.getIn());
+    }
+
+    /**
+     * Asserts that the given exchange has an OUT message of the given body value
+     *
+     * @param exchange the exchange which should have an OUT message
+     * @param expected the expected value of the OUT message
+     * @throws InvalidPayloadException is thrown if the payload is not the expected class type
+     */
+    public static void assertOutMessageBodyEquals(Exchange exchange, Object expected) throws InvalidPayloadException {
+        assertNotNull("Should have a response exchange!", exchange);
+
+        Object actual;
+        if (expected == null) {
+            actual = ExchangeHelper.getMandatoryOutBody(exchange);
+            assertEquals("output body of: " + exchange, expected, actual);
+        } else {
+            actual = ExchangeHelper.getMandatoryOutBody(exchange, expected.getClass());
+        }
+        assertEquals("output body of: " + exchange, expected, actual);
+
+        LOG.debug("Received response: " + exchange + " with out: " + exchange.getOut());
+    }
+
+    public static Object assertMessageHeader(Message message, String name, Object expected) {
+        Object value = message.getHeader(name);
+        assertEquals("Header: " + name + " on Message: " + message, expected, value);
+        return value;
+    }
+
+    /**
+     * Asserts that the given expression when evaluated returns the given answer
+     */
+    public static Object assertExpression(Expression expression, Exchange exchange, Object expected) {
+        Object value;
+        if (expected != null) {
+            value = expression.evaluate(exchange, expected.getClass());
+        } else {
+            value = expression.evaluate(exchange, Object.class);
+        }
+
+        LOG.debug("Evaluated expression: " + expression + " on exchange: " + exchange + " result: " + value);
+
+        assertEquals("Expression: " + expression + " on Exchange: " + exchange, expected, value);
+        return value;
+    }
+
+    /**
+     * Asserts that the predicate returns the expected value on the exchange
+     */
+    public static void assertPredicateMatches(Predicate predicate, Exchange exchange) {
+        assertPredicate(predicate, exchange, true);
+    }
+
+    /**
+     * Asserts that the predicate returns the expected value on the exchange
+     */
+    public static void assertPredicateDoesNotMatch(Predicate predicate, Exchange exchange) {
+        try {
+            PredicateAssertHelper.assertMatches(predicate, "Predicate should match: ", exchange);
+        } catch (AssertionError e) {
+            LOG.debug("Caught expected assertion error: " + e);
+        }
+        assertPredicate(predicate, exchange, false);
+    }
+
+    /**
+     * Asserts that the predicate returns the expected value on the exchange
+     */
+    public static boolean assertPredicate(final Predicate predicate, Exchange exchange, boolean expected) {
+        if (expected) {
+            PredicateAssertHelper.assertMatches(predicate, "Predicate failed: ", exchange);
+        }
+        boolean value = predicate.matches(exchange);
+
+        LOG.debug("Evaluated predicate: " + predicate + " on exchange: " + exchange + " result: " + value);
+
+        assertEquals("Predicate: " + predicate + " on Exchange: " + exchange, expected, value);
+        return value;
+    }
+
+    /**
+     * Resolves an endpoint and asserts that it is found
+     */
+    public static Endpoint resolveMandatoryEndpoint(CamelContext context, String uri) {
+        Endpoint endpoint = context.getEndpoint(uri);
+
+        assertNotNull("No endpoint found for URI: " + uri, endpoint);
+
+        return endpoint;
+    }
+
+    /**
+     * Resolves an endpoint and asserts that it is found
+     */
+    public static <T extends Endpoint> T resolveMandatoryEndpoint(CamelContext context, String uri,
+                                                              Class<T> endpointType) {
+        T endpoint = context.getEndpoint(uri, endpointType);
+
+        assertNotNull("No endpoint found for URI: " + uri, endpoint);
+
+        return endpoint;
+    }
+
+    /**
+     * Creates an exchange with the given body
+     */
+    protected Exchange createExchangeWithBody(CamelContext camelContext, Object body) {
+        Exchange exchange = new DefaultExchange(camelContext);
+        Message message = exchange.getIn();        
+        message.setHeader("testClass", getClass().getName());
+        message.setBody(body);
+        return exchange;
+    }
+
+    public static <T> T assertOneElement(List<T> list) {
+        assertEquals("Size of list should be 1: " + list, 1, list.size());
+        return list.get(0);
+    }
+
+    /**
+     * Asserts that a list is of the given size
+     */
+    public static <T> List<T> assertListSize(List<T> list, int size) {
+        return assertListSize("List", list, size);
+    }
+
+    /**
+     * Asserts that a list is of the given size
+     */
+    public static <T> List<T> assertListSize(String message, List<T> list, int size) {
+        assertEquals(message + " should be of size: "
+                + size + " but is: " + list, size, list.size());
+        return list;
+    }
+
+    /**
+     * Asserts that a list is of the given size
+     */
+    public static <T> Collection<T> assertCollectionSize(Collection<T> list, int size) {
+        return assertCollectionSize("List", list, size);
+    }
+
+    /**
+     * Asserts that a list is of the given size
+     */
+    public static <T> Collection<T> assertCollectionSize(String message, Collection<T> list, int size) {
+        assertEquals(message + " should be of size: "
+                + size + " but is: " + list, size, list.size());
+        return list;
+    }
+
+    /**
+     * A helper method to create a list of Route objects for a given route builder
+     */
+    public static List<Route> getRouteList(RouteBuilder builder) throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        context.addRoutes(builder);
+        context.start();
+        List<Route> answer = context.getRoutes();
+        context.stop();
+        return answer;
+    }
+
+    /**
+     * Asserts that the text contains the given string
+     *
+     * @param text the text to compare
+     * @param containedText the text which must be contained inside the other text parameter
+     */
+    public static void assertStringContains(String text, String containedText) {
+        assertNotNull("Text should not be null!", text);
+        assertTrue("Text: " + text + " does not contain: " + containedText, text.contains(containedText));
+    }
+
+    /**
+     * If a processor is wrapped with a bunch of DelegateProcessor or DelegateAsyncProcessor objects
+     * this call will drill through them and return the wrapped Processor.
+     */
+    public static Processor unwrap(Processor processor) {
+        while (true) {
+            if (processor instanceof DelegateProcessor) {
+                processor = ((DelegateProcessor)processor).getProcessor();
+            } else {
+                return processor;
+            }
+        }
+    }
+
+    /**
+     * If a processor is wrapped with a bunch of DelegateProcessor or DelegateAsyncProcessor objects
+     * this call will drill through them and return the Channel.
+     * <p/>
+     * Returns null if no channel is found.
+     */
+    public static Channel unwrapChannel(Processor processor) {
+        while (true) {
+            if (processor instanceof Channel) {
+                return (Channel) processor;
+            } else if (processor instanceof DelegateProcessor) {
+                processor = ((DelegateProcessor)processor).getProcessor();
+            } else {
+                return null;
+            }
+        }
+    }
+
+    /**
+     * Recursively delete a directory, useful to zapping test data
+     *
+     * @param file the directory to be deleted
+     */
+    public static void deleteDirectory(String file) {
+        deleteDirectory(new File(file));
+    }
+
+    /**
+     * Recursively delete a directory, useful to zapping test data
+     *
+     * @param file the directory to be deleted
+     */
+    public static void deleteDirectory(File file) {
+        if (file.isDirectory()) {
+            File[] files = file.listFiles();
+            for (int i = 0; i < files.length; i++) {
+                deleteDirectory(files[i]);
+            }
+        }
+        file.delete();
+    }
+
+    /**
+     * create the directory
+     *
+     * @param file the directory to be created
+     */
+    public static void createDirectory(String file) {
+        File dir = new File(file);
+        dir.mkdirs();
+    }
+
+    /**
+     * To be used for folder/directory comparison that works across different platforms such
+     * as Window, Mac and Linux.
+     */
+    public static void assertDirectoryEquals(String expected, String actual) {
+        assertDirectoryEquals(null, expected, actual);
+    }
+
+    /**
+     * To be used for folder/directory comparison that works across different platforms such
+     * as Window, Mac and Linux.
+     */
+    public static void assertDirectoryEquals(String message, String expected, String actual) {
+        // must use single / as path separators
+        String expectedPath = expected.replace('\\', '/');
+        String actualPath = actual.replace('\\', '/');
+
+        if (message != null) {
+            assertEquals(message, expectedPath, actualPath);
+        } else {
+            assertEquals(expectedPath, actualPath);
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date