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.component;
18:
19: import java.util.Properties;
20:
21: import javax.jbi.messaging.ExchangeStatus;
22: import javax.jbi.messaging.InOut;
23: import javax.xml.namespace.QName;
24:
25: import org.apache.activemq.xbean.BrokerFactoryBean;
26: import org.apache.log4j.PropertyConfigurator;
27: import org.apache.servicemix.client.DefaultServiceMixClient;
28: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
29: import org.apache.servicemix.jbi.jaxp.StringSource;
30: import org.apache.servicemix.tck.SpringTestSupport;
31: import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
32: import org.springframework.context.support.AbstractXmlApplicationContext;
33: import org.springframework.core.io.ClassPathResource;
34:
35: public class CorellationTest extends SpringTestSupport {
36:
37: private final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
38: .getLog(CorellationTest.class);
39:
40: public CorellationTest() {
41: Properties properties = new Properties();
42: properties.put("log4j.rootCategory", "INFO, stdout");
43: properties.put("log4j.appender.stdout",
44: "org.apache.log4j.ConsoleAppender");
45: properties.put("log4j.appender.stdout.layout",
46: "org.apache.log4j.PatternLayout");
47: properties.put(
48: "log4j.appender.stdout.layout.ConversionPattern",
49: "%p [%t] %c{1}.%M(%L) | %m%n");
50: PropertyConfigurator.configure(properties);
51: }
52:
53: // private BrokerFactoryBean bean;
54: //
55: // @Override
56: // protected void setUp() throws Exception {
57: // bean = new BrokerFactoryBean();
58: // bean.setConfig(new ClassPathResource("/org/bpmscript/jbi/flow/inmemoryactivemq.xml"));
59: // bean.afterPropertiesSet();
60: // super.setUp();
61: // }
62: //
63: // @Override
64: // protected void tearDown() throws Exception {
65: // super.tearDown();
66: // bean.destroy();
67: // }
68:
69: public void testCorellation() throws Exception {
70: DefaultServiceMixClient client = new DefaultServiceMixClient(
71: jbi);
72: InOut me = client.createInOutExchange();
73: me.setService(new QName("http://bpmscript.org/jbi",
74: "corellation"));
75: me.getInMessage().setContent(
76: new StringSource("<hello>world</hello>"));
77: assertTrue(client.sendSync(me, 1000000));
78: if (me.getStatus() == ExchangeStatus.ERROR) {
79: if (me.getFault() != null) {
80: fail("Received fault: "
81: + new SourceTransformer().toString(me
82: .getFault().getContent()));
83: } else if (me.getError() != null) {
84: throw me.getError();
85: } else {
86: fail("Received ERROR status");
87: }
88: }
89: }
90:
91: protected AbstractXmlApplicationContext createBeanFactory() {
92: return new ClassPathXmlApplicationContext(
93: "/corellation/spring.xml");
94: }
95:
96: }
|