cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r542771 - in /incubator/cxf/trunk/rt/transports/jbi/src: main/java/org/apache/cxf/transport/jbi/ test/java/org/ test/java/org/apache/ test/java/org/apache/cxf/ test/java/org/apache/cxf/transport/ test/java/org/apache/cxf/transport/jbi/
Date Wed, 30 May 2007 07:47:27 GMT
Author: ffang
Date: Wed May 30 00:47:25 2007
New Revision: 542771

URL: http://svn.apache.org/viewvc?view=rev&rev=542771
Log:
[CXF-692] add test for JBIConduit

Added:
    incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/
    incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/
    incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/
    incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/
    incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/
    incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/AbstractJBITest.java
  (with props)
    incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java
  (with props)
    incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduit.java
    incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduitOutputStream.java

Modified: incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduit.java?view=diff&rev=542771&r1=542770&r2=542771
==============================================================================
--- incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduit.java
(original)
+++ incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduit.java
Wed May 30 00:47:25 2007
@@ -28,6 +28,7 @@
 
 
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.transport.AbstractConduit;
@@ -39,12 +40,22 @@
     private static final Logger LOG = LogUtils.getL7dLogger(JBIConduit.class);
 
     private DeliveryChannel channel;
+    private Bus bus;
            
     public JBIConduit(EndpointReferenceType target, DeliveryChannel dc) {           
+        this(null, target, dc);
+    }
+    
+    public JBIConduit(Bus b, EndpointReferenceType target, DeliveryChannel dc) {
         super(target);
         channel = dc;
+        bus = b;
     }
 
+    public Bus getBus() {
+        return bus;
+    }
+    
     protected Logger getLogger() {
         return LOG;
     }

Modified: incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduitOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduitOutputStream.java?view=diff&rev=542771&r1=542770&r2=542771
==============================================================================
--- incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduitOutputStream.java
(original)
+++ incubator/cxf/trunk/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIConduitOutputStream.java
Wed May 30 00:47:25 2007
@@ -22,6 +22,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.util.logging.Logger;
 
