01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.servicemix.components.drools;
18:
19: import javax.jbi.messaging.ExchangeStatus;
20: import javax.jbi.messaging.InOut;
21: import javax.jbi.messaging.NormalizedMessage;
22: import javax.xml.namespace.QName;
23:
24: import org.apache.servicemix.jbi.jaxp.StringSource;
25: import org.apache.servicemix.tck.TestSupport;
26: import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
27: import org.springframework.context.support.AbstractXmlApplicationContext;
28: import org.w3c.dom.Document;
29: import org.w3c.dom.Element;
30: import org.w3c.dom.Node;
31:
32: /**
33: * @version $Revision: 376451 $
34: */
35: public class DroolsRouteTest extends TestSupport {
36:
37: public void testFiringRules() throws Exception {
38: QName service = new QName("http://servicemix.org/cheese/",
39: "droolsRouter");
40:
41: InOut exchange = client.createInOutExchange();
42: exchange.setService(service);
43: NormalizedMessage message = exchange.getInMessage();
44: message.setContent(new StringSource(createMessageXmlText(1)));
45: client.sendSync(exchange);
46: assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
47: Node node = transformer.toDOMNode(exchange.getOutMessage()
48: .getContent());
49: Element e = null;
50: if (node instanceof Element) {
51: e = (Element) node;
52: } else if (node instanceof Document) {
53: e = ((Document) node).getDocumentElement();
54: } else {
55: fail("Node should be an Element or a Document");
56: }
57: assertEquals("hello", e.getLocalName());
58: client.done(exchange);
59:
60: exchange = client.createInOutExchange();
61: exchange.setService(service);
62: message = exchange.getInMessage();
63: message.setContent(new StringSource(createMessageXmlText(2)));
64: client.sendSync(exchange);
65: assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
66: node = transformer.toDOMNode(exchange.getOutMessage()
67: .getContent());
68: e = null;
69: if (node instanceof Element) {
70: e = (Element) node;
71: } else if (node instanceof Document) {
72: e = ((Document) node).getDocumentElement();
73: } else {
74: fail("Node should be an Element or a Document");
75: }
76: assertEquals("world", e.getLocalName());
77: client.done(exchange);
78: }
79:
80: protected AbstractXmlApplicationContext createBeanFactory() {
81: return new ClassPathXmlApplicationContext(
82: "org/apache/servicemix/components/drools/jbi-example-route.xml");
83: }
84: }
|