001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.wsdl.refactoring;
043:
044: import java.io.IOException;
045: import java.util.List;
046: import junit.framework.*;
047: import org.netbeans.modules.refactoring.api.RefactoringSession;
048: import org.netbeans.modules.refactoring.api.RenameRefactoring;
049: import org.netbeans.modules.xml.refactoring.XMLRefactoringTransaction;
050: import org.netbeans.modules.xml.refactoring.spi.ChangeExecutor;
051: import org.netbeans.modules.xml.wsdl.model.Binding;
052: import org.netbeans.modules.xml.wsdl.model.BindingFault;
053: import org.netbeans.modules.xml.wsdl.model.BindingInput;
054: import org.netbeans.modules.xml.wsdl.model.BindingOperation;
055: import org.netbeans.modules.xml.wsdl.model.BindingOutput;
056: import org.netbeans.modules.xml.wsdl.model.Fault;
057: import org.netbeans.modules.xml.wsdl.model.Input;
058: import org.netbeans.modules.xml.wsdl.model.Message;
059: import org.netbeans.modules.xml.wsdl.model.Operation;
060: import org.netbeans.modules.xml.wsdl.model.Output;
061: import org.netbeans.modules.xml.wsdl.model.Part;
062: import org.netbeans.modules.xml.wsdl.model.Port;
063: import org.netbeans.modules.xml.wsdl.model.PortType;
064: import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
065: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
066: import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody;
067: import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPFault;
068: import org.netbeans.modules.xml.xam.Component;
069: import org.netbeans.modules.xml.xam.Nameable;
070: import org.netbeans.modules.xml.xam.Referenceable;
071: import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
072: import org.openide.util.lookup.Lookups;
073:
074: /**
075: *
076: * @author Nam Nguyen
077: */
078: public class WSDLRefactoringEngineTest extends TestCase {
079:
080: // private WSDLRefactoringEngine engine;
081: // private ChangeExecutor exec;
082:
083: public WSDLRefactoringEngineTest(String testName) {
084: super (testName);
085: }
086:
087: protected void setUp() throws Exception {
088: // exec = new WSDLChangeExecutor();
089: // engine = new WSDLRefactoringEngine();
090: }
091:
092: protected void tearDown() throws Exception {
093: }
094:
095: public static Test suite() {
096: TestSuite suite = new TestSuite(WSDLRefactoringEngineTest.class);
097: return suite;
098: }
099:
100: private void createRenameRequestAndExecute(
101: Nameable<WSDLComponent> target, WSDLModel model)
102: throws IOException {
103: //RenameRequest rr = new RenameRequest(target, "renamed");
104: RenameRefactoring refactoring = new RenameRefactoring(Lookups
105: .singleton(target));
106: XMLRefactoringTransaction transaction = new XMLRefactoringTransaction(
107: (Referenceable) target, refactoring);
108: refactoring.getContext().add(transaction);
109: refactoring.getContext().add(target.getName());
110: refactoring.getContext()
111: .add((Component) model.getDefinitions());
112: RefactoringSession session = RefactoringSession
113: .create("Test rename");
114: refactoring.setNewName("renamed");
115: assertNull(refactoring.prepare(session));
116: session.doRefactoring(true);
117:
118: }
119:
120: public void testMessage() throws Exception {
121: WSDLModel model = Util
122: .loadWSDLModel("resources/stockquote.wsdl");
123: Message target = (Message) Util.findByXpath(model,
124: "/definitions/message[@name='GetLastTradePriceInput']");
125: createRenameRequestAndExecute(target, model);
126:
127: Input fixed1 = (Input) Util.findByXpath(model,
128: "/definitions/portType/operation/input");
129: assertEquals("tns:renamed",
130: ((AbstractDocumentComponent) fixed1).getPeer()
131: .getAttribute("message"));
132:
133: // BindingInput.getInput is just implicit and should not be changed
134: BindingInput bi = (BindingInput) Util.findByXpath(model,
135: "/definitions/binding/operation/input");
136: assertNull(((AbstractDocumentComponent) bi).getPeer()
137: .getAttribute("name"));
138: }
139:
140: public void testBinding() throws Exception {
141: WSDLModel model = Util
142: .loadWSDLModel("resources/TravelReservationService.wsdl");
143: Binding target = (Binding) Util
144: .findByXpath(model,
145: "/definitions/binding[@name='TravelReservationSoapBinding']");
146:
147: createRenameRequestAndExecute(target, model);
148:
149: Port fixed1 = (Port) Util.findByXpath(model,
150: "/definitions/service/port");
151: assertEquals("tns:renamed",
152: ((AbstractDocumentComponent) fixed1).getPeer()
153: .getAttribute("binding"));
154: }
155:
156: public void testFault() throws Exception {
157: WSDLModel model = Util
158: .loadWSDLModel("resources/TravelReservationService.wsdl");
159: Fault target = (Fault) Util
160: .findByXpath(
161: model,
162: "/definitions/portType[@name='TravelReservationPortType']/operation/fault[@name='itineraryProblem']");
163:
164: createRenameRequestAndExecute(target, model);
165:
166: BindingFault fixed1 = (BindingFault) Util.findByXpath(model,
167: "/definitions/binding/operation/fault");
168: assertEquals("renamed", ((AbstractDocumentComponent) fixed1)
169: .getPeer().getAttribute("name"));
170: SOAPFault fixed2 = (SOAPFault) Util.findByXpath(model,
171: "/definitions/binding/operation/fault/soap:fault");
172: assertEquals("renamed", ((AbstractDocumentComponent) fixed2)
173: .getPeer().getAttribute("name"));
174: }
175:
176: public void testOperation() throws Exception {
177: WSDLModel model = Util
178: .loadWSDLModel("resources/TravelReservationService.wsdl");
179: WSDLRefactoringEngine engine = new WSDLRefactoringEngine();
180: Operation target = (Operation) Util
181: .findByXpath(
182: model,
183: "/definitions/portType[@name='TravelReservationPortType']/operation[@name='buildItinerary']");
184: createRenameRequestAndExecute(target, model);
185:
186: BindingOperation fixed1 = (BindingOperation) Util.findByXpath(
187: model, "/definitions/binding/operation");
188: assertEquals("renamed", ((AbstractDocumentComponent) fixed1)
189: .getPeer().getAttribute("name"));
190: }
191:
192: public void testPart() throws Exception {
193: WSDLModel model = Util.loadWSDLModel("resources/uddi.wsdl");
194: WSDLRefactoringEngine engine = new WSDLRefactoringEngine();
195: Part target = (Part) Util
196: .findByXpath(model,
197: "/definitions/message[@name='bindingDetail']/part[@name='body']");
198: createRenameRequestAndExecute(target, model);
199:
200: SOAPBody fixed1 = (SOAPBody) Util
201: .findByXpath(model,
202: "/definitions/binding/operation[@name='find_binding']/output/soap:body");
203: assertEquals("renamed", ((AbstractDocumentComponent) fixed1)
204: .getPeer().getAttribute("parts"));
205: SOAPBody fixed2 = (SOAPBody) Util
206: .findByXpath(model,
207: "/definitions/binding/operation[@name='get_bindingDetail']/output/soap:body");
208: assertEquals("renamed", ((AbstractDocumentComponent) fixed2)
209: .getPeer().getAttribute("parts"));
210:
211: }
212:
213: public void testInput() throws Exception {
214: WSDLModel model = Util.loadWSDLModel("resources/uddi.wsdl");
215: Input target = (Input) Util
216: .findByXpath(model,
217: "/definitions/portType/operation[@name='find_binding']/input");
218: createRenameRequestAndExecute(target, model);
219:
220: BindingInput fixed1 = (BindingInput) Util
221: .findByXpath(model,
222: "/definitions/binding/operation[@name='find_binding']/input");
223: // Still have binding/input@name implicit.
224: assertNull(((AbstractDocumentComponent) fixed1).getPeer()
225: .getAttribute("name"));
226: }
227:
228: public void testOutput() throws Exception {
229: WSDLModel model = Util.loadWSDLModel("resources/uddi.wsdl");
230: Output target = (Output) Util
231: .findByXpath(model,
232: "/definitions/portType/operation[@name='find_binding']/output");
233:
234: createRenameRequestAndExecute(target, model);
235:
236: BindingOutput fixed1 = (BindingOutput) Util
237: .findByXpath(model,
238: "/definitions/binding/operation[@name='find_binding']/output");
239: // Still have binding/output@name implicit.
240: assertNull(((AbstractDocumentComponent) fixed1).getPeer()
241: .getAttribute("name"));
242: }
243:
244: public void testPortType() throws Exception {
245: WSDLModel model = Util
246: .loadWSDLModel("resources/TravelReservationService.wsdl");
247: PortType target = (PortType) Util
248: .findByXpath(model,
249: "/definitions/portType[@name='TravelReservationPortType']");
250:
251: createRenameRequestAndExecute(target, model);
252:
253: Binding fixed1 = (Binding) Util.findByXpath(model,
254: "/definitions/binding");
255: assertEquals("tns:renamed",
256: ((AbstractDocumentComponent) fixed1).getPeer()
257: .getAttribute("type"));
258: }
259:
260: }
|