cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r537890 - in /incubator/cxf/branches/headerwork/rt/ws/addr/src: main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
Date Mon, 14 May 2007 15:48:30 GMT
Author: eglynn
Date: Mon May 14 08:48:29 2007
New Revision: 537890

URL: http://svn.apache.org/viewvc?view=rev&rev=537890
Log:
Modified WS-A unit tests to reflect changes to header processing logic in the code.


Modified:
    incubator/cxf/branches/headerwork/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
    incubator/cxf/branches/headerwork/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java

Modified: incubator/cxf/branches/headerwork/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java?view=diff&rev=537890&r1=537889&r2=537890
==============================================================================
--- incubator/cxf/branches/headerwork/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
(original)
+++ incubator/cxf/branches/headerwork/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
Mon May 14 08:48:29 2007
@@ -40,6 +40,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.binding.soap.SoapFault;
@@ -82,6 +83,7 @@
         Collections.synchronizedMap(new HashMap<String, Exchange>());
 
     private VersionTransformer transformer;
+    private HeaderFactory headerFactory;
     
     /**
      * Constructor.
@@ -147,20 +149,8 @@
             try {
                 List<Header> header = message.getHeaders();
                 discardMAPs(header, maps);
-//                List<Header> extraHdrs = new ArrayList<Header>();
 
-                Document doc = DOMUtils.createDocument();
-                SoapVersion version = Soap11.getInstance();
-                Element hdr = doc.createElementNS(version.getHeader().getNamespaceURI(),

-                        version.getHeader().getLocalPart());
-                
-                //ubhole: This doesn't seems to matter as we need to add on each node now.
-
-                // add WSA namespace declaration to header, instead of
-                // repeating in each individual child node
-//                hdr.setAttributeNS("http://www.w3.org/2000/xmlns/",
-//                                      "xmlns:" + Names.WSA_NAMESPACE_PREFIX,
-//                                      maps.getNamespaceURI());
+                Element hdr = getHeaderFactory().getHeader();                
                 JAXBContext jaxbContext = 
                     VersionTransformer.getExposedJAXBContext(
                                                      maps.getNamespaceURI());
@@ -204,17 +194,14 @@
                                 marshaller);
                 encodeReferenceParameters(maps, hdr, marshaller);
                 
-                for (int i = 0; i < hdr.getChildNodes().getLength(); i++) {
-                    Node node = hdr.getChildNodes().item(i);
+                NodeList children = hdr.getChildNodes();
+                for (int i = 0; i < children.getLength(); i++) {
+                    Node node = children.item(i);
                     
-//                    System.out.println("node name : " + node.getLocalName() 
-//                    +  " namespace URI" + node.getNamespaceURI());
                     if (node instanceof Element) {
                         ((Element) node).setAttributeNS("http://www.w3.org/2000/xmlns/",
                                 "xmlns:" + Names.WSA_NAMESPACE_PREFIX,
                                 maps.getNamespaceURI());
-                    } else {
-                        System.out.println("Should not come here...");
                     }
               
                     Header holder = new Header(
@@ -331,8 +318,6 @@
                             if (unmarshaller == null) {
                                 JAXBContext jaxbContext = 
                                     VersionTransformer.getExposedJAXBContext(headerURI);
-//                                System.out.println("JAxbcontext supports : " + jaxbContext.toString());
-                                
                                 unmarshaller = 
                                     jaxbContext.createUnmarshaller();
                             }
@@ -493,7 +478,6 @@
                                  Marshaller marshaller) throws JAXBException {
         if (value != null) {
             marshaller.marshal(new JAXBElement<T>(qname, clz, value), header);
-//            System.out.println("Last header child is : " + header.getLastChild());
         }
     }
 
@@ -508,7 +492,6 @@
     protected <T> T decodeMAP(Class<T> clz,
                               Element headerElement,
                               Unmarshaller unmarshaller) throws JAXBException {
-//        System.out.println("unmarshaller supports : " + unmarshaller);
         JAXBElement<T> element =
             unmarshaller.unmarshal(headerElement, clz);
         return element.getValue();
@@ -649,7 +632,28 @@
             message.put(Message.PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
         } 
     }
+    
+    protected HeaderFactory getHeaderFactory() {
+        if (headerFactory == null) {
+            headerFactory = new HeaderFactory() {
+                public Element getHeader() {
+                    Document doc = DOMUtils.createDocument();
+                    SoapVersion version = Soap11.getInstance();
+                    return doc.createElementNS(version.getHeader().getNamespaceURI(),
+                                               version.getHeader().getLocalPart());
+                }
+            };
+        }
+        return headerFactory;
+    }
+    
+    protected void setHeaderFactory(HeaderFactory factory) {
+        headerFactory = factory;
+    }
 
+    public interface HeaderFactory {
+        Element getHeader();
+    }
 }
 
 

Modified: incubator/cxf/branches/headerwork/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/headerwork/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java?view=diff&rev=537890&r1=537889&r2=537890
==============================================================================
--- incubator/cxf/branches/headerwork/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
(original)
+++ incubator/cxf/branches/headerwork/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
Mon May 14 08:48:29 2007
@@ -243,9 +243,14 @@
         message.put(REQUESTOR_ROLE, Boolean.valueOf(requestor));
         String mapProperty = getMAPProperty(requestor, outbound);
         AddressingPropertiesImpl maps = getMAPs(requestor, outbound, exposeAs);
-        Element header = control.createMock(Element.class);
-//        message.setHeaders(Element.class, header);
-//        List<Header> header = message.getHeaders();
+        final Element header = control.createMock(Element.class);
+        codec.setHeaderFactory(new MAPCodec.HeaderFactory() {
+            public Element getHeader() {
+                return header;
+            }
+        });
+        List<Header> headers = new ArrayList<Header>(); 
+        message.put(Header.HEADER_LIST, headers);
         JAXBContext jaxbContext = control.createMock(JAXBContext.class);
         ContextUtils.setJAXBContext(jaxbContext);
         VersionTransformer.Names200408.setJAXBContext(jaxbContext);
@@ -258,8 +263,7 @@
                         invalidMAP,
                         preExistingSOAPAction);
         } else {
-            List<Header> hdr = message.getHeaders();
-            setUpDecode(message, hdr, maps, mapProperty, requestor);
+            setUpDecode(message, headers, maps, mapProperty, requestor);
         }
         control.replay();
         return message;
@@ -273,16 +277,6 @@
                              boolean invalidMAP,
                              boolean preExistingSOAPAction) throws Exception { 
         message.put(mapProperty, maps);
-//        NodeList headerElements = control.createMock(NodeList.class);
-//        header.getElementsByTagNameNS(EasyMock.eq(maps.getNamespaceURI()),
-//                                      EasyMock.eq("*"));
-//        EasyMock.expectLastCall().andReturn(headerElements);
-//        headerElements.getLength();
-//        EasyMock.expectLastCall().andReturn(0);
-//        header.setAttributeNS(EasyMock.eq("http://www.w3.org/2000/xmlns/"),
-//                              EasyMock.eq("xmlns:" + Names.WSA_NAMESPACE_PREFIX),
-//                              EasyMock.eq(maps.getNamespaceURI()));
-//        EasyMock.expectLastCall();
         Marshaller marshaller = control.createMock(Marshaller.class);
         ContextUtils.getJAXBContext().createMarshaller();
         EasyMock.expectLastCall().andReturn(marshaller);
@@ -294,13 +288,28 @@
                                : expectedValues.length;
         for (int i = 0; i < expectedMarshals; i++) {
             EasyMock.reportMatcher(matcher);
-            
-            
-//            Element elem = null;
             EasyMock.eq(header);
             marshaller.marshal(null, header);
             EasyMock.expectLastCall();
         }
+        
+        NodeList children = control.createMock(NodeList.class);
+        header.getChildNodes();
+        EasyMock.expectLastCall().andReturn(children);
+        children.getLength();
+        EasyMock.expectLastCall().andReturn(1);
+        Element child = control.createMock(Element.class);
+        children.item(0);
+        EasyMock.expectLastCall().andReturn(child);
+        child.setAttributeNS(EasyMock.eq("http://www.w3.org/2000/xmlns/"),
+                             EasyMock.eq("xmlns:" + Names.WSA_NAMESPACE_PREFIX),
+                             EasyMock.eq(maps.getNamespaceURI()));
+        EasyMock.expectLastCall();
+        child.getNamespaceURI();
+        EasyMock.expectLastCall().andReturn("bar");
+        child.getLocalName();
+        EasyMock.expectLastCall().andReturn("foo");
+        
         mimeHeaders = new HashMap<String, List<String>>();
         message.put(MIME_HEADERS, mimeHeaders);
         if (preExistingSOAPAction) {
@@ -317,25 +326,20 @@
     }
     
     private void setUpDecode(SoapMessage message, 
-                             List<Header> header,
+                             List<Header> headers,
                              AddressingPropertiesImpl maps,
                              String mapProperty,
                              boolean requestor) throws Exception {
         Unmarshaller unmarshaller = control.createMock(Unmarshaller.class);
         ContextUtils.getJAXBContext().createUnmarshaller();
         EasyMock.expectLastCall().andReturn(unmarshaller);
-        NodeList headerElements = control.createMock(NodeList.class);
-//        header.getChildNodes();
-        EasyMock.expectLastCall().andReturn(headerElements);
         String uri = maps.getNamespaceURI();
         boolean exposedAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
         boolean exposedAs200408 = 
             VersionTransformer.Names200408.WSA_NAMESPACE_NAME.equals(uri);
         assertTrue("unexpected namescape URI: " + uri, 
                    exposedAsNative || exposedAs200408);
-        headerElements.getLength();
-        EasyMock.expectLastCall().andReturn(6);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_MESSAGEID_NAME,
                           exposedAsNative
@@ -343,7 +347,7 @@
                           : AttributedURI.class,
                           0,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_TO_NAME,
                           exposedAsNative
@@ -351,7 +355,7 @@
                           : AttributedURI.class,
                           1,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_REPLYTO_NAME,
                           exposedAsNative
@@ -359,7 +363,7 @@
                           : VersionTransformer.Names200408.EPR_TYPE,
                           2,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_FAULTTO_NAME,
                           exposedAsNative
@@ -367,7 +371,7 @@
                           : VersionTransformer.Names200408.EPR_TYPE,
                           3,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_RELATESTO_NAME,
                           exposedAsNative
@@ -375,7 +379,7 @@
                           : Relationship.class,
                           4,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_ACTION_NAME,
                           exposedAsNative
@@ -385,7 +389,7 @@
                           unmarshaller);
     }
 
-    private <T> void setUpHeaderDecode(NodeList headerElements,
+    private <T> void setUpHeaderDecode(List<Header> headers,
                                        String uri,
                                        String name,
                                        Class<T> clz,
@@ -393,8 +397,7 @@
                                        Unmarshaller unmarshaller) 
         throws Exception { 
         Element headerElement = control.createMock(Element.class);
-        headerElements.item(index);
-        EasyMock.expectLastCall().andReturn(headerElement).times(2);
+        headers.add(new Header(new QName(uri, name), headerElement));
         headerElement.getNamespaceURI();
         EasyMock.expectLastCall().andReturn(uri);
         headerElement.getLocalName();
@@ -518,7 +521,6 @@
             Object value = expectedValues[expectedIndex];
             boolean ret = false;
             expectedIndex++;
-            System.out.println("Expected index is : " + expectedIndex);
             if (expectedIndex == 5 && !expectRelatesTo) {
                 return true;
             }
@@ -532,7 +534,7 @@
         }
 
         public void appendTo(StringBuffer buffer) {
-            buffer.append("JAXBElements did not match");
+            buffer.append("JAXBElements did not match[" + expectedIndex + "]");
         }
         
         private boolean compare(Object a, Object b) {



Mime
View raw message