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 LoanBrokerSmokeTest extends SpringTestSupport {
36:
37: private BrokerFactoryBean bean;
38:
39: @Override
40: protected void setUp() throws Exception {
41: bean = new BrokerFactoryBean();
42: bean.setConfig(new ClassPathResource("inmemoryactivemq.xml"));
43: bean.afterPropertiesSet();
44: super .setUp();
45: }
46:
47: @Override
48: protected void tearDown() throws Exception {
49: super .tearDown();
50: bean.destroy();
51: }
52:
53: public LoanBrokerSmokeTest() {
54: Properties properties = new Properties();
55: properties.put("log4j.rootCategory", "INFO, stdout");
56: properties.put("log4j.appender.stdout",
57: "org.apache.log4j.ConsoleAppender");
58: properties.put("log4j.appender.stdout.layout",
59: "org.apache.log4j.PatternLayout");
60: properties.put(
61: "log4j.appender.stdout.layout.ConversionPattern",
62: "%p [%t] %c{1}.%M(%L) | %m%n");
63: PropertyConfigurator.configure(properties);
64: }
65:
66: public void testRegularLoanBroker() throws Exception {
67: DefaultServiceMixClient client = new DefaultServiceMixClient(
68: jbi);
69: InOut me = client.createInOutExchange();
70: me.setService(new QName("http://bpmscript.org/jbi",
71: "loanbroker"));
72: me.getInMessage().setContent(
73: new StringSource("<hello>world</hello>"));
74: assertTrue(client.sendSync(me, 1000000));
75: if (me.getStatus() == ExchangeStatus.ERROR) {
76: if (me.getFault() != null) {
77: fail("Received fault: "
78: + new SourceTransformer().toString(me
79: .getFault().getContent()));
80: } else if (me.getError() != null) {
81: throw me.getError();
82: } else {
83: fail("Received ERROR status");
84: }
85: }
86: }
87:
88: protected AbstractXmlApplicationContext createBeanFactory() {
89: return new ClassPathXmlApplicationContext(
90: "/loanbroker/spring.xml");
91: }
92:
93: }
|