You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/04/02 13:36:32 UTC
svn commit: r1088001 [1/2] - in /camel/trunk/components: ./ camel-test/
camel-test/src/test/resources/ camel-testng/ camel-testng/src/
camel-testng/src/main/ camel-testng/src/main/java/
camel-testng/src/main/java/org/ camel-testng/src/main/java/org/apa...
Author: davsclaus
Date: Sat Apr 2 11:36:31 2011
New Revision: 1088001
URL: http://svn.apache.org/viewvc?rev=1088001&view=rev
Log:
CAMEL-3699: Added camel-testng component. Thanks to Michael Shorter for the patch.
Added:
camel/trunk/components/camel-testng/ (with props)
camel/trunk/components/camel-testng/pom.xml (with props)
camel/trunk/components/camel-testng/src/
camel/trunk/components/camel-testng/src/main/
camel/trunk/components/camel-testng/src/main/java/
camel/trunk/components/camel-testng/src/main/java/org/
camel/trunk/components/camel-testng/src/main/java/org/apache/
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/AvailablePortFinder.java (with props)
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java (with props)
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java (with props)
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/ExchangeTestSupport.java (with props)
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java (with props)
camel/trunk/components/camel-testng/src/main/resources/
camel/trunk/components/camel-testng/src/main/resources/META-INF/
camel/trunk/components/camel-testng/src/main/resources/META-INF/LICENSE.txt (with props)
camel/trunk/components/camel-testng/src/main/resources/META-INF/NOTICE.txt (with props)
camel/trunk/components/camel-testng/src/test/
camel/trunk/components/camel-testng/src/test/java/
camel/trunk/components/camel-testng/src/test/java/org/
camel/trunk/components/camel-testng/src/test/java/org/apache/
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTest.java (with props)
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTestNGTest.java (with props)
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTest.java (with props)
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTestNGTest.java (with props)
camel/trunk/components/camel-testng/src/test/resources/
camel/trunk/components/camel-testng/src/test/resources/jndi.properties (with props)
camel/trunk/components/camel-testng/src/test/resources/log4j.properties (with props)
Modified:
camel/trunk/components/camel-test/pom.xml
camel/trunk/components/camel-test/src/test/resources/log4j.properties
camel/trunk/components/pom.xml
Modified: camel/trunk/components/camel-test/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/pom.xml?rev=1088001&r1=1088000&r2=1088001&view=diff
==============================================================================
--- camel/trunk/components/camel-test/pom.xml (original)
+++ camel/trunk/components/camel-test/pom.xml Sat Apr 2 11:36:31 2011
@@ -29,7 +29,7 @@
<artifactId>camel-test</artifactId>
<packaging>bundle</packaging>
<name>Camel :: Test</name>
- <description>Camel Testing Library</description>
+ <description>Camel Testing Library using JUnit</description>
<properties>
<camel.osgi.export.pkg>org.apache.camel.test.*</camel.osgi.export.pkg>
Modified: camel/trunk/components/camel-test/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/test/resources/log4j.properties?rev=1088001&r1=1088000&r2=1088001&view=diff
==============================================================================
--- camel/trunk/components/camel-test/src/test/resources/log4j.properties (original)
+++ camel/trunk/components/camel-test/src/test/resources/log4j.properties Sat Apr 2 11:36:31 2011
@@ -16,7 +16,7 @@
## ------------------------------------------------------------------------
#
-# The logging properties used for eclipse testing, We want to see debug output on the console.
+# The logging properties used for testing
#
log4j.rootLogger=INFO, file
@@ -33,4 +33,4 @@ log4j.appender.out.layout.ConversionPatt
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n
-log4j.appender.file.file=target/test.log
+log4j.appender.file.file=target/camel-test.log
Propchange: camel/trunk/components/camel-testng/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Apr 2 11:36:31 2011
@@ -0,0 +1,9 @@
+.project
+.checkstyle
+.pmd
+.classpath
+target
+.settings
+eclipse-classes
+*.i??
+classes
Added: camel/trunk/components/camel-testng/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/pom.xml?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/pom.xml (added)
+++ camel/trunk/components/camel-testng/pom.xml Sat Apr 2 11:36:31 2011
@@ -0,0 +1,67 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>2.8-SNAPSHOT</version>
+ <relativePath>../../parent</relativePath>
+ </parent>
+
+ <artifactId>camel-testng</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: TestNG</name>
+ <description>Camel Testing Library using TestNG</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.testng.*</camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ </dependency>
+
+ <!-- optional dependencies for running tests -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
Propchange: camel/trunk/components/camel-testng/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/pom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-testng/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/AvailablePortFinder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/AvailablePortFinder.java?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/AvailablePortFinder.java (added)
+++ camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/AvailablePortFinder.java Sat Apr 2 11:36:31 2011
@@ -0,0 +1,113 @@
+/**
+ * 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.testng;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.ServerSocket;
+import java.util.NoSuchElementException;
+
+/**
+ * Finds currently available server ports.
+ *
+ * @see <a href="http://www.iana.org/assignments/port-numbers">IANA.org</a>
+ */
+public final class AvailablePortFinder {
+ /**
+ * The minimum server port number. Set at 1024 to avoid returning privileged
+ * port numbers.
+ */
+ public static final int MIN_PORT_NUMBER = 1024;
+
+ /**
+ * The maximum server port number.
+ */
+ public static final int MAX_PORT_NUMBER = 49151;
+
+ /**
+ * Creates a new instance.
+ */
+ private AvailablePortFinder() {
+ // Do nothing
+ }
+
+ /**
+ * Gets the next available port starting at the lowest port number.
+ *
+ * @throws NoSuchElementException if there are no ports available
+ */
+ public static int getNextAvailable() {
+ return getNextAvailable(MIN_PORT_NUMBER);
+ }
+
+ /**
+ * Gets the next available port starting at a port.
+ *
+ * @param fromPort the port to scan for availability
+ * @throws NoSuchElementException if there are no ports available
+ */
+ public static int getNextAvailable(int fromPort) {
+ if (fromPort < MIN_PORT_NUMBER || fromPort > MAX_PORT_NUMBER) {
+ throw new IllegalArgumentException("Invalid start port: " + fromPort);
+ }
+
+ for (int i = fromPort; i <= MAX_PORT_NUMBER; i++) {
+ if (available(i)) {
+ return i;
+ }
+ }
+
+ throw new NoSuchElementException("Could not find an available port above " + fromPort);
+ }
+
+ /**
+ * Checks to see if a specific port is available.
+ *
+ * @param port the port to check for availability
+ */
+ public static boolean available(int port) {
+ if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) {
+ throw new IllegalArgumentException("Invalid start port: " + port);
+ }
+
+ ServerSocket ss = null;
+ DatagramSocket ds = null;
+ try {
+ ss = new ServerSocket(port);
+ ss.setReuseAddress(true);
+ ds = new DatagramSocket(port);
+ ds.setReuseAddress(true);
+ return true;
+ } catch (IOException e) {
+ // Do nothing
+ } finally {
+ if (ds != null) {
+ ds.close();
+ }
+
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
+ /* should not be thrown */
+ }
+ }
+ }
+
+ return false;
+ }
+}
Propchange: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/AvailablePortFinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/AvailablePortFinder.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java (added)
+++ camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java Sat Apr 2 11:36:31 2011
@@ -0,0 +1,162 @@
+/**
+ * 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.testng;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
+import org.apache.camel.impl.scan.AssignableToPackageScanFilter;
+import org.apache.camel.impl.scan.InvertingPackageScanFilter;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.util.CastUtils;
+import org.apache.camel.util.ObjectHelper;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+
+/**
+ * @version $Revision$
+ */
+public abstract class CamelSpringTestSupport extends CamelTestSupport {
+ protected AbstractApplicationContext applicationContext;
+ protected abstract AbstractApplicationContext createApplicationContext();
+
+ @Override
+ @BeforeTest
+ public void setUp() throws Exception {
+ applicationContext = createApplicationContext();
+ assertNotNull(applicationContext, "Should have created a valid spring context");
+ super.setUp();
+ }
+
+ @Override
+ @AfterTest
+ public void tearDown() throws Exception {
+ super.tearDown();
+ if (applicationContext != null) {
+ applicationContext.destroy();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static class ExcludingPackageScanClassResolver extends DefaultPackageScanClassResolver {
+
+ public void setExcludedClasses(Set<Class<?>> excludedClasses) {
+ excludedClasses = excludedClasses == null ? Collections.EMPTY_SET : excludedClasses;
+ addFilter(new InvertingPackageScanFilter(new AssignableToPackageScanFilter(excludedClasses)));
+ }
+
+ }
+
+ /**
+ * Create a parent context that initializes a
+ * {@link org.apache.camel.spi.PackageScanClassResolver} to exclude a set of given classes from
+ * being resolved. Typically this is used at test time to exclude certain routes,
+ * which might otherwise be just noisy, from being discovered and initialized.
+ * <p/>
+ * To use this filtering mechanism it is necessary to provide the
+ * {@link ApplicationContext} returned from here as the parent context to
+ * your test context e.g.
+ *
+ * <pre>
+ * protected AbstractXmlApplicationContext createApplicationContext() {
+ * return new ClassPathXmlApplicationContext(new String[] {"test-context.xml"}, getRouteExcludingApplicationContext());
+ * }
+ * </pre>
+ *
+ * This will, in turn, call the template methods <code>excludedRoutes</code>
+ * and <code>excludedRoute</code> to determine the classes to be excluded from scanning.
+ *
+ * @return ApplicationContext a parent {@link ApplicationContext} configured
+ * to exclude certain classes from package scanning
+ */
+ protected ApplicationContext getRouteExcludingApplicationContext() {
+ GenericApplicationContext routeExcludingContext = new GenericApplicationContext();
+ routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
+ routeExcludingContext.refresh();
+
+ ExcludingPackageScanClassResolver excludingResolver = (ExcludingPackageScanClassResolver)routeExcludingContext.getBean("excludingResolver");
+ List<Class<?>> excluded = CastUtils.cast(Arrays.asList(excludeRoutes()));
+ excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));
+
+ return routeExcludingContext;
+ }
+
+ /**
+ * Template method used to exclude {@link org.apache.camel.Route} from the test time context
+ * route scanning
+ *
+ * @return Class[] the classes to be excluded from test time context route scanning
+ */
+ protected Class<?>[] excludeRoutes() {
+ Class<?> excludedRoute = excludeRoute();
+ return excludedRoute != null ? new Class[] {excludedRoute} : new Class[0];
+ }
+
+ /**
+ * Template method used to exclude a {@link org.apache.camel.Route} from the test camel context
+ */
+ protected Class<?> excludeRoute() {
+ return null;
+ }
+
+ /**
+ * 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(value, "No spring bean found for name <" + name + ">");
+ 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(routes, "Should have some routes defined");
+ assertTrue(routes.size() >= routeCount, "Should have at least one route");
+ }
+ 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-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java (added)
+++ camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java Sat Apr 2 11:36:31 2011
@@ -0,0 +1,441 @@
+/**
+ * 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.testng;
+
+import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+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.BreakpointSupport;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultDebugger;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.management.JmxSystemPropertyKeys;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.spi.Language;
+import org.apache.camel.spring.CamelBeanPostProcessor;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+
+/**
+ * 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 volatile CamelContext context;
+ protected volatile ProducerTemplate template;
+ protected volatile ConsumerTemplate consumer;
+ private boolean useRouteBuilder = true;
+ private Service camelContextService;
+ private final DebugBreakpoint breakpoint = new DebugBreakpoint();
+
+ 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;
+ }
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ log.debug("setUp test");
+ if (!useJmx()) {
+ disableJMX();
+ } else {
+ enableJMX();
+ }
+
+ context = createCamelContext();
+ assertValidContext(context);
+
+ // reduce default shutdown timeout to avoid waiting for 300 seconds
+ context.getShutdownStrategy().setTimeout(getShutdownTimeout());
+
+ // set debugger
+ context.setDebugger(new DefaultDebugger());
+ context.getDebugger().addBreakpoint(breakpoint);
+ // note: when stopping CamelContext it will automatic remove the breakpoint
+
+ template = context.createProducerTemplate();
+ template.start();
+ consumer = context.createConsumerTemplate();
+ consumer.start();
+
+ 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);
+ }
+ log.debug("Routing Rules are: " + context.getRoutes());
+ }
+
+ @AfterMethod
+ public void tearDown() throws Exception {
+ log.info("Testing done: " + this);
+
+ log.debug("tearDown test");
+ if (consumer != null) {
+ consumer.stop();
+ }
+ if (template != null) {
+ template.stop();
+ }
+ stopCamelContext();
+ }
+
+ /**
+ * Returns the timeout to use when shutting down (unit in seconds).
+ * <p/>
+ * Will default use 10 seconds.
+ *
+ * @return the timeout to use
+ */
+ protected int getShutdownTimeout() {
+ return 10;
+ }
+
+ /**
+ * Whether or not JMX should be used during testing.
+ *
+ * @return <tt>false</tt> by default.
+ */
+ protected boolean useJmx() {
+ return false;
+ }
+
+ /**
+ * 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());
+ }
+
+ @SuppressWarnings("unchecked")
+ 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);
+ } else {
+ properties.put("java.naming.factory.initial", "org.apache.camel.util.jndi.CamelInitialContextFactory");
+ }
+ return new InitialContext(new Hashtable(properties));
+ }
+
+ /**
+ * Factory method which derived classes can use to create a {@link 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(expression, "No Expression could be created for text: " + expressionText + " language: " + language);
+
+ 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(predicate, "No Predicate could be created for text: " + expressionText + " language: " + language);
+
+ assertPredicate(predicate, exchange, expected);
+ }
+
+ /**
+ * Asserts that the language name can be resolved
+ */
+ protected Language assertResolveLanguage(String languageName) {
+ Language language = context.resolveLanguage(languageName);
+ assertNotNull(language, "No language found for name: " + languageName);
+ return language;
+ }
+
+ /**
+ * Asserts that all the expectations of the Mock endpoints are valid
+ */
+ protected void assertMockEndpointsSatisfied() throws InterruptedException {
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ /**
+ * Asserts that all the expectations of the Mock endpoints are valid
+ */
+ protected void assertMockEndpointsSatisfied(long timeout, TimeUnit unit) throws InterruptedException {
+ MockEndpoint.assertIsSatisfied(context, timeout, unit);
+ }
+
+ /**
+ * Reset all Mock endpoints.
+ */
+ protected void resetMocks() {
+ MockEndpoint.resetMocks(context);
+ }
+
+ protected void assertValidContext(CamelContext context) {
+ assertNotNull(context, "No context found!");
+ }
+
+ protected <T extends Endpoint> T getMandatoryEndpoint(String uri, Class<T> type) {
+ T endpoint = context.getEndpoint(uri, type);
+ assertNotNull(endpoint, "No endpoint found for uri: " + uri);
+ return endpoint;
+ }
+
+ protected Endpoint getMandatoryEndpoint(String uri) {
+ Endpoint endpoint = context.getEndpoint(uri);
+ assertNotNull(endpoint, "No endpoint found for uri: " + uri);
+ 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");
+ }
+
+ /**
+ * Single step debugs and Camel invokes this method before entering the given processor
+ */
+ protected void debugBefore(Exchange exchange, Processor processor, ProcessorDefinition definition,
+ String id, String label) {
+ }
+
+ /**
+ * Single step debugs and Camel invokes this method after processing the given processor
+ */
+ protected void debugAfter(Exchange exchange, Processor processor, ProcessorDefinition definition,
+ String id, String label, long timeTaken) {
+ }
+
+ /**
+ * To easily debug by overriding the <tt>debugBefore</tt> and <tt>debugAfter</tt> methods.
+ */
+ private class DebugBreakpoint extends BreakpointSupport {
+
+ @Override
+ public void beforeProcess(Exchange exchange, Processor processor, ProcessorDefinition definition) {
+ CamelTestSupport.this.debugBefore(exchange, processor, definition, definition.getId(), definition.getLabel());
+ }
+
+ @Override
+ public void afterProcess(Exchange exchange, Processor processor, ProcessorDefinition definition, long timeTaken) {
+ CamelTestSupport.this.debugAfter(exchange, processor, definition, definition.getId(), definition.getLabel(), timeTaken);
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/ExchangeTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/ExchangeTestSupport.java?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/ExchangeTestSupport.java (added)
+++ camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/ExchangeTestSupport.java Sat Apr 2 11:36:31 2011
@@ -0,0 +1,59 @@
+/**
+ * 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.testng;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.impl.DefaultExchange;
+import org.testng.annotations.BeforeTest;
+
+/**
+ * A base class for a test which requires a {@link org.apache.camel.CamelContext} and
+ * a populated {@link Exchange}
+ *
+ * @version $Revision$
+ */
+public abstract class ExchangeTestSupport extends CamelTestSupport {
+ protected Exchange exchange;
+
+ /**
+ * A factory method to create an Exchange implementation
+ */
+ protected Exchange createExchange() {
+ return new DefaultExchange(context);
+ }
+
+ /**
+ * A strategy method to populate an exchange with some example values for use
+ * by language plugins
+ */
+ protected void populateExchange(Exchange exchange) {
+ Message in = exchange.getIn();
+ in.setHeader("foo", "abc");
+ in.setHeader("bar", 123);
+ in.setBody("<hello id='m123'>world!</hello>");
+ }
+
+ @Override
+ @BeforeTest
+ public void setUp() throws Exception {
+ super.setUp();
+ exchange = createExchange();
+ assertNotNull(exchange, "No exchange created!");
+ populateExchange(exchange);
+ }
+}
Propchange: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/ExchangeTestSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/ExchangeTestSupport.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java (added)
+++ camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java Sat Apr 2 11:36:31 2011
@@ -0,0 +1,489 @@
+/**
+ * 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.testng;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+
+/**
+ * A bunch of useful testing methods
+ *
+ * @version $Revision$
+ */
+public abstract class TestSupport extends Assert {
+ private static final Logger LOG = LoggerFactory.getLogger(TestSupport.class);
+ protected transient Logger log = LoggerFactory.getLogger(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(value, "Expected an instance of type: " + expectedType.getName() + " but was null");
+ assertTrue(expectedType.isInstance(value), "object should be a " + expectedType.getName() +
+ " but was: " + value + " with type: " + value.getClass().getName());
+ return expectedType.cast(value);
+ }
+
+ public static void assertEndpointUri(Endpoint endpoint, String uri) {
+ assertNotNull(endpoint, "Endpoint is null when expecting endpoint for: " + uri);
+ assertEquals(endpoint.getEndpointUri(), uri, "Endoint uri for: " + endpoint);
+ }
+
+ /**
+ * 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(exchange, "Should have a response exchange!");
+
+ Object actual;
+ if (expected == null) {
+ actual = ExchangeHelper.getMandatoryInBody(exchange);
+ assertEquals(actual, expected, "in body of: " + exchange);
+ } else {
+ actual = ExchangeHelper.getMandatoryInBody(exchange, expected.getClass());
+ }
+ assertEquals(actual, expected, "in body of: " + exchange);
+
+ 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(exchange, "Should have a response exchange!");
+
+ Object actual;
+ if (expected == null) {
+ actual = ExchangeHelper.getMandatoryOutBody(exchange);
+ assertEquals(actual, expected, "output body of: " + exchange);
+ } else {
+ actual = ExchangeHelper.getMandatoryOutBody(exchange, expected.getClass());
+ }
+ assertEquals(actual, expected, "output body of: " + exchange);
+
+ 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(value, expected, "Header: " + name + " on Message: " + message);
+ 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(value, expected, "Expression: " + expression + " on Exchange: " + exchange);
+ 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(value, expected, "Predicate: " + predicate + " on Exchange: " + exchange);
+ 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(endpoint, "No endpoint found for URI: " + uri);
+
+ 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(endpoint, "No endpoint found for URI: " + uri);
+
+ 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(list.size(), 1, "Size of list should be 1: " + list);
+ 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(list.size(), size, message + " should be of size: " + size + " but is: " + list);
+ 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(list.size(), size, message + " should be of size: " + size + " but is: " + list);
+ 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, "Text should not be null!");
+ assertTrue(text.contains(containedText), "Text: " + text + " does not contain: " + 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(actualPath, expectedPath, message);
+ } else {
+ assertEquals(actualPath, expectedPath);
+ }
+ }
+
+ /**
+ * To be used to check is a file is found in the file system
+ */
+ public static void assertFileExists(String filename) {
+ File file = new File(filename).getAbsoluteFile();
+ assertTrue(file.exists(), "File " + filename + " should exist");
+ }
+
+ /**
+ * Is this OS the given platform.
+ * <p/>
+ * Uses <tt>os.name</tt> from the system properties to determine the OS.
+ *
+ * @param platform such as Windows
+ * @return <tt>true</tt> if its that platform.
+ */
+ public static boolean isPlatform(String platform) {
+ String osName = System.getProperty("os.name").toLowerCase(Locale.US);
+ return osName.indexOf(platform.toLowerCase(Locale.US)) > -1;
+ }
+
+ /**
+ * Is this Java by the given vendor.
+ * <p/>
+ * Uses <tt>java.vendor</tt> from the system properties to determine the vendor.
+ *
+ * @param vendor such as IBM
+ * @return <tt>true</tt> if its that vendor.
+ */
+ public static boolean isJavaVendor(String vendor) {
+ String javaVendor = System.getProperty("java.vendor").toLowerCase(Locale.US);
+ return javaVendor.indexOf(vendor.toLowerCase(Locale.US)) > -1;
+ }
+
+ /**
+ * Is this Java 1.5
+ *
+ * @return <tt>true</tt> if its Java 1.5, <tt>false</tt> if its not (for example Java 1.6 or better)
+ */
+ public static boolean isJava15() {
+ String javaVersion = System.getProperty("java.version").toLowerCase(Locale.US);
+ return javaVersion.startsWith("1.5");
+ }
+
+}
Propchange: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-testng/src/main/resources/META-INF/LICENSE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/resources/META-INF/LICENSE.txt?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/main/resources/META-INF/LICENSE.txt (added)
+++ camel/trunk/components/camel-testng/src/main/resources/META-INF/LICENSE.txt Sat Apr 2 11:36:31 2011
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
Propchange: camel/trunk/components/camel-testng/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-testng/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-testng/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/resources/META-INF/NOTICE.txt?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/main/resources/META-INF/NOTICE.txt (added)
+++ camel/trunk/components/camel-testng/src/main/resources/META-INF/NOTICE.txt Sat Apr 2 11:36:31 2011
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
Propchange: camel/trunk/components/camel-testng/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTest.java?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTest.java (added)
+++ camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTest.java Sat Apr 2 11:36:31 2011
@@ -0,0 +1,77 @@
+/**
+ * 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.testng.patterns;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.testng.CamelTestSupport;
+
+/**
+ * @version $Revision$
+ */
+public class DebugTest extends CamelTestSupport {
+
+ @Override
+ protected void debugBefore(Exchange exchange, Processor processor,
+ ProcessorDefinition definition, String id, String shortName) {
+ // this method is invoked before we are about to enter the given processor
+ // from your Java editor you can just add a breakpoint in the code line below
+ log.info("Before " + definition + " with body " + exchange.getIn().getBody());
+ }
+
+ public void testDebugger() throws Exception {
+ // set mock expectations
+ getMockEndpoint("mock:a").expectedMessageCount(1);
+ getMockEndpoint("mock:b").expectedMessageCount(1);
+
+ // send a message
+ template.sendBody("direct:start", "World");
+
+ // assert mocks
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testTwo() throws Exception {
+ // set mock expectations
+ getMockEndpoint("mock:a").expectedMessageCount(2);
+ getMockEndpoint("mock:b").expectedMessageCount(2);
+
+ // send a message
+ template.sendBody("direct:start", "World");
+ template.sendBody("direct:start", "Camel");
+
+ // assert mocks
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // this is the route we want to debug
+ from("direct:start")
+ .to("mock:a")
+ .transform(body().prepend("Hello "))
+ .to("mock:b");
+ }
+ };
+ }
+
+}
Propchange: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTestNGTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTestNGTest.java?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTestNGTest.java (added)
+++ camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTestNGTest.java Sat Apr 2 11:36:31 2011
@@ -0,0 +1,79 @@
+/**
+ * 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.testng.patterns;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.testng.CamelTestSupport;
+import org.testng.annotations.Test;
+
+/**
+ * @version $Revision$
+ */
+public class DebugTestNGTest extends CamelTestSupport {
+
+ @Override
+ protected void debugBefore(Exchange exchange, Processor processor,
+ ProcessorDefinition definition, String id, String shortName) {
+ // this method is invoked before we are about to enter the given processor
+ // from your Java editor you can just add a breakpoint in the code line below
+ log.info("Before " + definition + " with body " + exchange.getIn().getBody());
+ }
+
+ @Test
+ public void testDebugger() throws Exception {
+ // set mock expectations
+ getMockEndpoint("mock:a").expectedMessageCount(1);
+ getMockEndpoint("mock:b").expectedMessageCount(1);
+
+ // send a message
+ template.sendBody("direct:start", "World");
+
+ // assert mocks
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testTwo() throws Exception {
+ // set mock expectations
+ getMockEndpoint("mock:a").expectedMessageCount(2);
+ getMockEndpoint("mock:b").expectedMessageCount(2);
+
+ // send a message
+ template.sendBody("direct:start", "World");
+ template.sendBody("direct:start", "Camel");
+
+ // assert mocks
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // this is the route we want to debug
+ from("direct:start")
+ .to("mock:a")
+ .transform(body().prepend("Hello "))
+ .to("mock:b");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTestNGTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugTestNGTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTest.java?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTest.java (added)
+++ camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTest.java Sat Apr 2 11:36:31 2011
@@ -0,0 +1,65 @@
+/**
+ * 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.testng.patterns;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.testng.CamelTestSupport;
+
+/**
+ * Tests filtering using Camel Test
+ *
+ * @version $Revision$
+ */
+public class FilterTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ public void testSendMatchingMessage() throws Exception {
+ String expectedBody = "<matched/>";
+
+ resultEndpoint.expectedBodiesReceived(expectedBody);
+
+ template.sendBodyAndHeader(expectedBody, "foo", "bar");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ public void testSendNotMatchingMessage() throws Exception {
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTestNGTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTestNGTest.java?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTestNGTest.java (added)
+++ camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTestNGTest.java Sat Apr 2 11:36:31 2011
@@ -0,0 +1,68 @@
+/**
+ * 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.testng.patterns;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.testng.CamelTestSupport;
+import org.testng.annotations.Test;
+
+/**
+ * Tests filtering using Camel Test
+ *
+ * @version $Revision$
+ */
+public class FilterTestNGTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ @Test
+ public void testSendMatchingMessage() throws Exception {
+ String expectedBody = "<matched/>";
+
+ resultEndpoint.expectedBodiesReceived(expectedBody);
+
+ template.sendBodyAndHeader(expectedBody, "foo", "bar");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ public void testSendNotMatchingMessage() throws Exception {
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTestNGTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/FilterTestNGTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-testng/src/test/resources/jndi.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/test/resources/jndi.properties?rev=1088001&view=auto
==============================================================================
--- camel/trunk/components/camel-testng/src/test/resources/jndi.properties (added)
+++ camel/trunk/components/camel-testng/src/test/resources/jndi.properties Sat Apr 2 11:36:31 2011
@@ -0,0 +1,22 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# START SNIPPET: jndi
+
+java.naming.factory.initial = org.apache.camel.util.jndi.CamelInitialContextFactory
+
+# END SNIPPET: jndi