1 19 20 package org.netbeans.modules.xml.wsdl.model.spi; 21 22 import java.util.List ; 23 import javax.xml.namespace.QName ; 24 import junit.framework.*; 25 import org.netbeans.modules.xml.wsdl.model.BindingOutput; 26 import org.netbeans.modules.xml.wsdl.model.Definitions; 27 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement; 28 import org.netbeans.modules.xml.wsdl.model.TestCatalogModel; 29 import org.netbeans.modules.xml.wsdl.model.Util; 30 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 31 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody; 32 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPHeader; 33 import org.netbeans.modules.xml.wsdl.model.visitor.FindWSDLComponent; 34 import org.w3c.dom.Element ; 35 36 40 public class GenericExtensibilityElementTest extends TestCase { 41 42 public GenericExtensibilityElementTest(String testName) { 43 super(testName); 44 } 45 46 protected void setUp() throws Exception { 47 } 48 49 protected void tearDown() throws Exception { 50 TestCatalogModel.getDefault().clearDocumentPool(); 51 } 52 53 public static Test suite() { 54 TestSuite suite = new TestSuite(GenericExtensibilityElementTest.class); 55 56 return suite; 57 } 58 59 public void testAnyElement() throws Exception { 60 WSDLModel model = Util.loadWSDLModel("resources/echo.wsdl"); 61 Definitions definitions = model.getDefinitions(); 62 String xpath = "/definitions/binding/operation[@name='operation_0']/output"; 63 BindingOutput output = FindWSDLComponent.findComponent(BindingOutput.class, definitions, xpath); 64 assertEquals("output", output.getName()); 65 List <ExtensibilityElement> allEEs = output.getExtensibilityElements(); 66 assertEquals(1, allEEs.size()); 67 SOAPBody body = output.getExtensibilityElements(SOAPBody.class).get(0); 68 assertEquals("someNS", body.getAnyElements().get(0).getQName().getNamespaceURI()); 69 70 SOAPBody innerBody = model.getFactory().createSOAPBody(); 71 model.startTransaction(); 72 body.addExtensibilityElement(innerBody); 73 model.endTransaction(); 74 75 String localName = "element0"; 76 Element e0 = model.getDocument().createElementNS("someNS", localName); 77 GenericExtensibilityElement gee = new GenericExtensibilityElement(model, e0); 78 model.startTransaction(); 79 body.addAnyElement(gee, 0); 80 model.endTransaction(); 81 assertEquals(localName, body.getAnyElements().get(0).getPeer().getLocalName()); 82 83 localName = "element2"; 84 Element e2 = model.getDocument().createElementNS("someNS", localName); 85 GenericExtensibilityElement gee2 = new GenericExtensibilityElement(model, e2); 86 model.startTransaction(); 87 body.addAnyElement(gee2, 2); 88 model.endTransaction(); 89 assertEquals(localName, body.getAnyElements().get(2).getPeer().getLocalName()); 90 assertTrue(body.getExtensibilityElements().get(3) instanceof SOAPBody); 91 92 model.startTransaction(); 93 body.removeAnyElement(gee); 94 localName = "element1"; 95 Element e1 = model.getDocument().createElementNS("someNS", localName); 96 GenericExtensibilityElement gee1 = new GenericExtensibilityElement(model, e1); 97 body.addAnyElement(gee1, 1); 98 model.endTransaction(); 99 assertEquals(localName, body.getAnyElements().get(1).getPeer().getLocalName()); 100 assertTrue(body.getExtensibilityElements().get(3) instanceof SOAPBody); 101 } 102 103 public void testAddAnyElementToEmptyWsdl() throws Exception { 104 WSDLModel model = Util.loadWSDLModel("resources/empty.wsdl"); 105 Definitions definitions = model.getDefinitions(); 106 107 model.startTransaction(); 108 QName qname = new QName ("fooNS", "fooParent", "fo"); 109 ExtensibilityElement parentEE = new GenericExtensibilityElement(model, qname); 110 definitions.addExtensibilityElement(parentEE); 111 model.endTransaction(); 112 113 model.startTransaction(); 114 qname = new QName ("fooNS", "foo", "fo"); 115 ExtensibilityElement element = new GenericExtensibilityElement(model, qname); 116 String text = "asdfasdfsdf"; 117 element.setContentFragment(text); 118 parentEE.addAnyElement(element, 0); 119 model.endTransaction(); 120 121 model = Util.dumpAndReloadModel(model.getBaseDocument()); 122 definitions = model.getDefinitions(); 123 parentEE = definitions.getExtensibilityElements().get(0); 124 element = parentEE.getAnyElements().get(0); 125 assertEquals(text, element.getContentFragment()); 126 } 127 128 public void testAddAnyElementToKnownEEwithKnownEEChildren() throws Exception { 129 WSDLModel model = Util.loadWSDLModel("resources/stockquote_headerFault.xml"); 130 String xpath = "/definitions/binding/operation/input/soap:header"; 131 SOAPHeader header = Util.find(SOAPHeader.class, model, xpath); 132 assertEquals(2, header.getSOAPHeaderFaults().size()); 133 134 model.startTransaction(); 135 QName qname = new QName ("fooNS", "foo", "fo"); 136 ExtensibilityElement any = new GenericExtensibilityElement(model, qname); 137 header.addAnyElement(any, 1); 138 header.addAnyElement((ExtensibilityElement)any.copy(header), 3); 139 model.endTransaction(); 140 141 model = Util.dumpAndReloadModel(model.getBaseDocument()); 142 header = Util.find(SOAPHeader.class, model, xpath); 143 any = (ExtensibilityElement)header.getChildren().get(1); 144 assertEquals(qname, any.getQName()); 145 any = (ExtensibilityElement)header.getChildren().get(3); 146 assertEquals(qname, any.getQName()); 147 } 148 } 149 | Popular Tags |