1 19 20 package org.netbeans.modules.xml.schema.model.validation; 21 22 import java.util.List ; 23 import junit.framework.*; 24 import org.netbeans.modules.xml.schema.model.SchemaModel; 25 import org.netbeans.modules.xml.schema.model.SchemaModelReference; 26 import org.netbeans.modules.xml.schema.model.TestCatalogModel; 27 import org.netbeans.modules.xml.schema.model.Util; 28 import org.netbeans.modules.xml.xam.spi.Validation; 29 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 30 31 35 public class SchemaXsdBasedValidatorTest extends TestCase { 36 37 public SchemaXsdBasedValidatorTest(String testName) { 38 super(testName); 39 } 40 41 protected void setUp() throws Exception { 42 } 43 44 protected void tearDown() throws Exception { 45 TestCatalogModel.getDefault().clearDocumentPool(); 46 } 47 48 public static Test suite() { 49 TestSuite suite = new TestSuite(SchemaXsdBasedValidatorTest.class); 50 51 return suite; 52 } 53 54 public void testResolveResource() throws Exception { 55 Validation validation = new Validation(); 56 SchemaModel model = Util.loadSchemaModel("validation/SynchronousSample.xsd"); 57 SchemaModelReference imported = model.getSchema().getSchemaReferences().iterator().next(); 58 SchemaModel importedModel = imported.resolveReferencedModel(); 59 String expected1 = "s4s-att-not-allowed: Attribute 'nameXXXX' cannot appear in element 'attribute'."; 60 String expected2 = "s4s-att-must-appear: Attribute 'name' must appear in element 'attribute'."; 61 62 validation.validate(importedModel, Validation.ValidationType.COMPLETE); 63 List <ResultItem> results0 = validation.getValidationResult(); 64 assertEquals(2, results0.size()); 65 assertEquals("from imported model", importedModel, results0.get(0).getModel()); 66 assertEquals(expected1, results0.get(0).getDescription()); 67 assertEquals("from imported model", importedModel, results0.get(1).getModel()); 68 assertEquals(expected2, results0.get(1).getDescription()); 69 70 Validation validation2 = new Validation(); 71 validation2.validate(model, Validation.ValidationType.COMPLETE); 72 List <ResultItem> results = validation2.getValidationResult(); 73 assertEquals(2, results.size()); 74 assertEquals("from imported model", importedModel, results.get(0).getModel()); 75 assertEquals(expected1, results.get(0).getDescription()); 76 assertEquals("from imported model", importedModel, results.get(1).getModel()); 77 assertEquals(expected2, results.get(1).getDescription()); 78 } 79 80 } 81 | Popular Tags |