Author: davsclaus
Date: Fri Oct 16 07:16:39 2009
New Revision: 825785
URL: http://svn.apache.org/viewvc?rev=825785&view=rev
Log:
MR-187: Added more unit tests.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanComponentCustomCreateEndpointTest.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionStringBufferTest.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/util/PredicateAssertHelperTest.java
(with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyFooBean.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java?rev=825785&r1=825784&r2=825785&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
Fri Oct 16 07:16:39 2009
@@ -34,10 +34,11 @@
public BeanComponent() {
}
- /**
+ /**
* A helper method to create a new endpoint from a bean with a generated
URI
*/
public ProcessorEndpoint createEndpoint(Object bean) {
+ // used by servicemix-camel
String uri = "bean:generated:" + bean;
return createEndpoint(bean, uri);
}
@@ -46,6 +47,7 @@
* A helper method to create a new endpoint from a bean with a given URI
*/
public ProcessorEndpoint createEndpoint(Object bean, String uri) {
+ // used by servicemix-camel
BeanProcessor processor = new BeanProcessor(bean, getCamelContext());
return createEndpoint(uri, processor);
}
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanComponentCustomCreateEndpointTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanComponentCustomCreateEndpointTest.java?rev=825785&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanComponentCustomCreateEndpointTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanComponentCustomCreateEndpointTest.java
Fri Oct 16 07:16:39 2009
@@ -0,0 +1,67 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.ProcessorEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class BeanComponentCustomCreateEndpointTest extends ContextTestSupport {
+
+ public void testCreateEndpoint() throws Exception {
+ BeanComponent bc = context.getComponent("bean", BeanComponent.class);
+ ProcessorEndpoint pe = bc.createEndpoint(new MyFooBean());
+ assertNotNull(pe);
+
+ String uri = pe.getEndpointUri();
+ assertEquals("bean:generated:MyFooBean", uri);
+
+ Producer producer = pe.createProducer();
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody("World");
+
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+
+ assertEquals("Hello World", exchange.getOut().getBody());
+ }
+
+ public void testCreateEndpointUri() throws Exception {
+ BeanComponent bc = context.getComponent("bean", BeanComponent.class);
+ ProcessorEndpoint pe = bc.createEndpoint(new MyFooBean(), "cheese");
+ assertNotNull(pe);
+
+ String uri = pe.getEndpointUri();
+ assertEquals("cheese", uri);
+
+ Producer producer = pe.createProducer();
+ Exchange exchange = producer.createExchange();
+ exchange.getIn().setBody("World");
+
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+
+ assertEquals("Hello World", exchange.getOut().getBody());
+ }
+
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanComponentCustomCreateEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanComponentCustomCreateEndpointTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyFooBean.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyFooBean.java?rev=825785&r1=825784&r2=825785&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyFooBean.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyFooBean.java
Fri Oct 16 07:16:39 2009
@@ -25,4 +25,8 @@
return "Hello " + s;
}
+ @Override
+ public String toString() {
+ return "MyFooBean";
+ }
}
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionStringBufferTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionStringBufferTest.java?rev=825785&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionStringBufferTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionStringBufferTest.java
Fri Oct 16 07:16:39 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.util;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision$
+ */
+public class CollectionStringBufferTest extends TestCase {
+
+ public void testCollectionStringBufferDefault() {
+ CollectionStringBuffer buf = new CollectionStringBuffer();
+ assertEquals(", ", buf.getSeparator());
+
+ buf.append("foo");
+ buf.append("bar");
+
+ assertEquals("foo, bar", buf.toString());
+ }
+
+ public void testCollectionStringBufferSeparator() {
+ CollectionStringBuffer buf = new CollectionStringBuffer("#");
+ assertEquals("#", buf.getSeparator());
+
+ buf.append("foo");
+ buf.append("bar");
+
+ assertEquals("foo#bar", buf.toString());
+ }
+
+ public void testCollectionStringBufferSetSeparator() {
+ CollectionStringBuffer buf = new CollectionStringBuffer();
+ buf.setSeparator("#");
+ assertEquals("#", buf.getSeparator());
+
+ buf.append("foo");
+ buf.append("bar");
+
+ assertEquals("foo#bar", buf.toString());
+ }
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionStringBufferTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionStringBufferTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/PredicateAssertHelperTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/PredicateAssertHelperTest.java?rev=825785&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/util/PredicateAssertHelperTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/util/PredicateAssertHelperTest.java
Fri Oct 16 07:16:39 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.util;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Predicate;
+import org.apache.camel.builder.PredicateBuilder;
+import org.apache.camel.impl.DefaultExchange;
+import static org.apache.camel.builder.Builder.constant;
+
+/**
+ * @version $Revision$
+ */
+public class PredicateAssertHelperTest extends ContextTestSupport {
+
+ public void testPredicateAssertHelper() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ Predicate notNull = PredicateBuilder.isNotNull(constant("foo"));
+
+ PredicateAssertHelper.assertMatches(notNull, "foo is not null",
exchange);
+ PredicateAssertHelper.assertMatches(notNull, null, exchange);
+ }
+
+ public void testPredicateAssertHelperFailed() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ Predicate notNull = PredicateBuilder.isNotNull(constant(null));
+
+ try {
+ PredicateAssertHelper.assertMatches(notNull, "foo is not null",
exchange);
+ fail("Should have thrown exception");
+ } catch (AssertionError e) {
+ // expected
+ }
+ try {
+ PredicateAssertHelper.assertMatches(notNull, null, exchange);
+ fail("Should have thrown exception");
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/PredicateAssertHelperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/PredicateAssertHelperTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java?rev=825785&r1=825784&r2=825785&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
Fri Oct 16 07:16:39 2009
@@ -16,6 +16,10 @@
*/
package org.apache.camel.util;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.camel.ContextTestSupport;
/**
@@ -90,4 +94,15 @@
assertNotNull(out);
}
+ public void testCreateRemaingURI() throws Exception {
+ URI original = new URI("http://camel.apache.org");
+ Map param = new HashMap();
+ param.put("foo", "123");
+ URI newUri = URISupport.createRemainingURI(original, param);
+ assertNotNull(newUri);
+
+ String s = newUri.toString();
+ assertEquals("http://camel.apache.org?foo=123", s);
+ }
+
}