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/10/08 14:40:13 UTC
svn commit: r823148 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/component/bean/
test/java/org/apache/camel/component/bean/
Author: davsclaus
Date: Thu Oct 8 12:40:12 2009
New Revision: 823148
URL: http://svn.apache.org/viewvc?rev=823148&view=rev
Log:
MR-187: Added more unit tests.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanRegistryBeanTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanEndpointTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanMethodBeanTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java?rev=823148&r1=823147&r2=823148&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java Thu Oct 8 12:40:12 2009
@@ -43,11 +43,6 @@
this.registry = context.getRegistry();
}
- public RegistryBean(CamelContext context, String name, ParameterMappingStrategy parameterMappingStrategy) {
- this(context, name);
- this.parameterMappingStrategy = parameterMappingStrategy;
- }
-
@Override
public String toString() {
return "bean: " + name;
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanEndpointTest.java?rev=823148&r1=823147&r2=823148&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanEndpointTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanEndpointTest.java Thu Oct 8 12:40:12 2009
@@ -61,6 +61,109 @@
assertEquals("Hello World", out);
}
+ public void testBeanEndpointCtrUri() throws Exception {
+ final BeanEndpoint endpoint = new BeanEndpoint("bean:foo");
+ endpoint.setCamelContext(context);
+
+ endpoint.setBeanName("foo");
+ assertEquals("foo", endpoint.getBeanName());
+
+ assertEquals(false, endpoint.isCache());
+ assertNull(endpoint.getBeanHolder());
+ assertNull(endpoint.getMethod());
+ assertEquals("bean:foo", endpoint.getEndpointUri());
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to(endpoint);
+ }
+ });
+ context.start();
+
+ String out = template.requestBody("direct:start", "World", String.class);
+ assertEquals("Hello World", out);
+ }
+
+ public void testBeanEndpointCtrComponent() throws Exception {
+ final BeanComponent comp = context.getComponent("bean", BeanComponent.class);
+ final BeanEndpoint endpoint = new BeanEndpoint("bean:foo", comp);
+ endpoint.setCamelContext(context);
+
+ endpoint.setBeanName("foo");
+ assertEquals("foo", endpoint.getBeanName());
+
+ assertEquals(false, endpoint.isCache());
+ assertNull(endpoint.getBeanHolder());
+ assertNull(endpoint.getMethod());
+ assertEquals("bean:foo", endpoint.getEndpointUri());
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to(endpoint);
+ }
+ });
+ context.start();
+
+ String out = template.requestBody("direct:start", "World", String.class);
+ assertEquals("Hello World", out);
+ }
+
+ public void testBeanEndpointCtrComponentBeanProcessor() throws Exception {
+ final BeanComponent comp = context.getComponent("bean", BeanComponent.class);
+
+ BeanHolder holder = new RegistryBean(context, "foo");
+ final BeanProcessor bp = new BeanProcessor(holder);
+ final BeanEndpoint endpoint = new BeanEndpoint("bean:foo", comp, bp);
+ endpoint.setCamelContext(context);
+
+ endpoint.setBeanName("foo");
+ assertEquals("foo", endpoint.getBeanName());
+
+ assertEquals(false, endpoint.isCache());
+ assertNull(endpoint.getBeanHolder());
+ assertNull(endpoint.getMethod());
+ assertEquals("bean:foo", endpoint.getEndpointUri());
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to(endpoint);
+ }
+ });
+ context.start();
+
+ String out = template.requestBody("direct:start", "World", String.class);
+ assertEquals("Hello World", out);
+ }
+
+ public void testBeanEndpointCtrBeanProcessor() throws Exception {
+ BeanHolder holder = new RegistryBean(context, "foo");
+ final BeanProcessor bp = new BeanProcessor(holder);
+ final BeanEndpoint endpoint = new BeanEndpoint("bean:foo", bp);
+ endpoint.setCamelContext(context);
+
+ endpoint.setBeanName("foo");
+ assertEquals("foo", endpoint.getBeanName());
+
+ assertEquals(false, endpoint.isCache());
+ assertNull(endpoint.getBeanHolder());
+ assertNull(endpoint.getMethod());
+ assertEquals("bean:foo", endpoint.getEndpointUri());
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to(endpoint);
+ }
+ });
+ context.start();
+
+ String out = template.requestBody("direct:start", "World", String.class);
+ assertEquals("Hello World", out);
+ }
+
public void testBeanEndpointCtrWithMethod() throws Exception {
final BeanEndpoint endpoint = new BeanEndpoint();
endpoint.setCamelContext(context);
@@ -90,6 +193,7 @@
final BeanEndpoint endpoint = new BeanEndpoint();
endpoint.setCamelContext(context);
endpoint.setCache(true);
+ endpoint.setMultiParameterArray(false);
endpoint.setBeanName("foo");
endpoint.setMethod("hello");
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanMethodBeanTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanMethodBeanTest.java?rev=823148&r1=823147&r2=823148&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanMethodBeanTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanMethodBeanTest.java Thu Oct 8 12:40:12 2009
@@ -36,6 +36,7 @@
assertEquals("hello", mb.getName());
assertEquals(method, mb.getMethod());
assertNotNull(mb.getParameterTypes());
+ assertEquals(MyFooBean.class, mb.getType());
}
}
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanRegistryBeanTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanRegistryBeanTest.java?rev=823148&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanRegistryBeanTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanRegistryBeanTest.java Thu Oct 8 12:40:12 2009
@@ -0,0 +1,80 @@
+/**
+ * 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.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Expression;
+import org.apache.camel.NoSuchBeanException;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * @version $Revision$
+ */
+public class BeanRegistryBeanTest extends ContextTestSupport {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("foo", new MyFooBean());
+ return jndi;
+ }
+
+ public void testNoBean() {
+ RegistryBean rb = new RegistryBean(context, "bar");
+ try {
+ rb.getBean();
+ fail("Should have thrown exception");
+ } catch (NoSuchBeanException e) {
+ assertEquals("bar", e.getName());
+ }
+ }
+
+ public void testBean() {
+ RegistryBean rb = new RegistryBean(context, "foo");
+ Object bean = rb.getBean();
+ assertIsInstanceOf(MyFooBean.class, bean);
+
+ assertNotNull(rb.getContext());
+ assertEquals("foo", rb.getName());
+ assertNotNull(rb.getParameterMappingStrategy());
+ assertNotNull(rb.getRegistry());
+ }
+
+ public void testParameterMappingStrategy() {
+ RegistryBean rb = new RegistryBean(context, "foo");
+ ParameterMappingStrategy myStrategy = new ParameterMappingStrategy() {
+ public Expression getDefaultParameterTypeExpression(Class parameterType) {
+ return null;
+ }
+ };
+ rb.setParameterMappingStrategy(myStrategy);
+
+ Object bean = rb.getBean();
+ assertIsInstanceOf(MyFooBean.class, bean);
+
+ assertNotNull(rb.getContext());
+ assertEquals("foo", rb.getName());
+ assertEquals(myStrategy, rb.getParameterMappingStrategy());
+ assertNotNull(rb.getRegistry());
+ }
+
+ public class MyFooBean {
+
+ }
+
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanRegistryBeanTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanRegistryBeanTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date