@@ -38,6 +39,7 @@
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.io.AbstractCachedOutputStream;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -80,9 +82,10 @@
 
     private void commitOutputMessage() throws IOException {
         try {
-            Method targetMethod = (Method) message.get(Method.class.getName());
-            Class<?> clz = targetMethod.getDeclaringClass();
-            BindingOperationInfo bop = message.getExchange().get(BindingOperationInfo.class);
+            Member member = (Member) message.get(Method.class.getName());
+            Class<?> clz = member.getDeclaringClass();
+            Exchange exchange = message.getExchange();
+            BindingOperationInfo bop = exchange.get(BindingOperationInfo.class);
 
             LOG.info(new org.apache.cxf.common.i18n.Message("INVOKE.SERVICE", LOG).toString()
+ clz);
 
@@ -130,7 +133,9 @@
                     
                     Message inMessage = new MessageImpl();
                     message.getExchange().setInMessage(inMessage);
-                    XMLStreamReader reader = StaxUtils.createXMLStreamReader(outMsg.getContent());
+                    Source source = outMsg.getContent();
+                    XMLStreamReader reader = StaxUtils.createXMLStreamReader(source);
+                    
                     inMessage.setContent(XMLStreamReader.class, reader);
                     conduit.getMessageObserver().onMessage(inMessage);
                     

Added: incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/AbstractJBITest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/AbstractJBITest.java?view=auto&rev=542771
==============================================================================
--- incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/AbstractJBITest.java
(added)
+++ incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/AbstractJBITest.java
Wed May 30 00:47:25 2007
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.transport.jbi;
+
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.jbi.messaging.DeliveryChannel;
+
+import junit.framework.Assert;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+import org.junit.After;
+import org.junit.Before;
+
+
+public abstract class AbstractJBITest extends Assert {
+       
+    protected Bus bus;
+    protected EndpointReferenceType target;
+    protected MessageObserver observer;
+    protected Message inMessage;
+    protected IMocksControl control;
+    protected DeliveryChannel channel;
+    @Before
+    public void setUp() {
+        BusFactory bf = BusFactory.newInstance();
+        bus = bf.createBus();
+        BusFactory.setDefaultBus(bus);
+        control = EasyMock.createNiceControl();
+    }
+    
+    @After
+    public void tearDown() {
+        bus.shutdown(true);
+        if (System.getProperty("cxf.config.file") != null) {
+            System.clearProperty("cxf.config.file");
+        }
+        
+    }
+    
+    protected JBIConduit setupJBIConduit(boolean send, boolean decoupled) {
+        if (decoupled) {
+            // setup the reference type
+        } else {
+            target = control.createMock(EndpointReferenceType.class);
+        }    
+        channel = control.createMock(DeliveryChannel.class);
+        JBIConduit jbiConduit = new JBIConduit(bus, target, channel);
+        
+        if (send) {
+            // setMessageObserver
+            observer = new MessageObserver() {
+                public void onMessage(Message m) {                    
+                    inMessage = m;
+                }
+            };
+            jbiConduit.setMessageObserver(observer);
+        }
+        
+        return jbiConduit;        
+    }
+    
+    protected void sendoutMessage(Conduit conduit, Message message, Boolean isOneWay) throws
IOException {
+        
+        Exchange exchange = new ExchangeImpl();
+        exchange.setOneWay(isOneWay);
+        message.setExchange(exchange);
+        exchange.setInMessage(message);
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        exchange.put(BindingOperationInfo.class, boi);
+        try {
+            conduit.prepare(message);
+        } catch (IOException ex) {
+            assertFalse("JMSConduit can't perpare to send out message", false);
+            ex.printStackTrace();            
+        }            
+        OutputStream os = message.getContent(OutputStream.class);
+        assertTrue("The OutputStream should not be null ", os != null);
+        os.write("HelloWorld".getBytes());
+        os.close();            
+    }
+    
+
+}

Propchange: incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/AbstractJBITest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/AbstractJBITest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java?view=auto&rev=542771
==============================================================================
--- incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java
(added)
+++ incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java
Wed May 30 00:47:25 2007
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.transport.jbi;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.logging.Logger;
+
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.easymock.classextension.EasyMock;
+import org.junit.Test;
+
+public class JBIConduitTest extends AbstractJBITest {
+    static final Logger LOG = Logger.getLogger(JBIDestinationTest.class.getName());
+
+    
+    @Test
+    public void testPrepare() throws Exception {
+        LOG.info("test prepare");
+        JBIConduit conduit = setupJBIConduit(false, false);
+        Message message = new MessageImpl();
+        try {
+            conduit.prepare(message);
+        } catch (Exception ex) {
+            ex.printStackTrace();            
+        }
+        assertNotNull(message.getContent(OutputStream.class));
+        assertTrue(message.getContent(OutputStream.class) instanceof JBIConduitOutputStream);
+    }
+    
+    @Test
+    public void testSendOut() throws Exception {
+        LOG.info("test send");
+        JBIConduit conduit = setupJBIConduit(true, false); 
+        Message message = new MessageImpl();
+        Member method = control.createMock(Member.class);
+        message.put(Method.class.getName(), method);
+                
+        EasyMock.expect(method.getDeclaringClass()).andStubReturn(
+                                        (Class<?>)org.apache.hello_world_soap_http.Greeter.class);
+        
+                
+        
+        Exchange exchange = new ExchangeImpl();
+        exchange.setOneWay(false);
+        message.setExchange(exchange);
+        exchange.setInMessage(message);
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
+        EasyMock.expect(boi.getOutput()).andReturn(bmi);
+        exchange.put(BindingOperationInfo.class, boi);
+        MessageExchangeFactory factory = control.createMock(MessageExchangeFactory.class);
+        EasyMock.expect(channel.createExchangeFactoryForService(
+                        null)).andReturn(factory);
+        InOut xchg = control.createMock(InOut.class);
+        EasyMock.expect(factory.createInOutExchange()).andReturn(xchg);
+        NormalizedMessage inMsg = control.createMock(NormalizedMessage.class);
+        EasyMock.expect(xchg.createMessage()).andReturn(inMsg);
+        NormalizedMessage outMsg = control.createMock(NormalizedMessage.class);
+        EasyMock.expect(xchg.getOutMessage()).andReturn(outMsg);
+        
+        Source source = new StreamSource(new ByteArrayInputStream(
+                            "<message>TestHelloWorld</message>".getBytes()));
+        EasyMock.expect(outMsg.getContent()).andReturn(source);
+        control.replay();
+        try {
+            conduit.prepare(message);
+        } catch (IOException ex) {
+            assertFalse("JMSConduit can't perpare to send out message", false);
+            ex.printStackTrace();            
+        }            
+        OutputStream os = message.getContent(OutputStream.class);
+        assertTrue("The OutputStream should not be null ", os != null);
+        os.write("HelloWorld".getBytes());
+        os.close();               
+        XMLStreamReader reader = inMessage.getContent(XMLStreamReader.class);
+        reader.nextTag();
+         
+        String reponse = reader.getElementText();
+        assertEquals("The reponse date should be equals", reponse, "TestHelloWorld");
+    }
+}

Propchange: incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java?view=auto&rev=542771
==============================================================================
--- incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java
(added)
+++ incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java
Wed May 30 00:47:25 2007
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.transport.jbi;
+
+import java.util.logging.Logger;
+
+import org.junit.Test;
+
+public class JBIDestinationTest extends AbstractJBITest {
+    static final Logger LOG = Logger.getLogger(JBIDestinationTest.class.getName());
+    @Test
+    public void testDestination() throws Exception {
+        LOG.info("JBI destination test");
+    }
+}

Propchange: incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message