1 7 8 package org.netbeans.modules.xml.wsdl.validator; 9 10 import java.net.URI ; 11 import java.net.URL ; 12 import junit.framework.*; 13 import javax.xml.validation.Schema ; 14 import org.netbeans.modules.xml.wsdl.model.TestCatalogModel; 15 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 16 import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory; 17 import org.netbeans.modules.xml.xam.ModelSource; 18 import org.netbeans.modules.xml.xam.spi.Validation; 19 import org.netbeans.modules.xml.xam.spi.ValidationResult; 20 21 25 public class WSDLSchemaValidatorTest extends TestCase { 26 27 public WSDLSchemaValidatorTest(String testName) { 28 super(testName); 29 } 30 31 protected void setUp() throws Exception { 32 } 33 34 protected void tearDown() throws Exception { 35 } 36 37 40 public void testGetName() { 41 System.out.println("getName"); 42 43 WSDLSchemaValidator instance = new WSDLSchemaValidator(); 44 45 String expResult = "WSDLSchemaValidator"; 46 String result = instance.getName(); 47 assertEquals(expResult, result); 48 49 } 50 51 54 public void testGetSchema() throws Exception { 55 System.out.println("getSchema"); 56 57 String fileName = "/org/netbeans/modules/xml/wsdl/validator/visitor/resources/valid/AccountTransaction.wsdl"; 58 URL url = getClass().getResource(fileName); 59 URI uri = url.toURI(); 60 61 WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(uri); 62 63 WSDLSchemaValidator instance = new WSDLSchemaValidator(); 64 65 Schema expResult = null; 66 Schema result = instance.getSchema(model); 67 assertNotNull(result); 68 69 } 70 71 72 public void testValidateImportMultiLocation() throws Exception { 73 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/importWSDLtests/importMultiLocation_error.wsdl"; 74 URL url = getClass().getResource(fileName); 75 URI uri = url.toURI(); 76 77 validate(uri, 1); 78 } 79 80 public void testValidateImportMultiNamespace() throws Exception { 81 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/importWSDLtests/importMultiNamespace_error.wsdl"; 82 URL url = getClass().getResource(fileName); 83 URI uri = url.toURI(); 84 85 validate(uri, 1); 86 } 87 88 public void testValidateImportNoLocation() throws Exception { 89 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/importWSDLtests/importNoLocation_error.wsdl"; 90 URL url = getClass().getResource(fileName); 91 URI uri = url.toURI(); 92 93 validate(uri, 1); 94 } 95 96 97 public void testValidateImportNoNamespace() throws Exception { 98 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/importWSDLtests/importNoNamespace_error.wsdl"; 99 URL url = getClass().getResource(fileName); 100 URI uri = url.toURI(); 101 102 validate(uri, 2); 103 } 104 105 public void testValidateMessageMultiDocumentation() throws Exception { 106 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/messageTests/messageMultiDocumentation_error.wsdl"; 107 URL url = getClass().getResource(fileName); 108 URI uri = url.toURI(); 109 110 validate(uri, 1); 111 } 112 113 public void testValidateMessageMultiName() throws Exception { 114 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/messageTests/messageMultiName_error.wsdl"; 115 URL url = getClass().getResource(fileName); 116 URI uri = url.toURI(); 117 118 validate(uri, 1); 119 } 120 121 public void testValidateMessageNoName() throws Exception { 122 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/messageTests/messageNoName_error.wsdl"; 123 URL url = getClass().getResource(fileName); 124 URI uri = url.toURI(); 125 126 validate(uri, 2); 127 } 128 129 public void testValidateMessageNonUniqueName() throws Exception { 130 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/messageTests/messageNonUniqueName_error.wsdl"; 131 URL url = getClass().getResource(fileName); 132 URI uri = url.toURI(); 133 134 validate(uri, 1); 135 } 136 137 138 private void validate(URI uri, int expectedErrorCount) 139 throws Exception { 140 Validation v = new Validation(); 141 142 ModelSource ms = TestCatalogModel.getDefault().getModelSource(uri); 143 MyModelSource source = new MyModelSource(ms.getLookup(), ms.isEditable(), uri); 144 145 WSDLModel model = WSDLModelFactory.getDefault().getModel(source); 146 147 WSDLSchemaValidator instance = new WSDLSchemaValidator(); 148 ValidationResult vr = instance.validate(model, v, Validation.ValidationType.COMPLETE); 149 assertNotNull(vr.getValidationResult()); 150 151 ValidationHelper.dumpErrors(vr); 152 assertTrue("expect error " + expectedErrorCount, vr.getValidationResult().size() == expectedErrorCount); 153 } 154 155 156 157 } 158 | Popular Tags |