001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: *
022: *
023: * $Id: TestFileProvider.java 1475 2006-10-08 10:33:31Z jzhang $
024: */
025: package com.bostechcorp.cbesb.runtime.component.jms;
026:
027: import java.io.ByteArrayInputStream;
028: import java.io.File;
029: import java.net.URI;
030: import java.net.URL;
031:
032: import javax.jbi.messaging.ExchangeStatus;
033: import javax.jbi.messaging.InOnly;
034: import javax.jbi.messaging.InOut;
035: import javax.xml.namespace.QName;
036: import javax.xml.transform.stream.StreamSource;
037:
038: import junit.framework.TestCase;
039:
040: import org.apache.commons.logging.Log;
041: import org.apache.commons.logging.LogFactory;
042: import org.apache.servicemix.client.DefaultServiceMixClient;
043: import org.apache.servicemix.jbi.container.JBIContainer;
044:
045: /**
046: * @author Frank Ling
047: * @version 1.0.0
048: */
049: public class TestJMSProvider extends TestCase {
050:
051: protected final transient Log logger = LogFactory
052: .getLog(getClass());
053: protected JBIContainer container;
054:
055: protected void setUp() throws Exception {
056: container = new JBIContainer();
057: container.setUseMBeanServer(false);
058: container.setCreateMBeanServer(false);
059: container.setCreateJmxConnector(false);
060: container.setEmbedded(true);
061: container.init();
062: }
063:
064: protected void tearDown() throws Exception {
065: if (container != null) {
066: container.shutDown();
067: }
068: }
069:
070: /*
071: * The component flow for this testing are as follow:
072: *
073: * SMClient creates -> InOnly -> route FileComponent's Provider side ->
074: * Write into the outbox directory -> picked up by FilePoller -> route to
075: * ReceiverComponent
076: *
077: */
078: protected long testInOnly(String msg, boolean streaming)
079: throws Exception {
080:
081: // JMS Component
082: JMSComponent component = new JMSComponent();
083: container.activateComponent(component, "JMSProviderTest");
084:
085: // Start container
086: container.start();
087:
088: // Deploy SU
089: URL url = getClass().getClassLoader().getResource(
090: "provider/jms.wsdl");
091: File path = new File(new URI(url.toString()));
092: path = path.getParentFile();
093: component.getServiceUnitManager().deploy("provider",
094: path.getAbsolutePath());
095: component.getServiceUnitManager().start("provider");
096:
097: // Call it
098: DefaultServiceMixClient client = new DefaultServiceMixClient(
099: container);
100: InOnly in = client.createInOnlyExchange();
101: in.setInterfaceName(new QName(
102: "http://jms.bostechcorp.com/Test", "JMSInterface"));
103: in.getInMessage().setContent(
104: new StreamSource(new ByteArrayInputStream(msg
105: .getBytes())));
106:
107: long t0 = System.currentTimeMillis();
108: client.sendSync(in);
109: long t1 = System.currentTimeMillis();
110: assertTrue(in.getStatus() == ExchangeStatus.DONE);
111:
112: try {
113: Thread.sleep(10 * 1000);
114: } catch (InterruptedException e) {
115: e.printStackTrace();
116: }
117:
118: return t1 - t0;
119: }
120:
121: protected long testInOut(String msg, boolean streaming)
122: throws Exception {
123:
124: // JMS Component
125: JMSComponent component = new JMSComponent();
126: container.activateComponent(component, "JMSProviderTest");
127:
128: // Start container
129: container.start();
130:
131: // Deploy SU
132: URL url = getClass().getClassLoader().getResource(
133: "provider/jms.wsdl");
134: File path = new File(new URI(url.toString()));
135: path = path.getParentFile();
136: component.getServiceUnitManager().deploy("provider",
137: path.getAbsolutePath());
138: component.getServiceUnitManager().start("provider");
139:
140: // Call it
141: DefaultServiceMixClient client = new DefaultServiceMixClient(
142: container);
143: InOut inout = client.createInOutExchange();
144: inout.setInterfaceName(new QName(
145: "http://jms.bostechcorp.com/Test", "JMSInterface"));
146: inout.getInMessage().setContent(
147: new StreamSource(new ByteArrayInputStream(msg
148: .getBytes())));
149:
150: long t0 = System.currentTimeMillis();
151: client.sendSync(inout);
152: long t1 = System.currentTimeMillis();
153: assertTrue(inout.getStatus() == ExchangeStatus.DONE);
154:
155: try {
156: Thread.sleep(10 * 1000);
157: } catch (InterruptedException e) {
158: e.printStackTrace();
159: }
160:
161: return t1 - t0;
162: }
163:
164: /*
165: * public void testInOnly() throws Exception { testInOnly( "<DataEnvelope><XMLRecord><hello>world</hello></XMLRecord></DataEnvelope>",
166: * false); }
167: */
168:
169: public void testInOut() throws Exception {
170: testInOut(
171: "<DataEnvelope><XMLRecord><hello>world</hello></XMLRecord></DataEnvelope>",
172: false);
173: }
174:
175: }
|