Return-Path: Delivered-To: apmail-camel-commits-archive@www.apache.org Received: (qmail 25626 invoked from network); 9 May 2009 12:19:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 May 2009 12:19:20 -0000 Received: (qmail 50297 invoked by uid 500); 9 May 2009 12:19:20 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 50255 invoked by uid 500); 9 May 2009 12:19:20 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 50246 invoked by uid 99); 9 May 2009 12:19:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 May 2009 12:19:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 May 2009 12:19:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4689D2388A23; Sat, 9 May 2009 12:18:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@camel.apache.org From: ningjiang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090509121858.4689D2388A23@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 ValueBuilder header(String name) { + + public static ValueBuilder 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 ValueBuilder bodyAs(Class type) { + public static ValueBuilder bodyAs(Class 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 ValueBuilder outBodyAs(Class type) { + public static ValueBuilder outBodyAs(Class 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 ValueBuilder faultBodyAs(Class type) { + public static ValueBuilder faultBodyAs(Class 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 assertIsInstanceOf(Class expectedType, Object value) { + public static T assertIsInstanceOf(Class 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 endpoint, String uri) { + + public static void assertEndpointUri(Endpoint endpoint, String uri) { assertNotNull("Endpoint is null when expecting endpoint for: " + uri, endpoint); assertEquals("Endoint uri for: " + endpoint, uri, endpoint.getEndpointUri()); } @@ -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 resolveMandatoryEndpoint(CamelContext context, String uri, + public static T resolveMandatoryEndpoint(CamelContext context, String uri, Class endpointType) { T endpoint = context.getEndpoint(uri, endpointType); @@ -276,7 +281,7 @@ return exchange; } - protected T assertOneElement(List list) { + public static T assertOneElement(List 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 List assertListSize(List list, int size) { - assertEquals("List should be of size: " + size + " but is: " + list, size, list.size()); + public static List assertListSize(List list, int size) { + return assertListSize("List", list, size); + } + + /** + * Asserts that a list is of the given size + */ + public static List assertListSize(String message, List 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 Collection assertCollectionSize(Collection list, int size) { + return assertCollectionSize("List", list, size); + } + + /** + * Asserts that a list is of the given size + */ + public static Collection assertCollectionSize(String message, Collection 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 getRouteList(RouteBuilder builder) throws Exception { + public static List 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 getRouteList(RouteBuilder builder) throws Exception { + protected List getRouteListWithCurrentContext(RouteBuilder builder) throws Exception { context.addRoutes(builder); context.start(); List answer = context.getRoutes(); @@ -69,7 +69,7 @@ } }; - List list = getRouteList(builder); + List list = getRouteListWithCurrentContext(builder); assertEquals("Number routes created" + list, 1, list.size()); for (Route route : list) { Endpoint key = route.getEndpoint(); @@ -94,7 +94,7 @@ } }; - List list = getRouteList(builder); + List 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 buildSimpleRoute() throws Exception { // START SNIPPET: e1