SoapUtilities { public static List<SOAPElement> getParents( SOAPElement e ) { List<SOAPElement> parents = new ArrayList<SOAPElement>(); SOAPElement zwerg = e.getParentElement(); while ( zwerg != null ) { parents.add( zwerg ); zwerg = zwerg.getParentElement(); } return parents; }  static SOAPMessage stringToSoap( String soapString ); static String soapToString( SOAPElement element ); static Document stringToDom( String xmlString ); static List<SOAPElement> getSoapChilds( SOAPElement ele, QName name ); static List<SOAPElement> getSoapChilds( SOAPElement ele ); static List<SOAPElement> inputNeeded( SOAPElement ele ); static Map<String, String> allNamespaces( SOAPElement ele ); static List<SOAPElement> getParents( SOAPElement e ); static SOAPElement getRoot( SOAPElement e ); static final String SOAP_11_NAMESPACE_URL; static final String SOAP_12_NAMESPACE_URL; }
@Test public void testGetParents() throws Exception { String msg = new String( MESSAGE ); SOAPMessage soap = stringToSoap( msg ); SOAPElement ele = getSoapChilds( getSoapChilds( getSoapChilds( soap.getSOAPBody() ).get( 0 ) ).get( 1 ) ).get( 0 ); assertTrue( ele.getNodeName().equals( "ns2:d" ) ); List<SOAPElement> testParents = getParents( ele ); String[] trueParents = { "ns1:c", "ns1:ServiceOperation", "soapenv:Body", "soapenv:Envelope" }; for ( int i = 0; i < testParents.size(); ++i ) { String trueName = trueParents[i]; String testName = testParents.get( i ).getNodeName(); assertTrue( String.format( "Wrong Parent, got %s, but expected %s", testName, trueName ), trueName.equals( testName ) ); } }