You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dv...@apache.org on 2011/09/29 20:42:53 UTC
svn commit: r1177394 -
/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionWithExceptionTest.java
Author: dvaleri
Date: Thu Sep 29 18:42:53 2011
New Revision: 1177394
URL: http://svn.apache.org/viewvc?rev=1177394&view=rev
Log:
[CAMEL-4504] Added unit test to cover bean expressions that throw excetpions fix from 2.4.0.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionWithExceptionTest.java (with props)
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionWithExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionWithExceptionTest.java?rev=1177394&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionWithExceptionTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionWithExceptionTest.java Thu Sep 29 18:42:53 2011
@@ -0,0 +1,115 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.Body;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class ChoiceWhenBeanExpressionWithExceptionTest extends ContextTestSupport {
+ private MockEndpoint gradeA;
+ private MockEndpoint otherGrade;
+
+ protected void verifyGradeA(String endpointUri) throws Exception {
+ gradeA.reset();
+ otherGrade.reset();
+ gradeA.expectedMessageCount(0);
+ otherGrade.expectedMessageCount(0);
+
+ try {
+ template.sendBody(endpointUri, new Student(95));
+ fail();
+ } catch (CamelExecutionException e) {
+ e.printStackTrace();
+ }
+ assertMockEndpointsSatisfied();
+ }
+
+ public void verifyOtherGrade(String endpointUri) throws Exception {
+ gradeA.reset();
+ otherGrade.reset();
+ gradeA.expectedMessageCount(0);
+ otherGrade.expectedMessageCount(0);
+
+ try {
+ template.sendBody(endpointUri, new Student(60));
+ fail();
+ } catch (CamelExecutionException e) {
+ // expected
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testBeanExpression() throws Exception {
+ verifyGradeA("direct:expression");
+ verifyOtherGrade("direct:expression");
+ }
+
+ public void testMethod() throws Exception {
+ verifyGradeA("direct:method");
+ verifyOtherGrade("direct:method");
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ gradeA = getMockEndpoint("mock:gradeA");
+ otherGrade = getMockEndpoint("mock:otherGrade");
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:expression")
+ .choice()
+ .when().expression(bean(MyBean.class, "isGradeA")).to("mock:gradeA")
+ .otherwise().to("mock:otherGrade")
+ .end();
+
+ from("direct:method")
+ .choice()
+ .when().method(MyBean.class).to("mock:gradeA")
+ .otherwise().to("mock:otherGrade")
+ .end();
+ }
+ };
+ }
+
+
+ public static class MyBean {
+ public boolean isGradeA(@Body Student student) {
+ throw new RuntimeException("Bean predicated threw exception!");
+ }
+ }
+
+ class Student {
+ private int grade;
+
+ public Student(int grade) {
+ this.grade = grade;
+ }
+
+ public int getGrade() {
+ return grade;
+ }
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionWithExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native