1 19 20 package org.netbeans.modules.xml.wsdl.refactoring; 21 22 import java.io.IOException ; 23 import java.util.List ; 24 import junit.framework.*; 25 import org.netbeans.modules.xml.refactoring.RenameRequest; 26 import org.netbeans.modules.xml.refactoring.Usage; 27 import org.netbeans.modules.xml.refactoring.UsageGroup; 28 import org.netbeans.modules.xml.refactoring.UsageSet; 29 import org.netbeans.modules.xml.refactoring.spi.ChangeExecutor; 30 import org.netbeans.modules.xml.wsdl.model.Binding; 31 import org.netbeans.modules.xml.wsdl.model.BindingFault; 32 import org.netbeans.modules.xml.wsdl.model.BindingInput; 33 import org.netbeans.modules.xml.wsdl.model.BindingOperation; 34 import org.netbeans.modules.xml.wsdl.model.BindingOutput; 35 import org.netbeans.modules.xml.wsdl.model.Fault; 36 import org.netbeans.modules.xml.wsdl.model.Input; 37 import org.netbeans.modules.xml.wsdl.model.Message; 38 import org.netbeans.modules.xml.wsdl.model.Operation; 39 import org.netbeans.modules.xml.wsdl.model.Output; 40 import org.netbeans.modules.xml.wsdl.model.Part; 41 import org.netbeans.modules.xml.wsdl.model.Port; 42 import org.netbeans.modules.xml.wsdl.model.PortType; 43 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 44 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 45 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody; 46 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPFault; 47 import org.netbeans.modules.xml.xam.Nameable; 48 import org.netbeans.modules.xml.xam.Referenceable; 49 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; 50 51 55 public class WSDLRefactoringEngineTest extends TestCase { 56 57 private WSDLRefactoringEngine engine; 58 private ChangeExecutor exec; 59 60 public WSDLRefactoringEngineTest(String testName) { 61 super(testName); 62 } 63 64 protected void setUp() throws Exception { 65 exec = new WSDLChangeExecutor(); 66 engine = new WSDLRefactoringEngine(); 67 } 68 69 protected void tearDown() throws Exception { 70 } 71 72 public static Test suite() { 73 TestSuite suite = new TestSuite(WSDLRefactoringEngineTest.class); 74 return suite; 75 } 76 77 private void createRenameRequestAndExecute(Nameable<WSDLComponent> target, List <UsageGroup> usages) throws IOException { 78 RenameRequest rr = new RenameRequest(target, "renamed"); 79 exec.doChange(rr); 80 assertTrue(rr.confirmChangePerformed()); 81 UsageSet usageSet = new UsageSet((Referenceable)target); 82 usageSet.addUsages(usages); 83 rr.setUsages(usageSet); 84 engine.precheck(rr); 85 engine.refactorUsages(rr); 86 } 87 88 public void testMessage() throws Exception { 89 WSDLModel model = Util.loadWSDLModel("resources/stockquote.wsdl"); 90 Message target = (Message) Util.findByXpath(model, "/definitions/message[@name='GetLastTradePriceInput']"); 91 List <UsageGroup> usages = engine.findUsages(target, model.getDefinitions()); 92 List <Usage> items = usages.get(0).getItems(); 93 assertEquals(2, items.size()); 94 assertEquals(target, ((Input)items.get(0).getComponent()).getMessage().get()); 95 96 createRenameRequestAndExecute(target, usages); 97 98 Input fixed1 = (Input) Util.findByXpath(model, "/definitions/portType/operation/input"); 99 assertEquals("tns:renamed", ((AbstractDocumentComponent)fixed1).getPeer().getAttribute("message")); 100 101 BindingInput bi = (BindingInput) Util.findByXpath(model, "/definitions/binding/operation/input"); 103 assertNull(((AbstractDocumentComponent)bi).getPeer().getAttribute("name")); 104 } 105 106 public void testBinding() throws Exception { 107 WSDLModel model = Util.loadWSDLModel("resources/TravelReservationService.wsdl"); 108 Binding target = (Binding) Util.findByXpath(model, "/definitions/binding[@name='TravelReservationSoapBinding']"); 109 List <UsageGroup> usages = engine.findUsages(target, model.getDefinitions()); 110 List <Usage> items = usages.get(0).getItems(); 111 assertEquals(1, items.size()); 112 assertEquals(target, ((Port)items.get(0).getComponent()).getBinding().get()); 113 114 createRenameRequestAndExecute(target, usages); 115 116 Port fixed1 = (Port) Util.findByXpath(model, "/definitions/service/port"); 117 assertEquals("tns:renamed", ((AbstractDocumentComponent)fixed1).getPeer().getAttribute("binding")); 118 } 119 120 public void testFault() throws Exception { 121 WSDLModel model = Util.loadWSDLModel("resources/TravelReservationService.wsdl"); 122 Fault target = (Fault) Util.findByXpath(model, 123 "/definitions/portType[@name='TravelReservationPortType']/operation/fault[@name='itineraryProblem']"); 124 List <UsageGroup> usages = engine.findUsages(target, model.getDefinitions()); 125 List <Usage> items = usages.get(0).getItems(); 126 assertEquals(2, items.size()); 127 assertEquals(target, ((BindingFault)items.get(0).getComponent()).getFault().get()); 128 assertEquals(target, ((SOAPFault)items.get(1).getComponent()).getFault().get()); 129 130 createRenameRequestAndExecute(target, usages); 131 132 BindingFault fixed1 = (BindingFault) Util.findByXpath(model, "/definitions/binding/operation/fault"); 133 assertEquals("renamed", ((AbstractDocumentComponent)fixed1).getPeer().getAttribute("name")); 134 SOAPFault fixed2 = (SOAPFault) Util.findByXpath(model, "/definitions/binding/operation/fault/soap:fault"); 135 assertEquals("renamed", ((AbstractDocumentComponent)fixed2).getPeer().getAttribute("name")); 136 } 137 138 public void testOperation() throws Exception { 139 WSDLModel model = Util.loadWSDLModel("resources/TravelReservationService.wsdl"); 140 WSDLRefactoringEngine engine = new WSDLRefactoringEngine(); 141 Operation target = (Operation) Util.findByXpath(model, 142 "/definitions/portType[@name='TravelReservationPortType']/operation[@name='buildItinerary']"); 143 List <UsageGroup> usages = engine.findUsages(target, model.getDefinitions()); 144 List <Usage> items = usages.get(0).getItems(); 145 assertEquals(1, items.size()); 146 assertEquals(target, ((BindingOperation) items.get(0).getComponent()).getOperation().get()); 147 148 createRenameRequestAndExecute(target, usages); 149 150 BindingOperation fixed1 = (BindingOperation) Util.findByXpath(model, "/definitions/binding/operation"); 151 assertEquals("renamed", ((AbstractDocumentComponent)fixed1).getPeer().getAttribute("name")); 152 } 153 154 public void testPart() throws Exception { 155 WSDLModel model = Util.loadWSDLModel("resources/uddi.wsdl"); 156 WSDLRefactoringEngine engine = new WSDLRefactoringEngine(); 157 Part target = (Part) Util.findByXpath(model, 158 "/definitions/message[@name='bindingDetail']/part[@name='body']"); 159 List <UsageGroup> usages = engine.findUsages(target, model.getDefinitions()); 160 List <Usage> items = usages.get(0).getItems(); 161 assertEquals(2, items.size()); 162 assertTrue(((SOAPBody) items.get(1).getComponent()).getParts().contains("body")); 163 164 createRenameRequestAndExecute(target, usages); 165 166 SOAPBody fixed1 = (SOAPBody) Util.findByXpath(model, "/definitions/binding/operation[@name='find_binding']/output/soap:body"); 167 assertEquals("renamed", ((AbstractDocumentComponent)fixed1).getPeer().getAttribute("parts")); 168 SOAPBody fixed2 = (SOAPBody) Util.findByXpath(model, "/definitions/binding/operation[@name='get_bindingDetail']/output/soap:body"); 169 assertEquals("renamed", ((AbstractDocumentComponent)fixed2).getPeer().getAttribute("parts")); 170 171 } 172 173 public void testInput() throws Exception { 174 WSDLModel model = Util.loadWSDLModel("resources/uddi.wsdl"); 175 WSDLRefactoringEngine engine = new WSDLRefactoringEngine(); 176 Input target = (Input) Util.findByXpath(model, 177 "/definitions/portType/operation[@name='find_binding']/input"); 178 List <UsageGroup> usages = engine.findUsages(target, model.getDefinitions()); 179 List <Usage> items = usages.get(0).getItems(); 180 assertEquals(1, items.size()); 181 assertEquals(target, ((BindingInput) items.get(0).getComponent()).getInput().get()); 182 183 createRenameRequestAndExecute(target, usages); 184 185 BindingInput fixed1 = (BindingInput) Util.findByXpath(model, "/definitions/binding/operation[@name='find_binding']/input"); 186 assertNull(((AbstractDocumentComponent)fixed1).getPeer().getAttribute("name")); 188 } 189 190 public void testOutput() throws Exception { 191 WSDLModel model = Util.loadWSDLModel("resources/uddi.wsdl"); 192 WSDLRefactoringEngine engine = new WSDLRefactoringEngine(); 193 Output target = (Output) Util.findByXpath(model, 194 "/definitions/portType/operation[@name='find_binding']/output"); 195 List <UsageGroup> usages = engine.findUsages(target, model.getDefinitions()); 196 List <Usage> items = usages.get(0).getItems(); 197 assertEquals(1, items.size()); 198 assertEquals(target, ((BindingOutput) items.get(0).getComponent()).getOutput().get()); 199 200 createRenameRequestAndExecute(target, usages); 201 202 BindingOutput fixed1 = (BindingOutput) Util.findByXpath(model, "/definitions/binding/operation[@name='find_binding']/output"); 203 assertNull(((AbstractDocumentComponent)fixed1).getPeer().getAttribute("name")); 205 } 206 207 public void testPortType() throws Exception { 208 WSDLModel model = Util.loadWSDLModel("resources/TravelReservationService.wsdl"); 209 WSDLRefactoringEngine engine = new WSDLRefactoringEngine(); 210 PortType target = (PortType) Util.findByXpath(model, 211 "/definitions/portType[@name='TravelReservationPortType']"); 212 List <UsageGroup> usages = engine.findUsages(target, model.getDefinitions()); 213 List <Usage> items = usages.get(0).getItems(); 214 assertEquals(1, items.size()); 215 assertEquals(target, ((Binding)items.get(0).getComponent()).getType().get()); 216 217 createRenameRequestAndExecute(target, usages); 218 219 Binding fixed1 = (Binding) Util.findByXpath(model, "/definitions/binding"); 220 assertEquals("tns:renamed", ((AbstractDocumentComponent)fixed1).getPeer().getAttribute("type")); 221 } 222 223 } 224 | Popular Tags |