abadea@61
|
1 |
/*
|
yaroslavskiy@573
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
abadea@61
|
3 |
*
|
jglick@1329
|
4 |
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
|
jglick@1329
|
5 |
*
|
jglick@1329
|
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
jglick@1329
|
7 |
* Other names may be trademarks of their respective owners.
|
samaresh@119
|
8 |
*
|
yaroslavskiy@573
|
9 |
* The contents of this file are subject to the terms of either the GNU
|
yaroslavskiy@573
|
10 |
* General Public License Version 2 only ("GPL") or the Common
|
yaroslavskiy@573
|
11 |
* Development and Distribution License("CDDL") (collectively, the
|
yaroslavskiy@573
|
12 |
* "License"). You may not use this file except in compliance with the
|
yaroslavskiy@573
|
13 |
* License. You can obtain a copy of the License at
|
yaroslavskiy@573
|
14 |
* http://www.netbeans.org/cddl-gplv2.html
|
yaroslavskiy@573
|
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
yaroslavskiy@573
|
16 |
* specific language governing permissions and limitations under the
|
yaroslavskiy@573
|
17 |
* License. When distributing the software, include this License Header
|
yaroslavskiy@573
|
18 |
* Notice in each file and include the License file at
|
jglick@1329
|
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
yaroslavskiy@573
|
20 |
* particular file as subject to the "Classpath" exception as provided
|
jglick@1329
|
21 |
* by Oracle in the GPL Version 2 section of the License file that
|
yaroslavskiy@573
|
22 |
* accompanied this code. If applicable, add the following below the
|
yaroslavskiy@573
|
23 |
* License Header, with the fields enclosed by brackets [] replaced by
|
yaroslavskiy@573
|
24 |
* your own identifying information:
|
samaresh@119
|
25 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
samaresh@119
|
26 |
*
|
yaroslavskiy@573
|
27 |
* Contributor(s):
|
yaroslavskiy@573
|
28 |
*
|
samaresh@119
|
29 |
* The Original Software is NetBeans. The Initial Developer of the Original
|
samaresh@119
|
30 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
|
samaresh@119
|
31 |
* Microsystems, Inc. All Rights Reserved.
|
yaroslavskiy@573
|
32 |
*
|
yaroslavskiy@573
|
33 |
* If you wish your version of this file to be governed by only the CDDL
|
yaroslavskiy@573
|
34 |
* or only the GPL Version 2, indicate your decision by adding
|
yaroslavskiy@573
|
35 |
* "[Contributor] elects to include this software in this distribution
|
yaroslavskiy@573
|
36 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
yaroslavskiy@573
|
37 |
* single choice of license, a recipient has the option to distribute
|
yaroslavskiy@573
|
38 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
yaroslavskiy@573
|
39 |
* to extend the choice of license to its licensees as provided above.
|
yaroslavskiy@573
|
40 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
yaroslavskiy@573
|
41 |
* Version 2 license, then the option applies only if the new code is
|
yaroslavskiy@573
|
42 |
* made subject to such option by the copyright holder.
|
abadea@61
|
43 |
*/
|
abadea@61
|
44 |
|
abadea@61
|
45 |
package org.netbeans.modules.xml.wsdl.refactoring.xsd;
|
abadea@61
|
46 |
|
sonali@175
|
47 |
import java.util.Collection;
|
abadea@61
|
48 |
import java.util.List;
|
abadea@61
|
49 |
import junit.framework.*;
|
sonali@175
|
50 |
import org.netbeans.modules.refactoring.api.RefactoringElement;
|
sonali@175
|
51 |
import org.netbeans.modules.refactoring.api.RefactoringSession;
|
sonali@175
|
52 |
import org.netbeans.modules.refactoring.api.RenameRefactoring;
|
sonali@175
|
53 |
import org.netbeans.modules.refactoring.api.WhereUsedQuery;
|
sonali@175
|
54 |
import org.netbeans.modules.xml.refactoring.XMLRefactoringTransaction;
|
abadea@61
|
55 |
import org.netbeans.modules.xml.refactoring.spi.ChangeExecutor;
|
abadea@61
|
56 |
import org.netbeans.modules.xml.schema.model.GlobalElement;
|
abadea@61
|
57 |
import org.netbeans.modules.xml.schema.model.SchemaModel;
|
abadea@61
|
58 |
import org.netbeans.modules.xml.wsdl.model.Part;
|
abadea@61
|
59 |
import org.netbeans.modules.xml.wsdl.model.WSDLModel;
|
abadea@61
|
60 |
import org.netbeans.modules.xml.wsdl.refactoring.NamespaceLocation;
|
abadea@61
|
61 |
import org.netbeans.modules.xml.wsdl.refactoring.TestCatalogModel;
|
abadea@61
|
62 |
import org.netbeans.modules.xml.wsdl.refactoring.Util;
|
sonali@175
|
63 |
import org.netbeans.modules.xml.xam.Component;
|
sonali@175
|
64 |
import org.netbeans.modules.xml.xam.Referenceable;
|
abadea@61
|
65 |
import org.openide.util.Lookup;
|
sonali@175
|
66 |
import org.openide.util.lookup.Lookups;
|
abadea@61
|
67 |
|
abadea@61
|
68 |
/**
|
abadea@61
|
69 |
*
|
abadea@61
|
70 |
* @author nn136682
|
abadea@61
|
71 |
*/
|
abadea@61
|
72 |
public class SchemaUsageRefactoringEngineTest extends TestCase {
|
sonali@175
|
73 |
// SchemaUsageRefactoringEngine instance = new SchemaUsageRefactoringEngine();
|
abadea@61
|
74 |
|
abadea@61
|
75 |
public SchemaUsageRefactoringEngineTest(String testName) {
|
abadea@61
|
76 |
super(testName);
|
abadea@61
|
77 |
}
|
abadea@61
|
78 |
|
abadea@61
|
79 |
protected void setUp() throws Exception {
|
abadea@61
|
80 |
}
|
abadea@61
|
81 |
|
abadea@61
|
82 |
protected void tearDown() throws Exception {
|
abadea@61
|
83 |
}
|
abadea@61
|
84 |
|
abadea@61
|
85 |
public static Test suite() {
|
fvogler@1581
|
86 |
// TODO Fix Test - avoid dialogs
|
fvogler@1581
|
87 |
// TestSuite suite = new TestSuite(SchemaUsageRefactoringEngineTest.class);
|
fvogler@1581
|
88 |
// return suite;
|
fvogler@1581
|
89 |
return new TestSuite();
|
abadea@61
|
90 |
}
|
abadea@61
|
91 |
|
abadea@61
|
92 |
public void testFindUsages() throws Exception {
|
abadea@61
|
93 |
SchemaModel schemaMod = TestCatalogModel.getDefault().getSchemaModel(NamespaceLocation.OTA);
|
abadea@61
|
94 |
WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL);
|
abadea@61
|
95 |
GlobalElement el = (GlobalElement) Util.findGlobalComponentByName(schemaMod.getSchema(), "TravelItinerary");
|
sonali@175
|
96 |
WhereUsedQuery query = new WhereUsedQuery(Lookups.singleton((Referenceable)el));
|
sonali@175
|
97 |
query.getContext().add((Component)model.getDefinitions());
|
sonali@175
|
98 |
RefactoringSession session = RefactoringSession.create("test refactor");
|
sonali@175
|
99 |
query.prepare(session);
|
sonali@175
|
100 |
Collection<RefactoringElement> element = session.getRefactoringElements();
|
sonali@175
|
101 |
assertEquals(2, element.size());
|
sonali@175
|
102 |
|
abadea@61
|
103 |
}
|
abadea@61
|
104 |
|
abadea@61
|
105 |
|
abadea@61
|
106 |
public void testRefactorUsages() throws Exception {
|
abadea@61
|
107 |
SchemaModel schemaMod = TestCatalogModel.getDefault().getSchemaModel(NamespaceLocation.OTA);
|
abadea@61
|
108 |
WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL);
|
abadea@61
|
109 |
GlobalElement el = (GlobalElement) Util.findGlobalComponentByName(schemaMod.getSchema(), "TravelItinerary");
|
sonali@175
|
110 |
|
abadea@61
|
111 |
String newName = "myItirenary";
|
sonali@175
|
112 |
|
sonali@175
|
113 |
RenameRefactoring refactoring = new RenameRefactoring(Lookups.singleton(el));
|
sonali@175
|
114 |
XMLRefactoringTransaction transaction = new XMLRefactoringTransaction((Referenceable)el, refactoring);
|
sonali@175
|
115 |
refactoring.setNewName(newName);
|
sonali@175
|
116 |
refactoring.getContext().add(transaction);
|
sonali@175
|
117 |
refactoring.getContext().add((Component)model.getDefinitions());
|
sonali@175
|
118 |
refactoring.getContext().add(el.getName());
|
sonali@175
|
119 |
RefactoringSession session = RefactoringSession.create("test refactor");
|
sonali@175
|
120 |
assertNull(refactoring.prepare(session));
|
sonali@175
|
121 |
session.doRefactoring(true);
|
abadea@61
|
122 |
|
abadea@61
|
123 |
Part part = model.findComponentByName("itinerary", Part.class);
|
abadea@61
|
124 |
assertEquals(newName, part.getElement().getQName().getLocalPart());
|
sonali@175
|
125 |
|
abadea@61
|
126 |
}
|
abadea@61
|
127 |
|
abadea@61
|
128 |
}
|