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 it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * 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 MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: BasicTest.java 4575 2007-01-18 11:49:23Z jzhang $
023: */
024:
025: package com.bostechcorp.cbesb.runtime.component.jdbc;
026:
027: import java.io.File;
028: import java.net.URI;
029: import java.net.URL;
030:
031: import javax.jbi.messaging.ExchangeStatus;
032: import javax.jbi.messaging.InOut;
033: import javax.jbi.messaging.NormalizedMessage;
034: import javax.xml.namespace.QName;
035: import javax.xml.transform.Source;
036:
037: import org.apache.servicemix.client.DefaultServiceMixClient;
038: import org.apache.servicemix.jbi.container.JBIContainer;
039: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
040: import org.apache.servicemix.jbi.messaging.InOutImpl;
041:
042: import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.StringSource;
043:
044: import junit.framework.TestCase;
045:
046: public class BasicTest extends TestCase {
047:
048: protected JBIContainer container;
049:
050: protected void setUp() throws Exception {
051: container = new JBIContainer();
052: container.setUseMBeanServer(false);
053: container.setCreateMBeanServer(false);
054: container.setEmbedded(true);
055: container.setCreateJmxConnector(false);
056: container.init();
057: }
058:
059: protected void tearDown() throws Exception {
060: if (container != null) {
061: container.shutDown();
062: }
063: }
064:
065: public void test1() throws Throwable {
066: JdbcComponent jdbcComponent = new JdbcComponent();
067: container.activateComponent(jdbcComponent, "jdbcService");
068:
069: // Start container
070: container.start();
071:
072: // Deploy SU
073: URL url = getClass().getClassLoader().getResource(
074: "jdbc/jdbc.wsdl");
075: File path = new File(new URI(url.toString()));
076: path = path.getParentFile();
077: jdbcComponent.getServiceUnitManager().deploy("jdbc",
078: path.getAbsolutePath());
079: jdbcComponent.getServiceUnitManager().start("jdbc");
080:
081: // Call it
082: DefaultServiceMixClient client = new DefaultServiceMixClient(
083: container);
084: InOut inout = new InOutImpl("exchangeId");
085: inout.setInterfaceName(new QName(
086: "http://jdbc.bostechcorp.com/Test", "jdbcInterface"));
087:
088: //create message content
089: String content = "<DataEnvelope><XMLRecord>"
090: + "<jdbc_request xmlns='http://cbesb.bostechcorp.com/jdbc/1.0'>"
091: + "<execute>"
092: + "<statement>select stor_id, stor_name, stor_address, city, state, zip from stores</statement>"
093: + "</execute>" + "</jdbc_request>"
094: + "</XMLRecord></DataEnvelope>";
095: StringSource inSrc = new StringSource(content);
096: NormalizedMessage nmsg = inout.createMessage();
097: nmsg.setContent(inSrc);
098: inout.setMessage(nmsg, "In");
099:
100: boolean result = client.sendSync(inout);
101: assertTrue(result);
102: assertTrue(inout.getStatus() == ExchangeStatus.ACTIVE);
103: NormalizedMessage out = inout.getOutMessage();
104: assertNotNull(out);
105: Source outSrc = out.getContent();
106: assertNotNull(outSrc);
107:
108: String resultXML = "";
109: System.err.println(resultXML = new SourceTransformer()
110: .toString(outSrc));
111:
112: inout.setStatus(ExchangeStatus.DONE);
113: client.send(inout);
114:
115: // Let us sleep for a while and give other side a chance to receive exchange
116: try {
117: Thread.sleep(5 * 1000);
118: } catch (InterruptedException e) {
119: // TODO Auto-generated catch block
120: e.printStackTrace();
121: }
122:
123: jdbcComponent.getServiceUnitManager().stop("jdbc");
124: jdbcComponent.getServiceUnitManager().shutDown("jdbc");
125: jdbcComponent.getServiceUnitManager().undeploy("jdbc",
126: path.getAbsolutePath());
127:
128: }
129: }
|