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 2009/09/28 18:14:52 UTC
svn commit: r819629 - in
/camel/trunk/camel-core/src/test/java/org/apache/camel: component/mock/
component/seda/ impl/ management/ processor/
Author: davsclaus
Date: Mon Sep 28 16:14:51 2009
New Revision: 819629
URL: http://svn.apache.org/viewvc?rev=819629&view=rev
Log:
MR-187: Added more unit tests.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockPredicateTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockThroughtputTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/CollectionProducerTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultClassResolverTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerNoMessageIdTest.java
- copied, changed from r819504, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerTest.java
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTimerTest.java
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockPredicateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockPredicateTest.java?rev=819629&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockPredicateTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockPredicateTest.java Mon Sep 28 16:14:51 2009
@@ -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.component.mock;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.PredicateBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class MockPredicateTest extends ContextTestSupport {
+
+ public void testMockPredicate() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:foo");
+ mock.message(0).predicate().header("foo");
+
+ mock.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", "bar");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testMockPredicateAsParameter() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:foo");
+ mock.message(0).predicate(PredicateBuilder.isNotNull(header("foo")));
+
+ mock.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", "bar");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("mock:foo");
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockPredicateTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockPredicateTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockThroughtputTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockThroughtputTest.java?rev=819629&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockThroughtputTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockThroughtputTest.java Mon Sep 28 16:14:51 2009
@@ -0,0 +1,47 @@
+/**
+ * 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.component.mock;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class MockThroughtputTest extends ContextTestSupport {
+
+ public void testMockThroughtputTest() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:foo?reportGroup=5");
+ mock.expectedMessageCount(10);
+
+ for (int i = 0; i < 10; i++) {
+ template.sendBody("direct:start", "Hello " + i);
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("mock:foo?reportGroup=5");
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockThroughtputTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockThroughtputTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/CollectionProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/CollectionProducerTest.java?rev=819629&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/CollectionProducerTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/CollectionProducerTest.java Mon Sep 28 16:14:51 2009
@@ -0,0 +1,56 @@
+/**
+ * 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.component.seda;
+
+import java.util.Collection;
+import java.util.Queue;
+import java.util.concurrent.ArrayBlockingQueue;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
+
+/**
+ * @version $Revision$
+ */
+public class CollectionProducerTest extends ContextTestSupport {
+
+ private class MyProducer extends CollectionProducer {
+
+ public MyProducer(Endpoint endpoint, Collection<Exchange> queue) {
+ super(endpoint, queue);
+ }
+ }
+
+ public void testCollectionProducer() throws Exception {
+ Queue<Exchange> queue = new ArrayBlockingQueue<Exchange>(10);
+
+ Endpoint endpoint = context.getEndpoint("seda://foo");
+ MyProducer my = new MyProducer(endpoint, queue);
+
+ my.start();
+ Exchange exchange = new DefaultExchange(context);
+ exchange.getIn().setBody("Hello World");
+ my.process(exchange);
+
+ Exchange top = queue.poll();
+ assertNotNull(top);
+ assertEquals("Hello World", top.getIn().getBody());
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/CollectionProducerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/CollectionProducerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultClassResolverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultClassResolverTest.java?rev=819629&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultClassResolverTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultClassResolverTest.java Mon Sep 28 16:14:51 2009
@@ -0,0 +1,99 @@
+/**
+ * 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.impl;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision$
+ */
+public class DefaultClassResolverTest extends TestCase {
+
+ public void testResolveClass() {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ Class clazz = resolver.resolveClass("java.lang.Integer");
+ assertNotNull(clazz);
+ }
+
+ public void testResolveClassType() {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ Class<Integer> clazz = resolver.resolveClass("java.lang.Integer", Integer.class);
+ assertNotNull(clazz);
+ }
+
+ public void testResolveClassClassLoader() {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ Class clazz = resolver.resolveClass("java.lang.Integer", DefaultClassResolverTest.class.getClassLoader());
+ assertNotNull(clazz);
+ }
+
+ public void testResolveClassClassLoaderType() {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ Class<Integer> clazz = resolver.resolveClass("java.lang.Integer", Integer.class, DefaultClassResolverTest.class.getClassLoader());
+ assertNotNull(clazz);
+ }
+
+ public void testResolveMandatoryClass() throws Exception {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ Class clazz = resolver.resolveMandatoryClass("java.lang.Integer");
+ assertNotNull(clazz);
+ }
+
+ public void testResolveMandatoryClassType()throws Exception {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ Class<Integer> clazz = resolver.resolveMandatoryClass("java.lang.Integer", Integer.class);
+ assertNotNull(clazz);
+ }
+
+ public void testResolveMandatoryClassClassLoader() throws Exception {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ Class clazz = resolver.resolveMandatoryClass("java.lang.Integer", DefaultClassResolverTest.class.getClassLoader());
+ assertNotNull(clazz);
+ }
+
+ public void testResolveMandatoryClassClassLoaderType() throws Exception {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ Class<Integer> clazz = resolver.resolveMandatoryClass("java.lang.Integer", Integer.class, DefaultClassResolverTest.class.getClassLoader());
+ assertNotNull(clazz);
+ }
+
+ public void testResolveMandatoryClassNotFound() {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ try {
+ resolver.resolveMandatoryClass("com.FooBar");
+ fail("Should thrown an exception");
+ } catch (ClassNotFoundException e) {
+ // expected
+ }
+ }
+
+ public void testLoadResourceAsUri() {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ URL url = resolver.loadResourceAsURL("log4j.properties");
+ assertNotNull(url);
+ }
+
+ public void testLoadResourceAsStream() {
+ DefaultClassResolver resolver = new DefaultClassResolver();
+ InputStream is = resolver.loadResourceAsStream("log4j.properties");
+ assertNotNull(is);
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultClassResolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultClassResolverTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTimerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTimerTest.java?rev=819629&r1=819628&r2=819629&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTimerTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTimerTest.java Mon Sep 28 16:14:51 2009
@@ -50,6 +50,9 @@
Long period = (Long) mbeanServer.getAttribute(name, "Period");
assertEquals(8000, period.longValue());
+ String camelId = (String) mbeanServer.getAttribute(name, "CamelId");
+ assertEquals("camel-1", camelId);
+
// change period
mbeanServer.setAttribute(name, new Attribute("Period", 1000));
mbeanServer.setAttribute(name, new Attribute("Delay", 0));
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerNoMessageIdTest.java (from r819504, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerNoMessageIdTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerNoMessageIdTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerTest.java&r1=819504&r2=819629&rev=819629&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerNoMessageIdTest.java Mon Sep 28 16:14:51 2009
@@ -16,168 +16,35 @@
*/
package org.apache.camel.processor;
+import org.apache.camel.CamelExecutionException;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.processor.idempotent.MemoryIdempotentRepository;
+import org.apache.camel.processor.idempotent.NoMessageIdException;
/**
* @version $Revision$
*/
-public class IdempotentConsumerTest extends ContextTestSupport {
- protected Endpoint startEndpoint;
- protected MockEndpoint resultEndpoint;
+public class IdempotentConsumerNoMessageIdTest extends ContextTestSupport {
- @Override
- public boolean isUseRouteBuilder() {
- return false;
+ public void testNoMessageId() throws Exception {
+ try {
+ template.sendBody("direct:start", "Hello World");
+ fail("Should have thrown an exception");
+ } catch (CamelExecutionException e) {
+ assertIsInstanceOf(NoMessageIdException.class, e.getCause());
+ }
}
- public void testDuplicateMessagesAreFilteredOut() throws Exception {
- context.addRoutes(new RouteBuilder() {
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").idempotentConsumer(
header("messageId"), MemoryIdempotentRepository.memoryIdempotentRepository(200)
).to("mock:result");
}
- });
- context.start();
-
- resultEndpoint.expectedBodiesReceived("one", "two", "three");
-
- sendMessage("1", "one");
- sendMessage("2", "two");
- sendMessage("1", "one");
- sendMessage("2", "two");
- sendMessage("1", "one");
- sendMessage("3", "three");
-
- assertMockEndpointsSatisfied();
- }
-
- public void testFailedExchangesNotAddedDeadLetterChannel() throws Exception {
- context.addRoutes(new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2).redeliverDelay(0).logStackTrace(false));
-
- from("direct:start").idempotentConsumer(
- header("messageId"), MemoryIdempotentRepository.memoryIdempotentRepository(200)
- ).process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- String id = exchange.getIn().getHeader("messageId", String.class);
- if (id.equals("2")) {
- throw new IllegalArgumentException("Damm I cannot handle id 2");
- }
- }
- }).to("mock:result");
- }
- });
- context.start();
-
- // we send in 2 messages with id 2 that fails
- getMockEndpoint("mock:error").expectedMessageCount(2);
- resultEndpoint.expectedBodiesReceived("one", "three");
-
- sendMessage("1", "one");
- sendMessage("2", "two");
- sendMessage("1", "one");
- sendMessage("2", "two");
- sendMessage("1", "one");
- sendMessage("3", "three");
-
- assertMockEndpointsSatisfied();
- }
-
- public void testFailedExchangesNotAddedDeadLetterChannelNotHandled() throws Exception {
- context.addRoutes(new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- errorHandler(deadLetterChannel("mock:error").handled(false).maximumRedeliveries(2).redeliverDelay(0).logStackTrace(false));
-
- from("direct:start").idempotentConsumer(
- header("messageId"), MemoryIdempotentRepository.memoryIdempotentRepository(200)
- ).process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- String id = exchange.getIn().getHeader("messageId", String.class);
- if (id.equals("2")) {
- throw new IllegalArgumentException("Damm I cannot handle id 2");
- }
- }
- }).to("mock:result");
- }
- });
- context.start();
-
- // we send in 2 messages with id 2 that fails
- getMockEndpoint("mock:error").expectedMessageCount(2);
- resultEndpoint.expectedBodiesReceived("one", "three");
-
- sendMessage("1", "one");
- sendMessage("2", "two");
- sendMessage("1", "one");
- sendMessage("2", "two");
- sendMessage("1", "one");
- sendMessage("3", "three");
-
- assertMockEndpointsSatisfied();
+ };
}
-
- public void testFailedExchangesNotAdded() throws Exception {
- context.addRoutes(new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- // use default error handler
- errorHandler(defaultErrorHandler());
-
- from("direct:start").idempotentConsumer(
- header("messageId"), MemoryIdempotentRepository.memoryIdempotentRepository(200)
- ).process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- String id = exchange.getIn().getHeader("messageId", String.class);
- if (id.equals("2")) {
- throw new IllegalArgumentException("Damm I cannot handle id 2");
- }
- }
- }).to("mock:result");
- }
- });
- context.start();
-
- resultEndpoint.expectedBodiesReceived("one", "three");
-
- sendMessage("1", "one");
- sendMessage("2", "two");
- sendMessage("1", "one");
- sendMessage("2", "two");
- sendMessage("1", "one");
- sendMessage("3", "three");
-
- assertMockEndpointsSatisfied();
- }
-
- protected void sendMessage(final Object messageId, final Object body) {
- template.send(startEndpoint, new Processor() {
- public void process(Exchange exchange) {
- // now lets fire in a message
- Message in = exchange.getIn();
- in.setBody(body);
- in.setHeader("messageId", messageId);
- }
- });
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- startEndpoint = resolveMandatoryEndpoint("direct:start");
- resultEndpoint = getMockEndpoint("mock:result");
- }
-
-}
+}
\ No newline at end of file