001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.transport.jbi;
019:
020: import java.io.IOException;
021: import java.io.OutputStream;
022:
023: import javax.jbi.messaging.DeliveryChannel;
024:
025: import junit.framework.Assert;
026: import org.apache.cxf.Bus;
027: import org.apache.cxf.BusFactory;
028: import org.apache.cxf.message.Exchange;
029: import org.apache.cxf.message.ExchangeImpl;
030: import org.apache.cxf.message.Message;
031: import org.apache.cxf.service.model.BindingOperationInfo;
032: import org.apache.cxf.transport.Conduit;
033: import org.apache.cxf.transport.MessageObserver;
034: import org.apache.cxf.ws.addressing.EndpointReferenceType;
035: import org.easymock.classextension.EasyMock;
036: import org.easymock.classextension.IMocksControl;
037: import org.junit.After;
038: import org.junit.Before;
039:
040: public abstract class AbstractJBITest extends Assert {
041:
042: protected Bus bus;
043: protected EndpointReferenceType target;
044: protected MessageObserver observer;
045: protected Message inMessage;
046: protected IMocksControl control;
047: protected DeliveryChannel channel;
048:
049: @Before
050: public void setUp() {
051: BusFactory bf = BusFactory.newInstance();
052: bus = bf.createBus();
053: BusFactory.setDefaultBus(bus);
054: control = EasyMock.createNiceControl();
055: }
056:
057: @After
058: public void tearDown() {
059: bus.shutdown(true);
060: if (System.getProperty("cxf.config.file") != null) {
061: System.clearProperty("cxf.config.file");
062: }
063:
064: }
065:
066: protected JBIConduit setupJBIConduit(boolean send, boolean decoupled) {
067: if (decoupled) {
068: // setup the reference type
069: } else {
070: target = control.createMock(EndpointReferenceType.class);
071: }
072: channel = control.createMock(DeliveryChannel.class);
073: JBIConduit jbiConduit = new JBIConduit(bus, target, channel);
074:
075: if (send) {
076: // setMessageObserver
077: observer = new MessageObserver() {
078: public void onMessage(Message m) {
079: inMessage = m;
080: }
081: };
082: jbiConduit.setMessageObserver(observer);
083: }
084:
085: return jbiConduit;
086: }
087:
088: protected void sendoutMessage(Conduit conduit, Message message,
089: Boolean isOneWay) throws IOException {
090:
091: Exchange exchange = new ExchangeImpl();
092: exchange.setOneWay(isOneWay);
093: message.setExchange(exchange);
094: exchange.setInMessage(message);
095: BindingOperationInfo boi = control
096: .createMock(BindingOperationInfo.class);
097: exchange.put(BindingOperationInfo.class, boi);
098: try {
099: conduit.prepare(message);
100: } catch (IOException ex) {
101: assertFalse("JMSConduit can't perpare to send out message",
102: false);
103: ex.printStackTrace();
104: }
105: OutputStream os = message.getContent(OutputStream.class);
106: assertTrue("The OutputStream should not be null ", os != null);
107: os.write("HelloWorld".getBytes());
108: os.close();
109: }
110:
111: }
|