camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r773215 - in /camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel: ContextTestSupport.java TestSupport.java builder/ContextErrorHandlerTest.java builder/RouteBuilderTest.java
Date Sat, 09 May 2009 12:18:58 GMT
Author: ningjiang
Date: Sat May  9 12:18:57 2009
New Revision: 773215

URL: http://svn.apache.org/viewvc?rev=773215&view=rev
Log:
Merged revisions 773199 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r773199 | ningjiang | 2009-05-09 18:58:36 +0800 (Sat, 09 May 2009) | 1 line
  
  CAMEL-1593 make the utils method in TestSupport to be public static
........

Modified:
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/TestSupport.java
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ContextErrorHandlerTest.java
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java

Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java?rev=773215&r1=773214&r2=773215&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
Sat May  9 12:18:57 2009
@@ -29,6 +29,8 @@
 import org.apache.camel.spi.Language;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.jndi.JndiTest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * A useful base class which creates a {@link CamelContext} with some routes
@@ -37,6 +39,7 @@
  * @version $Revision$
  */
 public abstract class ContextTestSupport extends TestSupport {
+    
     protected CamelContext context;
     protected ProducerTemplate<Exchange> template;
     private boolean useRouteBuilder = true;

Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/TestSupport.java?rev=773215&r1=773214&r2=773215&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/TestSupport.java Sat
May  9 12:18:57 2009
@@ -17,6 +17,7 @@
 package org.apache.camel;
 
 import java.io.File;
+import java.util.Collection;
 import java.util.List;
 
 import junit.framework.TestCase;
@@ -36,24 +37,26 @@
  *
  * @version $Revision$
  */
-public abstract class TestSupport extends TestCase {
-
+public abstract class TestSupport extends TestCase {    
+    
+    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 <E extends Exchange> ValueBuilder<E> header(String name) {
+
+    public static <E extends Exchange> ValueBuilder<E> header(String name) {
   
         return Builder.header(name);
     }
-
+    
     /**
      * Returns a predicate and value builder for the inbound body on an exchange
      */
-    public ValueBuilder body() {
+    public static ValueBuilder body() {
         return Builder.body();
     }
 
@@ -61,7 +64,7 @@
      * Returns a predicate and value builder for the inbound message body as a
      * specific type
      */
-    public <T> ValueBuilder bodyAs(Class<T> type) {
+    public static <T> ValueBuilder bodyAs(Class<T> type) {
         return Builder.bodyAs(type);
     }
 
@@ -69,7 +72,7 @@
      * Returns a predicate and value builder for the outbound body on an
      * exchange
      */
-    public ValueBuilder outBody() {
+    public static ValueBuilder outBody() {
         return Builder.outBody();
     }
 
@@ -77,7 +80,7 @@
      * Returns a predicate and value builder for the outbound message body as a
      * specific type
      */
-    public <T> ValueBuilder outBodyAs(Class<T> type) {
+    public static <T> ValueBuilder outBodyAs(Class<T> type) {
         return Builder.outBodyAs(type);
     }
 
@@ -85,7 +88,7 @@
      * Returns a predicate and value builder for the fault body on an
      * exchange
      */
-    public ValueBuilder faultBody() {
+    public static ValueBuilder faultBody() {
         return Builder.faultBody();
     }
 
@@ -93,35 +96,36 @@
      * Returns a predicate and value builder for the fault message body as a
      * specific type
      */
-    public <T> ValueBuilder faultBodyAs(Class<T> type) {
+    public static <T> ValueBuilder faultBodyAs(Class<T> type) {
         return Builder.faultBodyAs(type);
     }
 
     /**
      * Returns a value builder for the given system property
      */
-    public ValueBuilder systemProperty(String name) {
+    public static ValueBuilder systemProperty(String name) {
         return Builder.systemProperty(name);
     }
 
     /**
      * Returns a value builder for the given system property
      */
-    public ValueBuilder systemProperty(String name, String defaultValue) {
+    public static ValueBuilder systemProperty(String name, String defaultValue) {
         return Builder.systemProperty(name, defaultValue);
     }
 
     // Assertions
     // -----------------------------------------------------------------------
 
-    protected <T> T assertIsInstanceOf(Class<T> expectedType, Object value) {
+    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);
     }
 
-    protected void assertEndpointUri(Endpoint<Exchange> endpoint, String uri) {
+
+    public static void assertEndpointUri(Endpoint<Exchange> endpoint, String uri) {
         assertNotNull("Endpoint is null when expecting endpoint for: " + uri, endpoint);
         assertEquals("Endoint uri for: " + endpoint, uri, endpoint.getEndpointUri());
     }
@@ -129,14 +133,14 @@
     /**
      * Asserts the In message on the exchange contains the expected value
      */
-    protected Object assertInMessageHeader(Exchange exchange, String name, Object expected)
{
+    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
      */
-    protected Object assertOutMessageHeader(Exchange exchange, String name, Object expected)
{
+    public static Object assertOutMessageHeader(Exchange exchange, String name, Object expected)
{
         return assertMessageHeader(exchange.getOut(), name, expected);
     }
 
@@ -147,7 +151,7 @@
      * @param expected the expected value of the OUT message
      * @throws InvalidPayloadException is thrown if the payload is not the expected class
type
      */
-    protected void assertInMessageBodyEquals(Exchange exchange, Object expected) throws InvalidPayloadException
{
+    public static void assertInMessageBodyEquals(Exchange exchange, Object expected) throws
InvalidPayloadException {
         assertNotNull("Should have a response exchange!", exchange);
 
         Object actual;
@@ -159,7 +163,7 @@
         }
         assertEquals("in body of: " + exchange, expected, actual);
 
-        log.debug("Received response: " + exchange + " with in: " + exchange.getIn());
+        LOG.debug("Received response: " + exchange + " with in: " + exchange.getIn());
     }
 
     /**
@@ -169,7 +173,7 @@
      * @param expected the expected value of the OUT message
      * @throws InvalidPayloadException is thrown if the payload is not the expected class
type
      */
-    protected void assertOutMessageBodyEquals(Exchange exchange, Object expected) throws
InvalidPayloadException {
+    public static void assertOutMessageBodyEquals(Exchange exchange, Object expected) throws
InvalidPayloadException {
         assertNotNull("Should have a response exchange!", exchange);
 
         Object actual;
@@ -181,10 +185,10 @@
         }
         assertEquals("output body of: " + exchange, expected, actual);
 
-        log.debug("Received response: " + exchange + " with out: " + exchange.getOut());
+        LOG.debug("Received response: " + exchange + " with out: " + exchange.getOut());
     }
 
-    protected Object assertMessageHeader(Message message, String name, Object expected) {
+    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;
@@ -193,7 +197,7 @@
     /**
      * Asserts that the given expression when evaluated returns the given answer
      */
-    protected Object assertExpression(Expression expression, Exchange exchange, Object expected)
{
+    public static Object assertExpression(Expression expression, Exchange exchange, Object
expected) {
         Object value = expression.evaluate(exchange);
 
         // lets try convert to the type of the expected
@@ -201,7 +205,7 @@
             value = ExchangeHelper.convertToType(exchange, expected.getClass(), value);
         }
 
-        log.debug("Evaluated expression: " + expression + " on exchange: " + exchange + "
result: " + value);
+        LOG.debug("Evaluated expression: " + expression + " on exchange: " + exchange + "
result: " + value);
 
         assertEquals("Expression: " + expression + " on Exchange: " + exchange, expected,
value);
         return value;
@@ -210,18 +214,18 @@
     /**
      * Asserts that the predicate returns the expected value on the exchange
      */
-    protected void assertPredicateMatches(Predicate predicate, Exchange exchange) {
+    public static void assertPredicateMatches(Predicate predicate, Exchange exchange) {
         assertPredicate(predicate, exchange, true);
     }
 
     /**
      * Asserts that the predicate returns the expected value on the exchange
      */
-    protected void assertPredicateDoesNotMatch(Predicate predicate, Exchange exchange) {
+    public static void assertPredicateDoesNotMatch(Predicate predicate, Exchange exchange)
{
         try {
             predicate.assertMatches("Predicate should match", exchange);
         } catch (AssertionError e) {
-            log.debug("Caught expected assertion error: " + e);
+            LOG.debug("Caught expected assertion error: " + e);
         }
         assertPredicate(predicate, exchange, false);
     }
@@ -229,13 +233,14 @@
     /**
      * Asserts that the predicate returns the expected value on the exchange
      */
-    protected boolean assertPredicate(Predicate predicate, Exchange exchange, boolean expected)
{
+
+    public static boolean assertPredicate(Predicate predicate, Exchange exchange, boolean
expected) {
         if (expected) {
             predicate.assertMatches("Predicate failed", exchange);
         }
         boolean value = predicate.matches(exchange);
 
-        log.debug("Evaluated predicate: " + predicate + " on exchange: " + exchange + " result:
" + value);
+        LOG.debug("Evaluated predicate: " + predicate + " on exchange: " + exchange + " result:
" + value);
 
         assertEquals("Predicate: " + predicate + " on Exchange: " + exchange, expected, value);
         return value;
@@ -244,7 +249,7 @@
     /**
      * Resolves an endpoint and asserts that it is found
      */
-    protected Endpoint resolveMandatoryEndpoint(CamelContext context, String uri) {
+    public static Endpoint resolveMandatoryEndpoint(CamelContext context, String uri) {
         Endpoint endpoint = context.getEndpoint(uri);
 
         assertNotNull("No endpoint found for URI: " + uri, endpoint);
@@ -255,7 +260,7 @@
     /**
      * Resolves an endpoint and asserts that it is found
      */
-    protected <T extends Endpoint> T resolveMandatoryEndpoint(CamelContext context,
String uri,
+    public static <T extends Endpoint> T resolveMandatoryEndpoint(CamelContext context,
String uri,
                                                               Class<T> endpointType)
{
         T endpoint = context.getEndpoint(uri, endpointType);
 
@@ -276,7 +281,7 @@
         return exchange;
     }
 
-    protected <T> T assertOneElement(List<T> list) {
+    public static <T> T assertOneElement(List<T> list) {
         assertEquals("Size of list should be 1: " + list, 1, list.size());
         return list.get(0);
     }
@@ -284,15 +289,39 @@
     /**
      * Asserts that a list is of the given size
      */
-    protected <T> List<T> assertListSize(List<T> list, int size) {
-        assertEquals("List should be of size: " + size + " but is: " + list, size, list.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
      */
-    protected List<Route> getRouteList(RouteBuilder builder) throws Exception {
+    public static List<Route> getRouteList(RouteBuilder builder) throws Exception {
         CamelContext context = new DefaultCamelContext();
         context.addRoutes(builder);
         context.start();
@@ -307,7 +336,7 @@
      * @param text the text to compare
      * @param containedText the text which must be contained inside the other text parameter
      */
-    protected void assertStringContains(String text, String containedText) {
+    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));
     }
@@ -316,7 +345,7 @@
      * If a processor is wrapped with a bunch of DelegateProcessor or DelegateAsyncProcessor
objects
      * this call will drill through them and return the wrapped Processor.
      */
-    protected Processor unwrap(Processor processor) {
+    public static Processor unwrap(Processor processor) {
         while (true) {
             if (processor instanceof DelegateAsyncProcessor) {
                 processor = ((DelegateAsyncProcessor)processor).getProcessor();
@@ -326,7 +355,7 @@
                 return processor;
             }
         }
-    }
+    }    
 
     /**
      * Recursively delete a directory, useful to zapping test data

Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ContextErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ContextErrorHandlerTest.java?rev=773215&r1=773214&r2=773215&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ContextErrorHandlerTest.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ContextErrorHandlerTest.java
Sat May  9 12:18:57 2009
@@ -52,7 +52,7 @@
         // do nothing here
     }
 
-    protected List<Route> getRouteList(RouteBuilder builder) throws Exception {
+    protected List<Route> getRouteListWithCurrentContext(RouteBuilder builder) throws
Exception {
         context.addRoutes(builder);
         context.start();
         List<Route> answer = context.getRoutes();
@@ -69,7 +69,7 @@
             }
         };
 
-        List<Route> list = getRouteList(builder);
+        List<Route> list = getRouteListWithCurrentContext(builder);
         assertEquals("Number routes created" + list, 1, list.size());
         for (Route route : list) {
             Endpoint key = route.getEndpoint();
@@ -94,7 +94,7 @@
             }
         };
 
-        List<Route> list = getRouteList(builder);
+        List<Route> list = getRouteListWithCurrentContext(builder);
         assertEquals("Number routes created" + list, 2, list.size());
         for (Route route : list) {
 

Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java?rev=773215&r1=773214&r2=773215&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java
Sat May  9 12:18:57 2009
@@ -25,6 +25,7 @@
 import org.apache.camel.Producer;
 import org.apache.camel.Route;
 import org.apache.camel.TestSupport;
+import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.EventDrivenConsumerRoute;
 import org.apache.camel.management.InstrumentationProcessor;
 import org.apache.camel.management.JmxSystemPropertyKeys;
@@ -48,7 +49,7 @@
 public class RouteBuilderTest extends TestSupport {
     protected Processor myProcessor = new MyProcessor();
     protected DelegateProcessor interceptor1;
-    protected DelegateProcessor interceptor2;
+    protected DelegateProcessor interceptor2;   
 
     protected List<Route> buildSimpleRoute() throws Exception {
         // START SNIPPET: e1



Mime
View raw message