1 7 8 package org.netbeans.modules.xml.wsdl.validator; 9 10 import java.net.URL ; 11 import java.util.Set ; 12 import junit.framework.*; 13 import java.net.URI ; 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import javax.xml.validation.Schema ; 17 import org.netbeans.modules.xml.wsdl.model.TestCatalogModel; 18 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 19 import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory; 20 import org.netbeans.modules.xml.xam.Model; 21 import org.netbeans.modules.xml.xam.ModelSource; 22 import org.netbeans.modules.xml.xam.spi.Validation; 23 import org.netbeans.modules.xml.xam.spi.ValidationResult; 24 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType; 25 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 26 27 31 public class WSDLInlineSchemaValidatorTest extends TestCase { 32 33 public WSDLInlineSchemaValidatorTest(String testName) { 34 super(testName); 35 } 36 37 protected void setUp() throws Exception { 38 } 39 40 protected void tearDown() throws Exception { 41 } 42 43 46 public void testGetName() { 47 System.out.println("getName"); 48 49 WSDLInlineSchemaValidator instance = new WSDLInlineSchemaValidator(); 50 51 String expResult = "WSDLInlineSchemaValidator"; 52 String result = instance.getName(); 53 assertEquals(expResult, result); 54 55 56 } 57 58 61 public void testValidate() throws Exception { 62 System.out.println("validate"); 63 64 String fileName = "/org/netbeans/modules/xml/wsdl/validator/visitor/resources/valid/AccountTransaction.wsdl"; 65 URL url = getClass().getResource(fileName); 66 URI uri = url.toURI(); 67 68 Set <String > expectedErrors = new HashSet <String >(); 69 validate(uri, expectedErrors); 70 71 } 72 73 76 public void testGetSchema() { 77 System.out.println("getSchema"); 78 79 Model model = null; 80 WSDLInlineSchemaValidator instance = new WSDLInlineSchemaValidator(); 81 82 Schema expResult = null; 83 Schema result = instance.getSchema(model); 84 assertEquals(expResult, result); 85 86 } 87 88 91 105 public void testSapInlineCrossReferenceValid() throws Exception { 106 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/typesTests/inlineSchemaTests/Z_Flight.wsdl"; 107 URL url = getClass().getResource(fileName); 108 URI uri = url.toURI(); 109 110 validate(uri, 0); 111 } 112 113 114 public void testInlineCrossReferenceValid() throws Exception { 115 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/typesTests/inlineSchemaTests/InlineSchemaCrossReference.wsdl"; 116 URL url = getClass().getResource(fileName); 117 URI uri = url.toURI(); 118 119 validate(uri, 0); 120 } 121 122 public void testInlineSchemaImportingAnotherSchemaValid() throws Exception { 123 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/typesTests/inlineSchemaTests/Z_FlightWSD_EUC_SAP.wsdl"; 124 URL url = getClass().getResource(fileName); 125 URI uri = url.toURI(); 126 127 validate(uri, 0); 128 } 129 130 131 public void testInlineSchemaImportingAnotherSchemaUsingCatalogValid() throws Exception { 132 String fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/typesTests/inlineSchemaTests/InventoryService.wsdl"; 135 URL url = getClass().getResource(fileName); 136 URI uri = url.toURI(); 137 138 validate(uri, 0); 139 } 140 141 private void validate(URI uri, int expectedErrorCount) 142 throws Exception { 143 Validation v = new Validation(); 144 145 ModelSource ms = TestCatalogModel.getDefault().getModelSource(uri); 146 MyModelSource source = new MyModelSource(ms.getLookup(), ms.isEditable(), uri); 147 148 WSDLModel model = WSDLModelFactory.getDefault().getModel(source); 149 150 WSDLSchemaValidator instance = new WSDLSchemaValidator(); 151 ValidationResult vr = instance.validate(model, v, Validation.ValidationType.COMPLETE); 152 assertNotNull(vr.getValidationResult()); 153 154 ValidationHelper.dumpErrors(vr); 155 assertTrue("expect error " + expectedErrorCount, vr.getValidationResult().size() == expectedErrorCount); 156 } 157 158 159 private ValidationResult validate(URI relativePath) throws Exception { 160 WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(relativePath); 161 Validation validation = new Validation(); 162 ValidationType validationType = Validation.ValidationType.COMPLETE; 163 WSDLInlineSchemaValidator instance = new WSDLInlineSchemaValidator(); 164 165 ValidationResult result = 166 instance.validate(model, validation, validationType); 167 return result; 168 } 169 170 private void validate(URI relativePath, Set <String > expectedErrors) 171 throws Exception { 172 System.out.println(relativePath); 173 ValidationResult result = validate(relativePath); 174 Iterator <ResultItem> it = result.getValidationResult().iterator(); 175 ValidationHelper.dumpExpecedErrors(expectedErrors); 176 while (it.hasNext()) { 177 ResultItem item = it.next(); 178 assertTrue("Actual Error "+ item.getDescription() + "in " +relativePath, ValidationHelper.containsExpectedError(expectedErrors, item.getDescription())); 180 } 181 if (result.getValidationResult().size() == 0 && expectedErrors.size() > 0) { 182 fail("Expected at least " + expectedErrors.size() + " error(s). Got 0 errors instead"); 183 } 184 } 185 } 186 | Popular Tags |