1 22 package org.jboss.test.webservice.jbws84; 23 24 import junit.framework.Test; 25 import org.jboss.test.webservice.WebserviceTestBase; 26 import org.w3c.dom.Document ; 27 28 import javax.naming.InitialContext ; 29 import javax.xml.parsers.DocumentBuilder ; 30 import javax.xml.parsers.DocumentBuilderFactory ; 31 import javax.xml.parsers.ParserConfigurationException ; 32 import javax.xml.rpc.Service ; 33 import javax.xml.soap.MessageFactory ; 34 import javax.xml.soap.Name ; 35 import javax.xml.soap.SOAPBody ; 36 import javax.xml.soap.SOAPElement ; 37 import javax.xml.soap.SOAPEnvelope ; 38 import javax.xml.soap.SOAPException ; 39 import javax.xml.soap.SOAPFactory ; 40 import javax.xml.soap.SOAPMessage ; 41 import java.io.ByteArrayInputStream ; 42 43 49 public class JBWS84TestCase extends WebserviceTestBase 50 { 51 52 public JBWS84TestCase(String name) 53 { 54 super(name); 55 } 56 57 58 public static Test suite() throws Exception 59 { 60 return getDeploySetup(JBWS84TestCase.class, "ws4ee-jbws84.war, ws4ee-jbws84-client.jar"); 61 } 62 63 66 public void testProcessSOAPElement() throws Exception 67 { 68 InitialContext iniCtx = getClientContext(); 69 Service service = (Service )iniCtx.lookup("java:comp/env/service/MessageService"); 70 Message port = (Message)service.getPort(Message.class); 71 72 MessageFactory factory = MessageFactory.newInstance(); 73 SOAPMessage reqMessage = factory.createMessage(); 74 75 DocumentBuilder builder = getDocumentBuilder(); 76 Document doc = builder.parse(new ByteArrayInputStream (Message.request.getBytes())); 77 reqMessage.getSOAPBody().addDocument(doc); 78 79 SOAPEnvelope soapEnvelope = reqMessage.getSOAPPart().getEnvelope(); 80 SOAPBody soapBody = soapEnvelope.getBody(); 81 SOAPElement reqElement = (SOAPElement )soapBody.getChildElements().next(); 82 83 SOAPElement resElement = port.processSOAPElement(reqElement); 84 validateResponse(resElement); 85 } 86 87 private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException 88 { 89 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); 91 docBuilderFactory.setNamespaceAware(true); 92 93 DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); 94 return builder; 95 } 96 97 private void validateResponse(SOAPElement resElement) 98 throws SOAPException 99 { 100 SOAPFactory factory = SOAPFactory.newInstance(); 101 102 Name expName = factory.createName("Response", Message.PREFIX, Message.NAMESPACE_URI); 103 Name elementName = resElement.getElementName(); 104 assertEquals(expName, elementName); 105 106 expName = factory.createName("POID"); 107 SOAPElement poidElement = (SOAPElement )resElement.getChildElements(expName).next(); 108 elementName = poidElement.getElementName(); 109 assertEquals(expName, elementName); 110 111 String elementValue = poidElement.getValue(); 112 assertEquals("12345", elementValue); 113 114 expName = factory.createName("Status"); 115 SOAPElement statusElement = (SOAPElement )resElement.getChildElements(expName).next(); 116 elementName = statusElement.getElementName(); 117 assertEquals(expName, elementName); 118 119 elementValue = statusElement.getValue(); 120 assertEquals("ok", elementValue); 121 } 122 } 123 | Popular Tags |