001: /*
002: * Copyright 2005-2006 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.bpmscript.client;
017:
018: import java.util.Properties;
019:
020: import javax.jbi.servicedesc.ServiceEndpoint;
021: import javax.naming.InitialContext;
022: import javax.xml.namespace.QName;
023:
024: import junit.framework.TestCase;
025:
026: import org.apache.activemq.xbean.BrokerFactoryBean;
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.apache.log4j.PropertyConfigurator;
030: import org.apache.servicemix.client.DefaultServiceMixClient;
031: import org.apache.servicemix.jbi.container.JBIContainer;
032: import org.springframework.core.io.ClassPathResource;
033:
034: public class SpringClientTest extends TestCase {
035:
036: private static Log logger = LogFactory
037: .getLog(SpringClientTest.class);
038:
039: private BrokerFactoryBean bean;
040:
041: protected void setUp() throws Exception {
042: super .setUp();
043: Properties properties = new Properties();
044: properties.put("log4j.rootCategory", "INFO, stdout");
045: properties.put("log4j.appender.stdout",
046: "org.apache.log4j.ConsoleAppender");
047: properties.put("log4j.appender.stdout.layout",
048: "org.apache.log4j.PatternLayout");
049: PropertyConfigurator.configure(properties);
050:
051: bean = new BrokerFactoryBean();
052: bean.setConfig(new ClassPathResource("inmemoryactivemq.xml"));
053: bean.afterPropertiesSet();
054: }
055:
056: protected void tearDown() throws Exception {
057: super .tearDown();
058: bean.destroy();
059: }
060:
061: public void test() throws Exception {
062:
063: JBIContainer container = new JBIContainer();
064: container.setName("org.bpmscript.client.SpringClientTest");
065: container.setUseMBeanServer(false);
066: container.setCreateMBeanServer(false);
067: container.setMonitorInstallationDirectory(false);
068: container.setNamingContext(new InitialContext());
069: container.setFlowName("jms?jmsURL=tcp://localhost:61616");
070: container.setEmbedded(false);
071: container.init();
072: container.start();
073: DefaultServiceMixClient client = new DefaultServiceMixClient(
074: container);
075: ServiceEndpoint[] endpointsForService = client.getContext()
076: .getEndpointsForService(
077: new QName("http://www.vnocore.com/jbi",
078: "rpc-component"));
079: for (ServiceEndpoint endpoint : endpointsForService) {
080: System.out.println(endpoint);
081: }
082:
083: // InOut me = client.createInOutExchange();
084: // me.setService(new QName("http://www.vnocore.com/jbi", "rpc-component"));
085: // me.getInMessage().setProperty("interface", "com.vnocore.catalogue.facade.ICatalogueFacade");
086: // me.getInMessage().setProperty("operation", "getCatalogue");
087: // me.getInMessage().setContent(new StringSource("<object-array>" +
088: // "<com.vnocore.common.model.Locality>" +
089: // "<country>GB</country><language>en</language>" +
090: // "<variant></variant>" +
091: // "</com.vnocore.common.model.Locality></object-array>"));
092: // client.sendSync(me);
093: // if (me.getStatus() == ExchangeStatus.ERROR) {
094: // if (me.getFault() != null) {
095: // fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
096: // } else if (me.getError() != null) {
097: // throw me.getError();
098: // } else {
099: // fail("Received ERROR status");
100: // }
101: // } else {
102: // logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
103: // }
104: // Thread.sleep(1000);
105: container.shutDown();
106: }
107:
108: // protected AbstractXmlApplicationContext createBeanFactory() {
109: // return new ClassPathXmlApplicationContext("org/bpmscript/client/spring.xml");
110: // }
111:
112: }
|