1 19 20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.staticanalysis; 21 22 import java.net.URI ; 23 import java.net.URL ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.ResourceBundle ; 27 import java.util.regex.Pattern ; 28 import junit.framework.*; 29 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 30 import org.netbeans.modules.xml.wsdl.model.extensions.TestCatalogModel; 31 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.ValidationHelper; 32 import org.netbeans.modules.xml.xam.spi.Validation; 33 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType; 34 import org.netbeans.modules.xml.xam.spi.ValidationResult; 35 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 36 37 41 public class BPELExtensionStaticAnalysisValidatorTest extends TestCase { 42 43 private static final ResourceBundle mMessages = 44 ResourceBundle.getBundle(BPELExtensionStaticAnalysisValidatorTest.class.getPackage().getName()+".Bundle"); 45 47 public BPELExtensionStaticAnalysisValidatorTest(String testName) { 48 super(testName); 49 } 50 51 protected void setUp() throws Exception { 52 } 53 54 protected void tearDown() throws Exception { 55 } 56 57 public void testProperty1() throws Exception { 58 HashSet <String > expectedErrors = new HashSet <String >(); 59 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY")); 60 61 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidProperty1.wsdl"; 62 URL url = getClass().getResource(fileName); 63 URI uri = url.toURI(); 64 65 validate(uri, expectedErrors); 66 } 67 68 public void testProperty2() throws Exception { 69 HashSet <String > expectedErrors = new HashSet <String >(); 70 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE")); 71 72 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidProperty2.wsdl"; 73 URL url = getClass().getResource(fileName); 74 URI uri = url.toURI(); 75 76 validate(uri, expectedErrors); 77 } 78 79 80 81 public void testPropertyAlias() throws Exception { 82 HashSet <String > expectedErrors = new HashSet <String >(); 83 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS")); 84 85 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAlias1.wsdl"; 86 URL url = getClass().getResource(fileName); 87 URI uri = url.toURI(); 88 89 validate(uri, expectedErrors); 90 } 91 92 public void testPropertyAliasMissingMessage() throws Exception { 93 HashSet <String > expectedErrors = new HashSet <String >(); 94 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE")); 95 96 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAliasMissingMessage.wsdl"; 97 URL url = getClass().getResource(fileName); 98 URI uri = url.toURI(); 99 100 validate(uri, expectedErrors); 101 } 102 103 public void testPropertyAliasMissingPart() throws Exception { 104 HashSet <String > expectedErrors = new HashSet <String >(); 105 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART")); 106 107 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAliasMissingMessagePart.wsdl"; 108 URL url = getClass().getResource(fileName); 109 URI uri = url.toURI(); 110 111 validate(uri, expectedErrors); 112 } 113 114 public void testPropertyAliasInvalidPart() throws Exception { 115 HashSet <String > expectedErrors = new HashSet <String >(); 116 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE")); 117 118 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAliasInvalidMessagePart.wsdl"; 119 URL url = getClass().getResource(fileName); 120 URI uri = url.toURI(); 121 122 validate(uri, expectedErrors); 123 } 124 125 126 private ValidationResult validate(URI relativePath) throws Exception { 127 WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(relativePath); 128 Validation validation = new Validation(); 129 ValidationType validationType = Validation.ValidationType.COMPLETE; 130 BPELExtensionStaticAnalysisValidator instance = new BPELExtensionStaticAnalysisValidator(); 131 ValidationResult result = 132 instance.validate(model, validation, validationType); 133 return result; 134 } 135 136 private void validate(URI relativePath, HashSet <String > expectedErrors) 137 throws Exception { 138 System.out.println(relativePath); 139 ValidationResult result = validate(relativePath); 140 Iterator <ResultItem> it = result.getValidationResult().iterator(); 141 ValidationHelper.dumpExpecedErrors(expectedErrors); 142 while (it.hasNext()) { 143 ResultItem item = it.next(); 144 assertTrue("Actual Error "+ item.getDescription() + "in " +relativePath, ValidationHelper.containsExpectedError(expectedErrors, item.getDescription())); 146 } 147 if (result.getValidationResult().size() == 0 && expectedErrors.size() > 0) { 148 fail("Expected at least " + expectedErrors.size() + " error(s). Got 0 errors instead"); 149 } 150 } 151 } 152 | Popular Tags |