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.bpmscript.jbi.flow;
18:
19: import javax.jbi.messaging.ExchangeStatus;
20: import javax.jbi.messaging.InOut;
21: import javax.xml.namespace.QName;
22:
23: import org.apache.activemq.xbean.BrokerFactoryBean;
24: import org.apache.servicemix.client.DefaultServiceMixClient;
25: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
26: import org.apache.servicemix.jbi.jaxp.StringSource;
27: import org.apache.servicemix.tck.SpringTestSupport;
28: import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
29: import org.springframework.context.support.AbstractXmlApplicationContext;
30: import org.springframework.core.io.ClassPathResource;
31:
32: public class FlowTest extends SpringTestSupport {
33:
34: private BrokerFactoryBean bean;
35:
36: @Override
37: protected void setUp() throws Exception {
38: bean = new BrokerFactoryBean();
39: bean.setConfig(new ClassPathResource("inmemoryactivemq.xml"));
40: bean.afterPropertiesSet();
41: super .setUp();
42: }
43:
44: @Override
45: protected void tearDown() throws Exception {
46: super .tearDown();
47: bean.destroy();
48: }
49:
50: public void testEcho() throws Exception {
51: DefaultServiceMixClient client = new DefaultServiceMixClient(
52: jbi);
53: InOut me = client.createInOutExchange();
54: me.setService(new QName("http://servicemix.org/components",
55: "echo"));
56: me.getInMessage().setContent(
57: new StringSource("<hello>world</hello>"));
58: assertTrue(client.sendSync(me, 5000));
59: if (me.getStatus() == ExchangeStatus.ERROR) {
60: if (me.getFault() != null) {
61: fail("Received fault: "
62: + new SourceTransformer().toString(me
63: .getFault().getContent()));
64: } else if (me.getError() != null) {
65: throw me.getError();
66: } else {
67: fail("Received ERROR status");
68: }
69: } else {
70: System.out.println(new SourceTransformer().toString(me
71: .getOutMessage().getContent()));
72: }
73: client.done(me);
74: }
75:
76: protected AbstractXmlApplicationContext createBeanFactory() {
77: return new ClassPathXmlApplicationContext(
78: "/org/bpmscript/jbi/flow/flow.xml");
79: }
80:
81: }
|