Author: davsclaus
Date: Tue Sep 22 08:45:27 2009
New Revision: 817545
URL: http://svn.apache.org/viewvc?rev=817545&view=rev
Log:
MR-187: Added more unit tests. Removed not needed methods and marked others as
@deprecated.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java
(with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/LoadBalancerSupport.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=817545&r1=817544&r2=817545&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Tue
Sep 22 08:45:27 2009
@@ -187,7 +187,9 @@
*
* @param uri the URI of the endpoints
* @return collection of endpoints
+ * @deprecated makes no sense, is removed in Camel 2.2
*/
+ @Deprecated
Collection<Endpoint> getEndpoints(String uri);
/**
@@ -215,7 +217,9 @@
* @param uri the URI to be used to remove
* @return a collection of endpoints removed or null if there are no
endpoints for this URI
* @throws Exception if at least one endpoint could not be stopped
+ * @deprecated makes no sense, is removed in Camel 2.2
*/
+ @Deprecated
Collection<Endpoint> removeEndpoints(String uri) throws Exception;
/**
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=817545&r1=817544&r2=817545&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Tue Sep 22 08:45:27 2009
@@ -339,7 +339,6 @@
return oldEndpoint;
}
- @Deprecated
public Collection<Endpoint> removeEndpoints(String uri) throws Exception {
Collection<Endpoint> answer = new ArrayList<Endpoint>();
synchronized (endpoints) {
@@ -367,16 +366,6 @@
return answer;
}
- public Endpoint addSingletonEndpoint(String uri, Endpoint endpoint) throws
Exception {
- return addEndpoint(uri, endpoint);
- }
-
- @Deprecated
- public Endpoint removeSingletonEndpoint(String uri) throws Exception {
- Collection<Endpoint> answer = removeEndpoints(uri);
- return (Endpoint) (answer.size() > 0 ? answer.toArray()[0] : null);
- }
-
public Endpoint getEndpoint(String uri) {
ObjectHelper.notEmpty(uri, "uri");
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?rev=817545&r1=817544&r2=817545&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
Tue Sep 22 08:45:27 2009
@@ -35,7 +35,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
/**
* Default component to use for base for components implementations.
*
@@ -229,7 +228,9 @@
/**
* Converts the given value to the requested type
+ * @deprecated will be removed in Camel 2.2
*/
+ @Deprecated
public <T> T convertTo(Class<T> type, Object value) {
return CamelContextHelper.convertTo(getCamelContext(), type, value);
}
@@ -237,7 +238,9 @@
/**
* Converts the given value to the specified type throwing an {...@link
IllegalArgumentException}
* if the value could not be converted to a non null value
+ * @deprecated will be removed in Camel 2.2
*/
+ @Deprecated
public <T> T mandatoryConvertTo(Class<T> type, Object value) {
return CamelContextHelper.mandatoryConvertTo(getCamelContext(), type,
value);
}
@@ -245,7 +248,9 @@
/**
* Creates a new instance of the given type using the {...@link
org.apache.camel.spi.Injector} on the given
* {...@link CamelContext}
+ * @deprecated will be removed in Camel 2.2
*/
+ @Deprecated
public <T> T newInstance(Class<T> beanType) {
return getCamelContext().getInjector().newInstance(beanType);
}
@@ -253,7 +258,9 @@
/**
* Look up the given named bean in the {...@link
org.apache.camel.spi.Registry} on the
* {...@link CamelContext}
+ * @deprecated will be removed in Camel 2.2
*/
+ @Deprecated
public Object lookup(String name) {
return getCamelContext().getRegistry().lookup(name);
}
@@ -261,7 +268,9 @@
/**
* Look up the given named bean of the given type in the {...@link
org.apache.camel.spi.Registry} on the
* {...@link CamelContext}
+ * @deprecated will be removed in Camel 2.2
*/
+ @Deprecated
public <T> T lookup(String name, Class<T> beanType) {
return getCamelContext().getRegistry().lookup(name, beanType);
}
@@ -269,7 +278,9 @@
/**
* Look up the given named bean in the {...@link
org.apache.camel.spi.Registry} on the
* {...@link CamelContext} or throws exception if not found.
+ * @deprecated will be removed in Camel 2.2
*/
+ @Deprecated
public Object mandatoryLookup(String name) {
return CamelContextHelper.mandatoryLookup(getCamelContext(), name);
}
@@ -277,7 +288,9 @@
/**
* Look up the given named bean of the given type in the {...@link
org.apache.camel.spi.Registry} on the
* {...@link CamelContext} or throws exception if not found.
+ * @deprecated will be removed in Camel 2.2
*/
+ @Deprecated
public <T> T mandatoryLookup(String name, Class<T> beanType) {
return CamelContextHelper.mandatoryLookup(getCamelContext(), name,
beanType);
}
@@ -311,7 +324,8 @@
if (value == null) {
return null;
}
- return convertTo(type, value);
+
+ return CamelContextHelper.convertTo(getCamelContext(), type, value);
}
/**
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/LoadBalancerSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/LoadBalancerSupport.java?rev=817545&r1=817544&r2=817545&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/LoadBalancerSupport.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/LoadBalancerSupport.java
Tue Sep 22 08:45:27 2009
@@ -58,10 +58,13 @@
}
protected void doStart() throws Exception {
- ServiceHelper.startServices(processors);
+ ServiceHelper.startServices(processors);
}
protected void doStop() throws Exception {
- ServiceHelper.stopServices(processors);
+ ServiceHelper.stopServices(processors);
+ for (Processor processor : processors) {
+ removeProcessor(processor);
+ }
}
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java?rev=817545&r1=817544&r2=817545&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java
Tue Sep 22 08:45:27 2009
@@ -38,11 +38,6 @@
private int numberOfHashGroups = 64 * 1024;
private final Map<Object, Processor> stickyMap = new HashMap<Object,
Processor>();
- public StickyLoadBalancer() {
- super();
- this.loadBalancer = new RoundRobinLoadBalancer();
- }
-
public StickyLoadBalancer(Expression correlationExpression) {
this(correlationExpression, new RoundRobinLoadBalancer());
}
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java?rev=817545&r1=817544&r2=817545&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
Tue Sep 22 08:45:27 2009
@@ -17,6 +17,7 @@
package org.apache.camel.impl;
import java.util.List;
+import java.util.Map;
import junit.framework.TestCase;
import org.apache.camel.Component;
@@ -25,6 +26,9 @@
import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.bean.BeanComponent;
+import org.apache.camel.component.direct.DirectComponent;
+import org.apache.camel.component.log.LogComponent;
+import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.util.CamelContextHelper;
/**
@@ -60,6 +64,13 @@
DefaultCamelContext ctx = new DefaultCamelContext();
Endpoint endpoint = ctx.getEndpoint("log:foo");
assertNotNull(endpoint);
+
+ try {
+ ctx.getEndpoint(null);
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
}
public void testGetEndpointNotFound() throws Exception {
@@ -81,14 +92,14 @@
// expected
}
}
-
+
public void testRestartCamelContext() throws Exception {
DefaultCamelContext ctx = new DefaultCamelContext();
ctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:endpointA").to("mock:endpointB");
- }
+ from("direct:endpointA").to("mock:endpointB");
+ }
});
ctx.start();
assertEquals("Should have one RouteService", 1,
ctx.getRouteServices().size());
@@ -102,4 +113,65 @@
assertEquals("The RouteService should NOT be removed even when we
stop", 1, ctx.getRouteServices().size());
}
+ public void testName() {
+ DefaultCamelContext ctx = new DefaultCamelContext();
+ assertNotNull("Should have a default name", ctx.getName());
+ ctx.setName("foo");
+ assertEquals("foo", ctx.getName());
+
+ assertNotNull(ctx.toString());
+ assertTrue(ctx.isAutoStartup());
+ }
+
+ public void testVersion() {
+ DefaultCamelContext ctx = new DefaultCamelContext();
+ assertNotNull("Should have a version", ctx.getVersion());
+ }
+
+ public void testHasComponent() {
+ DefaultCamelContext ctx = new DefaultCamelContext();
+ assertNull(ctx.hasComponent("log"));
+
+ ctx.addComponent("log", new LogComponent());
+ assertNotNull(ctx.hasComponent("log"));
+ }
+
+ public void testGetComponent() {
+ DefaultCamelContext ctx = new DefaultCamelContext();
+ ctx.addComponent("log", new LogComponent());
+
+ LogComponent log = ctx.getComponent("log", LogComponent.class);
+ assertNotNull(log);
+ try {
+ ctx.addComponent("direct", new DirectComponent());
+ ctx.getComponent("log", DirectComponent.class);
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testGetEndpointMap() throws Exception {
+ DefaultCamelContext ctx = new DefaultCamelContext();
+ ctx.addEndpoint("mock://foo", new MockEndpoint("mock://foo"));
+
+ Map map = ctx.getEndpointMap();
+ assertEquals(1, map.size());
+ }
+
+ public void testHasEndpoint() throws Exception {
+ DefaultCamelContext ctx = new DefaultCamelContext();
+ ctx.addEndpoint("mock://foo", new MockEndpoint("mock://foo"));
+
+ assertNotNull(ctx.hasEndpoint("mock://foo"));
+ assertNull(ctx.hasEndpoint("mock://bar"));
+
+ try {
+ ctx.hasEndpoint(null);
+ fail("Should have thrown exception");
+ } catch (ResolveEndpointFailedException e) {
+ // expected
+ }
+ }
+
}
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java?rev=817545&r1=817544&r2=817545&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java
Tue Sep 22 08:45:27 2009
@@ -27,6 +27,7 @@
public void testMarshal() throws Exception {
DefaultExchangeHolder holder = createHolder();
assertNotNull(holder);
+ assertNotNull(holder.toString());
}
public void testUnmarshal() throws Exception {
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java?rev=817545&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java
Tue Sep 22 08:45:27 2009
@@ -0,0 +1,63 @@
+/**
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+
+/**
+ * @version $Revision$
+ */
+public class ExpressionSupportTest extends ContextTestSupport {
+
+ private class MyExpression extends ExpressionSupport {
+
+ protected String assertionFailureMessage(Exchange exchange) {
+ return "foo";
+ }
+
+ public <T> T evaluate(Exchange exchange, Class<T> type) {
+ String in = exchange.getIn().getBody(String.class);
+ if ("Kabom".equals(in)) {
+ return null;
+ }
+ return (T) in;
+ }
+ }
+
+ public void testExpressionSupport() throws Exception {
+ MyExpression my = new MyExpression();
+
+ Exchange e = new DefaultExchange(context);
+ e.getIn().setBody("bar");
+
+ my.assertMatches("bar", e);
+ }
+
+ public void testExpressionSupportFail() throws Exception {
+ MyExpression my = new MyExpression();
+
+ Exchange e = new DefaultExchange(context);
+ e.getIn().setBody("Kabom");
+ try {
+ my.assertMatches("damn", e);
+ fail("Should have thrown exception");
+ } catch (AssertionError ae) {
+ assertTrue(ae.getMessage().contains("foo"));
+ }
+ }
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ExpressionSupportTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date