You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2013/01/21 21:42:45 UTC
svn commit: r1436603 - in /camel/trunk/components:
camel-cxf/src/test/java/org/apache/camel/component/cxf/util/
camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/
camel-sjms/src/test/java/org/apache/camel/component/sjms/jms/ came...
Author: bvahdat
Date: Mon Jan 21 20:42:44 2013
New Revision: 1436603
URL: http://svn.apache.org/viewvc?rev=1436603&view=rev
Log:
CAMEL-5983: Avoid the negative-tests to behave as false-positive.
Modified:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java
camel/trunk/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/jms/ObjectPoolTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/MixedPropagationTransactedTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMixedTransactedTest.java
Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java?rev=1436603&r1=1436602&r2=1436603&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java Mon Jan 21 20:42:44 2013
@@ -21,6 +21,7 @@ import javax.xml.namespace.QName;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
+import org.apache.camel.Producer;
import org.apache.camel.component.cxf.CxfComponent;
import org.apache.camel.component.cxf.CxfEndpoint;
import org.apache.camel.component.cxf.DataFormat;
@@ -99,30 +100,26 @@ public class CxfEndpointUtilsTest extend
@Test
public void testCheckServiceClassProcedure() throws Exception {
CxfEndpoint endpoint = createEndpoint(getNoServiceClassURI());
- try {
- endpoint.createProducer();
- } catch (IllegalArgumentException exception) {
- assertNotNull("Should get a CamelException here", exception);
- }
+ assertNotNull(endpoint.createProducer());
}
@Test
public void testCheckServiceClassConsumer() throws Exception {
CxfEndpoint endpoint = createEndpoint(getNoServiceClassURI());
try {
- endpoint.createConsumer(new NullProcessor());
+ endpoint.createConsumer(new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ // noop
+ }
+
+ });
+ fail("Should have thrown exception");
} catch (IllegalArgumentException exception) {
assertNotNull("Should get a CamelException here", exception);
assertTrue(exception.getMessage().startsWith("serviceClass must be specified"));
}
}
- class NullProcessor implements Processor {
-
- public void process(Exchange exchange) throws Exception {
- // Do nothing here
- }
-
- }
-
}
Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java?rev=1436603&r1=1436602&r2=1436603&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java Mon Jan 21 20:42:44 2013
@@ -40,15 +40,14 @@ public class JettyHttpProducerSimulate40
// give Jetty time to startup properly
Thread.sleep(1000);
- try {
- template.request(url, null);
- } catch (Exception e) {
- HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
- assertEquals(404, cause.getStatusCode());
- assertEquals("http//0.0.0.0:" + getPort() + "/bar", cause.getUri());
- assertEquals("Page not found", cause.getResponseBody());
- assertNotNull(cause.getResponseHeaders());
- }
+ Exchange exchange = template.request(url, null);
+
+ assertNotNull(exchange.getException());
+ HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, exchange.getException());
+ assertEquals(404, cause.getStatusCode());
+ assertEquals("http//0.0.0.0:" + getPort() + "/bar", cause.getUri());
+ assertEquals("Page not found", cause.getResponseBody());
+ assertNotNull(cause.getResponseHeaders());
}
@Override
Modified: camel/trunk/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/jms/ObjectPoolTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/jms/ObjectPoolTest.java?rev=1436603&r1=1436602&r2=1436603&view=diff
==============================================================================
--- camel/trunk/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/jms/ObjectPoolTest.java (original)
+++ camel/trunk/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/jms/ObjectPoolTest.java Mon Jan 21 20:42:44 2013
@@ -20,29 +20,20 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import org.junit.Before;
+import org.apache.camel.test.junit4.TestSupport;
+
import org.junit.Test;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
/**
* TODO Add Class documentation for ObjectPoolTest
*/
-public class ObjectPoolTest {
+public class ObjectPoolTest extends TestSupport {
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectPoolTest.class);
- private AtomicInteger atomicInteger;
-
- @Before
- public void setUp() {
- atomicInteger = new AtomicInteger();
- }
-
/**
* Test method for
* {@link org.apache.camel.component.sjms.jms.ObjectPool#ObjectPool()}.
@@ -51,7 +42,7 @@ public class ObjectPoolTest {
*/
@Test
public void testObjectPool() throws Exception {
- TestPool testPool = new TestPool();
+ ObjectPool<MyPooledObject> testPool = new TestPool();
assertNotNull(testPool);
testPool.fillPool();
MyPooledObject pooledObject = testPool.borrowObject();
@@ -73,10 +64,13 @@ public class ObjectPoolTest {
*/
@Test
public void testBadObjectPool() {
+ ObjectPool<Object> objectPool = new BadTestPool();
+
try {
- new BadTestPool();
+ objectPool.createObject();
+ fail("Should have thrown exception");
} catch (Exception e) {
- assertTrue("Should have thrown an IllegalStateException", e instanceof IllegalStateException);
+ assertIsInstanceOf(IllegalStateException.class, e);
}
}
@@ -90,7 +84,7 @@ public class ObjectPoolTest {
public void testObjectPoolInt() throws Exception {
final int maxPoolObjects = 5;
- TestPool testPool = new TestPool(maxPoolObjects);
+ ObjectPool<MyPooledObject> testPool = new TestPool(maxPoolObjects);
testPool.fillPool();
List<MyPooledObject> poolObjects = new ArrayList<MyPooledObject>();
@@ -125,7 +119,7 @@ public class ObjectPoolTest {
*/
@Test
public void testCreateObject() throws Exception {
- TestPool testPool = new TestPool();
+ ObjectPool<MyPooledObject> testPool = new TestPool();
assertNotNull(testPool.createObject());
}
@@ -137,7 +131,7 @@ public class ObjectPoolTest {
*/
@Test
public void testBorrowObject() throws Exception {
- TestPool testPool = new TestPool();
+ ObjectPool<MyPooledObject> testPool = new TestPool();
testPool.fillPool();
MyPooledObject pooledObject = testPool.borrowObject();
assertNotNull(pooledObject);
@@ -157,7 +151,7 @@ public class ObjectPoolTest {
*/
@Test
public void testReturnObject() throws Exception {
- TestPool testPool = new TestPool();
+ ObjectPool<MyPooledObject> testPool = new TestPool();
testPool.fillPool();
assertNotNull(testPool);
MyPooledObject pooledObject = testPool.borrowObject();
@@ -168,7 +162,9 @@ public class ObjectPoolTest {
testPool.drainPool();
}
- class TestPool extends ObjectPool<MyPooledObject> {
+ private static class TestPool extends ObjectPool<MyPooledObject> {
+
+ private final AtomicInteger atomicInteger = new AtomicInteger();
public TestPool() {
}
@@ -204,14 +200,16 @@ public class ObjectPoolTest {
}
}
- static class BadTestPool extends ObjectPool<Object> {
+ private static class BadTestPool extends ObjectPool<Object> {
+
@Override
protected Object createObject() throws Exception {
- throw new Exception();
+ throw new IllegalStateException("I'm a bad ObjectPool impl");
}
@Override
protected void destroyObject(Object t) throws Exception {
+ // noop
}
}
Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/MixedPropagationTransactedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/MixedPropagationTransactedTest.java?rev=1436603&r1=1436602&r2=1436603&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/MixedPropagationTransactedTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/MixedPropagationTransactedTest.java Mon Jan 21 20:42:44 2013
@@ -81,9 +81,10 @@ public class MixedPropagationTransactedT
assertEquals("Number of books", 3, count);
}
- public void testRequiredOnlkyRollback() throws Exception {
+ public void testRequiredOnlyRollback() throws Exception {
try {
template.sendBody("direct:required", "Donkey in Action");
+ fail("Should have thrown exception");
} catch (RuntimeCamelException e) {
// expected as we fail
assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
@@ -96,9 +97,10 @@ public class MixedPropagationTransactedT
assertEquals("Number of books", 1, count);
}
- public void testRequiresNewOnlkyRollback() throws Exception {
+ public void testRequiresNewOnlyRollback() throws Exception {
try {
template.sendBody("direct:new", "Donkey in Action");
+ fail("Should have thrown exception");
} catch (RuntimeCamelException e) {
// expected as we fail
assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
@@ -111,21 +113,13 @@ public class MixedPropagationTransactedT
assertEquals("Number of books", 1, count);
}
- public void testRequiredAndNewRollback() throws Exception {
- try {
- template.sendBody("direct:new", "Tiger in Action");
- } catch (RuntimeCamelException e) {
- // expeced as we fail
- assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
- assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
- assertEquals("We don't have Donkeys, only Camels", e.getCause().getCause().getMessage());
- }
+ public void testRequiredAndNew() throws Exception {
+ template.sendBody("direct:requiredAndNew", "Tiger in Action");
int count = jdbc.queryForInt("select count(*) from books");
- assertEquals(1, jdbc.queryForInt("select count(*) from books where title = ?", "Tiger in Action"));
+ assertEquals(2, jdbc.queryForInt("select count(*) from books where title = ?", "Tiger in Action"));
assertEquals(0, jdbc.queryForInt("select count(*) from books where title = ?", "Donkey in Action"));
- // the tiger in action should be committed, but our 2nd route should rollback
- assertEquals("Number of books", 2, count);
+ assertEquals("Number of books", 3, count);
}
protected RouteBuilder createRouteBuilder() throws Exception {
Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMixedTransactedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMixedTransactedTest.java?rev=1436603&r1=1436602&r2=1436603&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMixedTransactedTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMixedTransactedTest.java Mon Jan 21 20:42:44 2013
@@ -16,7 +16,6 @@
*/
package org.apache.camel.spring.interceptor;
-import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spring.SpringRouteBuilder;
@@ -26,13 +25,9 @@ import org.apache.camel.spring.SpringRou
public class TransactionalClientDataSourceMixedTransactedTest extends TransactionalClientDataSourceTest {
public void testTransactionRollback() throws Exception {
- try {
- template.sendBody("direct:fail", "Hello World");
- } catch (RuntimeCamelException e) {
- // expected as we fail
- assertTrue(e.getCause() instanceof IllegalArgumentException);
- assertEquals("We don't have Donkeys, only Camels", e.getCause().getMessage());
- }
+ // through the onException clause below we've marked the exceptions containing the message
+ // "Donkey" as being handled so that we don't count with any exception on the client side.
+ template.sendBody("direct:fail", "Hello World");
int count = jdbc.queryForInt("select count(*) from books");
// should get 2 books as the first operation will succeed and we are not transacted