1 7 8 package org.netbeans.modules.xml.wsdl.model.extensions.soap.validation; 9 10 import junit.framework.*; 11 import java.io.File ; 12 import java.io.FileFilter ; 13 import java.net.URI ; 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.ResourceBundle ; 17 18 import org.netbeans.modules.xml.wsdl.model.Util; 19 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 20 import org.netbeans.modules.xml.xam.spi.Validation; 21 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType; 22 import org.netbeans.modules.xml.xam.spi.ValidationResult; 23 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 24 25 import org.netbeans.modules.xml.wsdl.model.TestCatalogModel; 26 27 31 public class SOAPComponentValidatorTest extends TestCase { 32 33 private static final ResourceBundle mMessages = 34 ResourceBundle.getBundle("org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.Bundle"); 35 36 public SOAPComponentValidatorTest(String testName) { 37 super(testName); 38 } 39 40 protected void setUp() throws Exception { 41 } 42 43 protected void tearDown() throws Exception { 44 TestCatalogModel.getDefault().clearDocumentPool(); 45 } 46 47 private ValidationResult validate(String relativePath) throws Exception { 48 WSDLModel model = Util.loadWSDLModel(relativePath); 49 Validation validation = new Validation(); 50 ValidationType validationType = Validation.ValidationType.COMPLETE; 51 SOAPComponentValidator instance = new SOAPComponentValidator(); 52 ValidationResult result = 53 instance.validate(model, validation, validationType); 54 return result; 55 } 56 57 private void validate(String relativePath, HashSet <String > expectedErrors) 58 throws Exception { 59 System.out.println(relativePath); 60 ValidationResult result = validate(relativePath); 61 Iterator <ResultItem> it = result.getValidationResult().iterator(); 62 while (it.hasNext()) { 63 ResultItem item = it.next(); 64 System.out.println(" " + item.getDescription()); 65 assertTrue(item.getDescription(), expectedErrors.contains(item.getDescription())); 66 } 67 if (result.getValidationResult().size() == 0 && expectedErrors.size() > 0) { 68 fail("Expected at least " + expectedErrors.size() + " error(s). Got 0 errors instead"); 69 } 70 } 71 74 public void testGetName() throws Exception { 75 SOAPComponentValidator instance = new SOAPComponentValidator(); 76 77 String expResult = instance.getClass().getName(); 78 String result = instance.getName(); 79 assertEquals(expResult, result); 80 } 81 82 85 public void testValidWSDLs() throws Exception { 86 URI resource = Util.getResourceURI("extensions/soap/validation/resources/valid/AccountTransaction.wsdl"); 88 File resourceFile = new File (resource); 89 File [] wsdls = resourceFile.getParentFile().listFiles(new FileFilter () { 90 public boolean accept(File pathname) { 91 return pathname.getName().endsWith(".wsdl"); 92 }}); 93 for (int ii = 0; ii < wsdls.length; ii++) { 94 String relativePath = 95 "extensions/soap/validation/resources/valid/" + 96 wsdls[ii].getName(); 97 ValidationResult result = validate(relativePath); 98 assertTrue(result.getValidationResult().size() == 0); 99 } 100 } 101 102 public void testSOAPAddressBadLocation() throws Exception { 103 HashSet <String > expectedErrors = new HashSet <String >(); 104 expectedErrors.add(mMessages.getString("SOAPAddressValidator.Unsupported_location_attribute")); 105 106 String relativePath = "extensions/soap/validation/resources/invalid/SOAPAddressBadLocation.wsdl"; 107 validate(relativePath, expectedErrors); 108 } 109 110 public void testSOAPAddressMissingLocation() throws Exception { 111 HashSet <String > expectedErrors = new HashSet <String >(); 112 expectedErrors.add(mMessages.getString("SOAPAddressValidator.Missing_location")); 113 114 String relativePath = "extensions/soap/validation/resources/invalid/SOAPAddressMissingLocation.wsdl"; 115 validate(relativePath, expectedErrors); 116 } 117 118 public void testSOAPBindingBadStyle() throws Exception { 119 HashSet <String > expectedErrors = new HashSet <String >(); 120 expectedErrors.add(mMessages.getString("SOAPBindingValidator.Unsupported_style_attribute")); 121 expectedErrors.add(mMessages.getString("SOAPOperationValidator.Unsupported_style_attribute")); 122 123 String relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingBadStyle.wsdl"; 124 validate(relativePath, expectedErrors); 125 } 126 127 public void testSOAPBindingBadTransportURI() throws Exception { 128 HashSet <String > expectedErrors = new HashSet <String >(); 129 expectedErrors.add(mMessages.getString("SOAPBindingValidator.Unsupported_transport")); 130 131 String relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingBadTransportURI.wsdl"; 132 validate(relativePath, expectedErrors); 133 } 134 135 public void testSOAPBindingMissingTransportURI() throws Exception { 136 HashSet <String > expectedErrors = new HashSet <String >(); 137 expectedErrors.add(mMessages.getString("SOAPBindingValidator.Transport_URI_required")); 138 139 String relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingMissingTransportURI.wsdl"; 140 validate(relativePath, expectedErrors); 141 } 142 143 public void testSOAPBindingMissingAddress() throws Exception { 144 HashSet <String > expectedErrors = new HashSet <String >(); 145 expectedErrors.add(mMessages.getString("SOAPAddressValidator.Missing_SoapAddress")); 146 147 String relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingInvalidAddress.wsdl"; 148 validate(relativePath, expectedErrors); 149 } 150 151 public void testSOAPBindingMultipleAddresses() throws Exception { 152 HashSet <String > expectedErrors = new HashSet <String >(); 153 expectedErrors.add(mMessages.getString("SOAPAddressValidator.Only_one_SoapAddress_allowed")); 154 155 String relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingMultipleSoapAddress.wsdl"; 156 validate(relativePath, expectedErrors); 157 } 158 159 public void testSOAPBodyBadUse() throws Exception { 160 HashSet <String > expectedErrors = new HashSet <String >(); 161 expectedErrors.add(mMessages.getString("SOAPBodyValidator.Unsupported_use_attribute")); 162 163 String relativePath = "extensions/soap/validation/resources/invalid/SOAPBodyBadUse.wsdl"; 164 validate(relativePath, expectedErrors); 165 } 166 167 public void testSOAPBodyMultipleElements() throws Exception { 168 HashSet <String > expectedErrors = new HashSet <String >(); 169 expectedErrors.add(mMessages.getString("SOAPBodyValidator.Only_one_body_allowed")); 170 171 String relativePath = "extensions/soap/validation/resources/invalid/SOAPBodyMultipleElements.wsdl"; 172 validate(relativePath, expectedErrors); 173 174 relativePath = "extensions/soap/validation/resources/invalid/SOAPBodyMultipleElements1.wsdl"; 175 validate(relativePath, expectedErrors); 176 } 177 178 public void testSOAPFaultBadUse() throws Exception { 179 HashSet <String > expectedErrors = new HashSet <String >(); 180 expectedErrors.add(mMessages.getString("SOAPFaultValidator.Unsupported_use_attribute")); 181 182 String relativePath = "extensions/soap/validation/resources/invalid/SOAPFaultBadUse.wsdl"; 183 validate(relativePath, expectedErrors); 184 } 185 186 public void testSOAPFaultMissingName() throws Exception { 187 HashSet <String > expectedErrors = new HashSet <String >(); 188 expectedErrors.add(mMessages.getString("SOAPFaultValidator.Missing_name")); 189 190 String relativePath = "extensions/soap/validation/resources/invalid/SOAPFaultMissingName.wsdl"; 191 validate(relativePath, expectedErrors); 192 } 193 194 public void testSOAPFaultMultipleElements() throws Exception { 195 HashSet <String > expectedErrors = new HashSet <String >(); 196 expectedErrors.add(mMessages.getString("SOAPFaultValidator.Only_one_fault_allowed")); 197 198 String relativePath = "extensions/soap/validation/resources/invalid/SOAPFaultMultipleElements.wsdl"; 199 validate(relativePath, expectedErrors); 200 } 201 202 public void testSOAPHeaderBadUse() throws Exception { 203 HashSet <String > expectedErrors = new HashSet <String >(); 204 expectedErrors.add(mMessages.getString("SOAPHeaderValidator.Unsupported_header_use_attribute")); 205 206 String relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderBadUse.wsdl"; 207 validate(relativePath, expectedErrors); 208 } 209 210 public void testSOAPHeaderMissingMessage() throws Exception { 211 HashSet <String > expectedErrors = new HashSet <String >(); 212 expectedErrors.add(mMessages.getString("SOAPHeaderValidator.Missing_message")); 213 214 String relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderMissingMessage.wsdl"; 215 validate(relativePath, expectedErrors); 216 } 217 218 public void testSOAPHeaderMissingPart() throws Exception { 219 HashSet <String > expectedErrors = new HashSet <String >(); 220 expectedErrors.add(mMessages.getString("SOAPHeaderValidator.Missing_part")); 221 222 String relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderMissingPart.wsdl"; 223 validate(relativePath, expectedErrors); 224 } 225 226 public void testSOAPHeaderMissingUse() throws Exception { 227 HashSet <String > expectedErrors = new HashSet <String >(); 228 expectedErrors.add(mMessages.getString("SOAPHeaderValidator.Missing_use")); 229 230 String relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderMissingUse.wsdl"; 231 validate(relativePath, expectedErrors); 232 } 233 234 public void testSOAPHeaderFaultBadUse() throws Exception { 235 HashSet <String > expectedErrors = new HashSet <String >(); 236 expectedErrors.add(mMessages.getString("SOAPHeaderFaultValidator.Unsupported_header_fault_use_attribute")); 237 238 String relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderFaultBadUse.wsdl"; 239 validate(relativePath, expectedErrors); 240 } 241 242 public void testSOAPHeaderFaultMissingMessage() throws Exception { 243 HashSet <String > expectedErrors = new HashSet <String >(); 244 expectedErrors.add(mMessages.getString("SOAPHeaderFaultValidator.Missing_header_fault_message")); 245 246 String relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderFaultMissingMessage.wsdl"; 247 validate(relativePath, expectedErrors); 248 } 249 250 public void testSOAPHeaderFaultMissingPart() throws Exception { 251 HashSet <String > expectedErrors = new HashSet <String >(); 252 expectedErrors.add(mMessages.getString("SOAPHeaderFaultValidator.Missing_header_fault_part")); 253 254 String relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderFaultMissingPart.wsdl"; 255 validate(relativePath, expectedErrors); 256 } 257 258 public void testSOAPHeaderFaultMissingUse() throws Exception { 259 HashSet <String > expectedErrors = new HashSet <String >(); 260 expectedErrors.add(mMessages.getString("SOAPHeaderFaultValidator.Missing_header_fault_use")); 261 262 String relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderFaultMissingUse.wsdl"; 263 validate(relativePath, expectedErrors); 264 } 265 266 public void testSOAPOperationBadStyle() throws Exception { 267 HashSet <String > expectedErrors = new HashSet <String >(); 268 expectedErrors.add(mMessages.getString("SOAPOperationValidator.Unsupported_style_attribute")); 269 270 String relativePath = "extensions/soap/validation/resources/invalid/SOAPOperationBadStyle.wsdl"; 271 validate(relativePath, expectedErrors); 272 273 relativePath = "extensions/soap/validation/resources/invalid/SOAPOperationBadStyle1.wsdl"; 274 validate(relativePath, expectedErrors); 275 } 276 277 public void testSOAPOperationMissingBody() throws Exception { 278 HashSet <String > expectedErrors = new HashSet <String >(); 279 expectedErrors.add(mMessages.getString("SOAPBodyValidator.Atleast_one_body_Required")); 280 281 String relativePath = "extensions/soap/validation/resources/invalid/SOAPOperationMissingBody.wsdl"; 282 validate(relativePath, expectedErrors); 283 } 284 285 288 public void test6399367() throws Exception { 289 HashSet <String > expectedErrors = new HashSet <String >(); 290 expectedErrors.add(mMessages.getString("SOAPOperationValidator.Unsupported_style_attribute")); 291 expectedErrors.add(mMessages.getString("SOAPBindingValidator.Unsupported_style_attribute")); 292 293 String relativePath = "extensions/soap/validation/resources/invalid/6399367.wsdl"; 294 validate(relativePath, expectedErrors); 295 } 296 297 300 public void test6400567() throws Exception { 301 HashSet <String > expectedErrors = new HashSet <String >(); 302 expectedErrors.add(mMessages.getString("SOAPBodyValidator.Unsupported_use_attribute")); 303 304 String relativePath = "extensions/soap/validation/resources/invalid/6400567.wsdl"; 305 validate(relativePath, expectedErrors); 306 } 307 308 311 public void test6400569() throws Exception { 312 HashSet <String > expectedErrors = new HashSet <String >(); 313 expectedErrors.add(mMessages.getString("SOAPAddressValidator.Unsupported_location_attribute")); 314 315 String relativePath = "extensions/soap/validation/resources/invalid/6400569.wsdl"; 316 validate(relativePath, expectedErrors); 317 } 318 319 322 330 333 public void test6400574() throws Exception { 334 HashSet <String > expectedErrors = new HashSet <String >(); 335 expectedErrors.add(mMessages.getString("SOAPBindingValidator.Only_one_binding_allowed")); 336 337 String relativePath = "extensions/soap/validation/resources/invalid/6400574.wsdl"; 338 validate(relativePath, expectedErrors); 339 } 340 341 344 350 353 364 367 } 373 | Popular Tags |