You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2009/06/05 10:29:04 UTC

svn commit: r781940 - in /servicemix/smx4/features/trunk/cxf/cxf-binding-nmr: ./ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/servicemix/ src/test/java/org/apache/servicemix/cxf/ src/test/java/org/apach...

Author: ffang
Date: Fri Jun  5 08:29:04 2009
New Revision: 781940

URL: http://svn.apache.org/viewvc?rev=781940&view=rev
Log:
[SMX4-291]Improve test coverage :: SMX4 :: cxf-binding-nmr

Added:
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/NMRBindingFactoryTest.java   (with props)
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMRFaultOutInterceptorTest.java   (with props)
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMROperationInInterceptorTest.java   (with props)
Modified:
    servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/pom.xml

Modified: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/pom.xml?rev=781940&r1=781939&r2=781940&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/pom.xml (original)
+++ servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/pom.xml Fri Jun  5 08:29:04 2009
@@ -58,6 +58,19 @@
             <artifactId>org.apache.servicemix.specs.stax-api-1.0</artifactId>
             <version>${servicemix.specs.version}</version>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymockclassextension</artifactId>
+            <version>${easymock.version}</version>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
     <build>

Added: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/NMRBindingFactoryTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/NMRBindingFactoryTest.java?rev=781940&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/NMRBindingFactoryTest.java (added)
+++ servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/NMRBindingFactoryTest.java Fri Jun  5 08:29:04 2009
@@ -0,0 +1,56 @@
+/**
+ * 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.servicemix.cxf.binding.nmr;
+
+
+import org.apache.cxf.binding.Binding;
+import org.apache.cxf.interceptor.StaxOutInterceptor;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.servicemix.cxf.binding.nmr.interceptors.NMRFaultOutInterceptor;
+import org.apache.servicemix.cxf.binding.nmr.interceptors.NMROperationInInterceptor;
+import org.apache.servicemix.cxf.binding.nmr.interceptors.NMRWrapperInInterceptor;
+import org.apache.servicemix.cxf.binding.nmr.interceptors.NMRWrapperOutInterceptor;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NMRBindingFactoryTest extends Assert {
+
+    @Test
+    public void testCreateBinding() {
+        
+        NMRBindingInfo info = new NMRBindingInfo(new ServiceInfo(), "id");
+        Binding binding = new NMRBindingFactory().createBinding(info);
+        assertEquals(3, binding.getInInterceptors().size());
+        //assertEquals(?, binding.getInFaultInterceptors().size());
+        assertEquals(2, binding.getOutInterceptors().size());
+        assertEquals(2, binding.getOutFaultInterceptors().size());
+        assertEquals(NMROperationInInterceptor.class.getName(), 
+                        binding.getInInterceptors().get(1).getClass().getName());
+        assertEquals(NMRWrapperInInterceptor.class.getName(), 
+                        binding.getInInterceptors().get(2).getClass().getName());
+        assertEquals(StaxOutInterceptor.class.getName(), 
+                        binding.getOutInterceptors().get(0).getClass().getName());
+        assertEquals(NMRWrapperOutInterceptor.class.getName(), 
+                        binding.getOutInterceptors().get(1).getClass().getName());
+        assertEquals(StaxOutInterceptor.class.getName(), 
+                        binding.getOutFaultInterceptors().get(0).getClass().getName());
+        assertEquals(NMRFaultOutInterceptor.class.getName(), 
+                        binding.getOutFaultInterceptors().get(1).getClass().getName());
+    }
+}

Propchange: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/NMRBindingFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/NMRBindingFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMRFaultOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMRFaultOutInterceptorTest.java?rev=781940&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMRFaultOutInterceptorTest.java (added)
+++ servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMRFaultOutInterceptorTest.java Fri Jun  5 08:29:04 2009
@@ -0,0 +1,106 @@
+/**
+ * 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.servicemix.cxf.binding.nmr.interceptors;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ResourceBundle;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.phase.PhaseInterceptor;
+import org.apache.servicemix.cxf.binding.nmr.NMRMessage;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NMRFaultOutInterceptorTest extends Assert {
+    
+    @Test
+    public void testPhase() throws Exception {
+        PhaseInterceptor<NMRMessage> interceptor = new NMRFaultOutInterceptor();
+        assertEquals(Phase.MARSHAL, interceptor.getPhase());
+    }
+    
+    @Test
+    public void testNoWriter() throws Exception {
+        PhaseInterceptor<NMRMessage> interceptor = new NMRFaultOutInterceptor();
+        try {
+            NMRMessage msg = new NMRMessage(new MessageImpl());
+            interceptor.handleMessage(msg);
+            fail("Should have thrown an exception");
+        } catch (IllegalStateException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void testNoFault() throws Exception {
+        PhaseInterceptor<NMRMessage> interceptor = new NMRFaultOutInterceptor();
+        try {
+            NMRMessage msg = new NMRMessage(new MessageImpl());
+            msg.setContent(XMLStreamWriter.class, 
+                    XMLOutputFactory.newInstance().createXMLStreamWriter(new ByteArrayOutputStream()));
+            interceptor.handleMessage(msg);
+            fail("Should have thrown an exception");
+        } catch (IllegalStateException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void testEmptyFault() throws Exception {
+        PhaseInterceptor<NMRMessage> interceptor = new NMRFaultOutInterceptor();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(baos); 
+        NMRMessage msg = new NMRMessage(new MessageImpl());
+        msg.setContent(XMLStreamWriter.class, writer);
+        msg.setContent(Exception.class, new Exception("My fault"));
+        interceptor.handleMessage(msg);
+        writer.close();
+        Document doc = DOMUtils.readXml(new ByteArrayInputStream(baos.toByteArray()));
+        assertEquals("fault", doc.getDocumentElement().getFirstChild().getNodeName());
+    }
+
+    @Test
+    public void testDetailedFault() throws Exception {
+        PhaseInterceptor<NMRMessage> interceptor = new NMRFaultOutInterceptor();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(baos); 
+        NMRMessage msg = new NMRMessage(new MessageImpl());
+        Fault f = new Fault(new Message("FAULT", (ResourceBundle) null));
+        f.getOrCreateDetail();
+        f.getDetail().appendChild(f.getDetail().getOwnerDocument().createElementNS("urn:test", "myDetails"));
+        msg.setContent(XMLStreamWriter.class, writer);
+        msg.setContent(Exception.class, f);
+        interceptor.handleMessage(msg);
+        writer.close();
+        Document doc = DOMUtils.readXml(new ByteArrayInputStream(baos.toByteArray()));
+        assertEquals("urn:test", doc.getDocumentElement().getFirstChild().getNamespaceURI());
+        assertEquals("myDetails", doc.getDocumentElement().getFirstChild().getNodeName());
+    }
+
+}

Propchange: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMRFaultOutInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMRFaultOutInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMROperationInInterceptorTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMROperationInInterceptorTest.java?rev=781940&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMROperationInInterceptorTest.java (added)
+++ servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMROperationInInterceptorTest.java Fri Jun  5 08:29:04 2009
@@ -0,0 +1,98 @@
+/**
+ * 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.servicemix.cxf.binding.nmr.interceptors;
+
+
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.binding.BindingFactoryManager;
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.configuration.spring.ConfigurerImpl;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.endpoint.EndpointImpl;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.phase.PhaseInterceptor;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.test.TestApplicationContext;
+import org.apache.servicemix.cxf.binding.nmr.NMRBindingInfo;
+import org.apache.servicemix.cxf.binding.nmr.NMRConstants;
+import org.apache.servicemix.cxf.binding.nmr.NMRMessage;
+import org.apache.servicemix.nmr.api.Exchange;
+import org.easymock.classextension.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NMROperationInInterceptorTest extends Assert {
+
+    private static final Logger LOG = LogUtils.getL7dLogger(NMROperationInInterceptor.class);
+    private static final ResourceBundle BUNDLE = LOG.getResourceBundle();
+    
+    private static final String S1 = 
+        NMROperationInInterceptorTest.class.getResource("/META-INF/cxf/cxf.xml").toString();
+    private static final String S2 = 
+        NMROperationInInterceptorTest.class.getResource("/META-INF/cxf/binding/nmr/cxf-binding-nmr.xml").toString();
+    
+    @Test
+    public void testPhase() throws Exception {
+        PhaseInterceptor<NMRMessage> interceptor = new NMROperationInInterceptor();
+        assertEquals(Phase.PRE_PROTOCOL, interceptor.getPhase());
+    }
+    
+    @Test
+    public void testUnknownOperation() throws Exception {
+        PhaseInterceptor<NMRMessage> interceptor = new NMROperationInInterceptor();
+        NMRMessage msg = new NMRMessage(new MessageImpl());
+        Exchange me = EasyMock.createMock(Exchange.class);
+        EasyMock.expect(me.getOperation()).andReturn(new QName("urn:test", "SayHi")).times(4);
+        EasyMock.replay(me);
+        msg.put(Exchange.class, me);
+
+        TestApplicationContext ctx = new TestApplicationContext(new String[] {
+                S1, S2 });
+        ConfigurerImpl cfg = new ConfigurerImpl(ctx);
+        Bus bus = (Bus) ctx.getBean(Bus.DEFAULT_BUS_ID);
+        bus.setExtension(cfg, Configurer.class);
+        assertNotNull(bus.getExtension(BindingFactoryManager.class).getBindingFactory(NMRConstants.NS_NMR_BINDING));
+        
+        EndpointInfo endpointInfo = new EndpointInfo();
+        endpointInfo.setBinding(new NMRBindingInfo(null, NMRConstants.NS_NMR_BINDING));
+        Endpoint ep = new EndpointImpl(null, null, endpointInfo);
+        msg.setExchange(new ExchangeImpl());
+        msg.getExchange().put(Endpoint.class, ep);
+        try { 
+            interceptor.handleMessage(msg);
+            fail("shouldn't found SayHi operation");
+        } catch (Fault fault) {
+            assertEquals(fault.getMessage(), new Message("UNKNOWN_OPERATION", BUNDLE, 
+                                                 msg.getNmrExchange().getOperation().toString()).toString());
+        }
+    }
+    
+    
+}

Propchange: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMROperationInInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/smx4/features/trunk/cxf/cxf-binding-nmr/src/test/java/org/apache/servicemix/cxf/binding/nmr/interceptors/NMROperationInInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date