Created
January 9, 2013 14:14
-
-
Save davsclaus/4493411 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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.drools; | |
| import org.apache.camel.builder.RouteBuilder; | |
| import org.apache.camel.component.mock.MockEndpoint; | |
| import org.apache.camel.test.junit4.CamelTestSupport; | |
| import org.junit.Test; | |
| /** | |
| * | |
| */ | |
| public class GoToBarTest extends CamelTestSupport { | |
| @Test | |
| public void testGoToBar() throws Exception { | |
| Person barney = new Person(); | |
| barney.setAge(38); | |
| barney.setName("Barney"); | |
| Person bart = new Person(); | |
| bart.setAge(10); | |
| bart.setName("Bart"); | |
| MockEndpoint bar = getMockEndpoint("mock:bar"); | |
| bar.expectedBodiesReceived(barney); | |
| MockEndpoint home = getMockEndpoint("mock:home"); | |
| home.expectedBodiesReceived(bart); | |
| MockEndpoint drink = getMockEndpoint("mock:drink"); | |
| drink.expectedBodiesReceived("Yeah Drink"); | |
| template.sendBody("direct:start", barney); | |
| template.sendBody("direct:start", bart); | |
| assertMockEndpointsSatisfied(); | |
| } | |
| @Override | |
| protected RouteBuilder createRouteBuilder() throws Exception { | |
| return new RouteBuilder() { | |
| @Override | |
| public void configure() throws Exception { | |
| from("direct:start") | |
| .to("drools:cheers.drl") | |
| .choice() | |
| .when().simple("${body.canDrink}") | |
| .log("Person ${body} can go to the bar") | |
| .to("mock:bar") | |
| .otherwise() | |
| .log("Person ${body} stays home") | |
| .to("mock:home"); | |
| } | |
| }; | |
| } | |
| } | |
| /** | |
| * 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. | |
| */ | |
| import org.apache.camel.component.drools.Person; | |
| global org.apache.camel.ProducerTemplate producerTemplate; | |
| rule "Cheers" | |
| when | |
| p : Person( age >= 21 ) | |
| then | |
| p.setCanDrink(true); | |
| producerTemplate.sendBody("mock:drink", "Yeah Drink"); | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment