1 19 20 package org.netbeans.modules.xml.wsdl.refactoring.xsd; 21 22 import java.util.List ; 23 import junit.framework.*; 24 import org.netbeans.modules.xml.refactoring.RefactorRequest; 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.schema.model.GlobalElement; 31 import org.netbeans.modules.xml.schema.model.SchemaModel; 32 import org.netbeans.modules.xml.wsdl.model.Part; 33 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 34 import org.netbeans.modules.xml.wsdl.refactoring.NamespaceLocation; 35 import org.netbeans.modules.xml.wsdl.refactoring.TestCatalogModel; 36 import org.netbeans.modules.xml.wsdl.refactoring.Util; 37 import org.openide.util.Lookup; 38 39 43 public class SchemaUsageRefactoringEngineTest extends TestCase { 44 SchemaUsageRefactoringEngine instance = new SchemaUsageRefactoringEngine(); 45 46 public SchemaUsageRefactoringEngineTest(String testName) { 47 super(testName); 48 } 49 50 protected void setUp() throws Exception { 51 } 52 53 protected void tearDown() throws Exception { 54 } 55 56 public static Test suite() { 57 TestSuite suite = new TestSuite(SchemaUsageRefactoringEngineTest.class); 58 59 return suite; 60 } 61 62 public void testFindUsages() throws Exception { 63 SchemaModel schemaMod = TestCatalogModel.getDefault().getSchemaModel(NamespaceLocation.OTA); 64 WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL); 65 GlobalElement el = (GlobalElement) Util.findGlobalComponentByName(schemaMod.getSchema(), "TravelItinerary"); 66 67 List <UsageGroup> result = instance.findUsages(el, model.getDefinitions()); 68 assertEquals(1, result.size()); 69 assertEquals(2, result.get(0).getItems().size()); 70 Usage usage0 = (Usage) result.get(0).getItems().get(0); 71 assertEquals("itinerary", ((Part)usage0.getComponent()).getName()); 72 } 73 74 private void executeChange(RefactorRequest request) throws Exception { 75 Lookup.Result results = Lookup.getDefault().lookup( 76 new Lookup.Template(ChangeExecutor.class)); 77 for (Object service : results.allInstances()){ 78 ChangeExecutor exec = (ChangeExecutor)service; 79 if (exec.canChange(RenameRequest.class, request.getTarget())) { 80 exec.doChange(request); 81 return; 82 } 83 } 84 85 fail("Failed to find a change executor for schema component"); 86 } 87 88 public void testRefactorUsages() throws Exception { 89 SchemaModel schemaMod = TestCatalogModel.getDefault().getSchemaModel(NamespaceLocation.OTA); 90 WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL); 91 GlobalElement el = (GlobalElement) Util.findGlobalComponentByName(schemaMod.getSchema(), "TravelItinerary"); 92 List <UsageGroup> usageList = instance.findUsages(el, model.getDefinitions()); 93 UsageSet usages = new UsageSet(el); 94 usages.addUsages(usageList); 95 String newName = "myItirenary"; 96 RenameRequest request = new RenameRequest(el, newName); 97 request.setUsages(usages); 98 executeChange(request); 99 assertTrue(request.confirmChangePerformed()); 100 instance.refactorUsages(request); 101 102 Part part = model.findComponentByName("itinerary", Part.class); 103 assertEquals(newName, part.getElement().getQName().getLocalPart()); 104 usageList = instance.findUsages((GlobalElement)request.getRenamedTarget(), model.getDefinitions()); 105 assertEquals(2, usageList.get(0).getItems().size()); 106 } 107 108 } 109 | Popular Tags |