1 7 8 package org.netbeans.modules.xml.schema.model; 9 import java.beans.PropertyChangeListener ; 10 import junit.framework.*; 11 import java.net.URI ; 12 import java.util.Collection ; 13 14 18 public class IncludeTest extends TestCase { 19 private static final String TEST_XSD = "resources/testInclude.xsd"; 20 21 public IncludeTest(String testName) { 22 super(testName); 23 } 24 25 protected void setUp() throws Exception { 26 } 27 28 protected void tearDown() throws Exception { 29 TestCatalogModel.getDefault().clearDocumentPool(); 30 } 31 32 public static Test suite() { 33 TestSuite suite = new TestSuite(IncludeTest.class); 34 35 return suite; 36 } 37 38 41 public void testGetSchemaLocation() throws Exception { 42 Include instance = null; 43 SchemaModel model = Util.loadSchemaModel(TEST_XSD); 44 Schema schema = model.getSchema(); 45 assertNotNull("Null schema " , schema); 46 47 Collection <Include> refs = schema.getIncludes(); 48 this.assertNotNull("Null refs ", refs); 49 instance = refs.iterator().next(); 50 this.assertNotNull("Null include ", instance); 51 String expResult = "somefile.xsd"; 52 System.out.println("expResult: " + expResult.toString()); 53 String result = instance.getSchemaLocation(); 54 System.out.println("result: " + result.toString()); 55 assertEquals(expResult.toString(), result.toString()); 56 } 57 58 61 public void testSetSchemaLocation() throws Exception { 62 URI uri = null; 63 Include instance = null; 64 SchemaModel model = Util.loadSchemaModel(TEST_XSD); 65 Schema schema = model.getSchema(); 66 assertNotNull("Null schema " , schema); 67 68 java.util.List <SchemaComponent> children = schema.getChildren(); 69 for(SchemaComponent child: children){ 70 if(child instanceof Include){ 71 instance = (Include)child; 72 break; 73 } 74 } 75 this.assertNotNull("Null include ", instance); 76 TestListener tl = new TestListener(); 77 instance.getModel().addPropertyChangeListener(tl); 78 String result = instance.getSchemaLocation(); 79 assertEquals("somefile.xsd", instance.getSchemaLocation().toString()); 80 model.startTransaction(); 81 instance.setSchemaLocation("newfile.xsd"); 82 model.endTransaction(); 83 assertEquals("newfile.xsd", instance.getSchemaLocation().toString()); 84 assertTrue("only one event should be fired " + tl.getEventsFired(), tl.getEventsFired()==1); 85 assertEquals("event should be modified", Include.SCHEMA_LOCATION_PROPERTY, tl.getLastEventName()); 86 } 87 88 static class TestListener implements PropertyChangeListener { 89 private String eventName; 90 private int count = 0; 91 92 public void propertyChange(java.beans.PropertyChangeEvent evt) { 93 eventName = evt.getPropertyName(); 94 count++; 95 } 96 97 public int getEventsFired() { 98 return count; 99 } 100 101 public String getLastEventName() { 102 return eventName; 103 } 104 105 public void resetFiredEvents() { 106 count = 0; 107 } 108 } 109 } 110 | Popular Tags |