001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.bpmscript.jbi.component;
018:
019: import java.io.File;
020: import java.net.URL;
021: import java.util.Properties;
022:
023: import javax.jbi.messaging.ExchangeStatus;
024: import javax.jbi.messaging.InOut;
025: import javax.naming.InitialContext;
026: import javax.xml.namespace.QName;
027:
028: import junit.framework.TestCase;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.apache.log4j.PropertyConfigurator;
033: import org.apache.servicemix.client.DefaultServiceMixClient;
034: import org.apache.servicemix.jbi.container.JBIContainer;
035: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
036: import org.apache.servicemix.jbi.jaxp.StringSource;
037:
038: public class BpmScriptComponentSmokeTest extends TestCase {
039:
040: private static Log logger = LogFactory
041: .getLog(BpmScriptComponentSmokeTest.class);
042:
043: protected JBIContainer container;
044:
045: public BpmScriptComponentSmokeTest() {
046: Properties properties = new Properties();
047: properties.put("log4j.rootCategory", "INFO, stdout");
048: properties.put("log4j.appender.stdout",
049: "org.apache.log4j.ConsoleAppender");
050: properties.put("log4j.appender.stdout.layout",
051: "org.apache.log4j.PatternLayout");
052: properties.put(
053: "log4j.appender.stdout.layout.ConversionPattern",
054: "%p [%t] %c{1}.%M(%L) | %m%n");
055: PropertyConfigurator.configure(properties);
056: }
057:
058: protected void setUp() throws Exception {
059: container = new JBIContainer();
060: container.setUseMBeanServer(false);
061: container.setCreateMBeanServer(false);
062: container.setMonitorInstallationDirectory(false);
063: container.setNamingContext(new InitialContext());
064: container.setEmbedded(true);
065: container.init();
066: }
067:
068: protected void tearDown() throws Exception {
069: if (container != null) {
070: container.shutDown();
071: }
072: }
073:
074: public void testCommonsAnnotations() throws Exception {
075: BpmScriptComponent component = new BpmScriptComponent();
076: container.activateComponent(component, "BpmScriptComponent");
077:
078: // Start container
079: container.start();
080:
081: // Deploy SU
082: component.getServiceUnitManager().deploy("echo",
083: getServiceUnitPath("good1"));
084: component.getServiceUnitManager().init("echo",
085: getServiceUnitPath("good1"));
086: component.getServiceUnitManager().start("echo");
087:
088: // Call it
089: DefaultServiceMixClient client = new DefaultServiceMixClient(
090: container);
091: InOut me = client.createInOutExchange();
092: me.setService(new QName("http://bpmscript.org/jbi", "echo"));
093: me
094: .getInMessage()
095: .setContent(
096: new StringSource(
097: "<echo xmlns='http://test'><in0>world</in0></echo>"));
098: client.sendSync(me);
099: if (me.getStatus() == ExchangeStatus.ERROR) {
100: if (me.getFault() != null) {
101: fail("Received fault: "
102: + new SourceTransformer().toString(me
103: .getFault().getContent()));
104: } else if (me.getError() != null) {
105: throw me.getError();
106: } else {
107: fail("Received ERROR status");
108: }
109: } else {
110: logger.info(new SourceTransformer().toString(me
111: .getOutMessage().getContent()));
112: }
113:
114: component.getServiceUnitManager().stop("echo");
115: component.getServiceUnitManager().shutDown("echo");
116: component.getServiceUnitManager().undeploy("echo",
117: getServiceUnitPath("good1"));
118: }
119:
120: protected String getServiceUnitPath(String name) {
121: URL url = getClass().getClassLoader().getResource(
122: name + "/xbean.xml");
123: File path = new File(url.getFile());
124: path = path.getParentFile();
125: return path.getAbsolutePath();
126: }
127:
128: }
|