1 19 20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.semantic; 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 junit.framework.*; 28 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 29 import org.netbeans.modules.xml.wsdl.model.extensions.TestCatalogModel; 30 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.ValidationHelper; 31 import org.netbeans.modules.xml.xam.spi.Validation; 32 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType; 33 import org.netbeans.modules.xml.xam.spi.ValidationResult; 34 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 35 36 40 public class BPELExtensionSemanticValidatorTest extends TestCase { 41 42 private static final ResourceBundle mMessages = 43 ResourceBundle.getBundle(BPELExtensionSemanticValidatorTest.class.getPackage().getName()+".Bundle"); 44 45 public BPELExtensionSemanticValidatorTest(String testName) { 46 super(testName); 47 } 48 49 protected void setUp() throws Exception { 50 } 51 52 protected void tearDown() throws Exception { 53 } 54 55 public void testPropertyAliasMissingProperty() throws Exception { 56 HashSet <String > expectedErrors = new HashSet <String >(); 57 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_NAME")); 58 59 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAliasMissingProperty.wsdl"; 60 URL url = getClass().getResource(fileName); 61 URI uri = url.toURI(); 62 63 validate(uri, expectedErrors); 64 } 65 66 public void testPropertyAlias1() throws Exception { 67 HashSet <String > expectedErrors = new HashSet <String >(); 68 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE")); 69 70 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAlias1.wsdl"; 71 URL url = getClass().getResource(fileName); 72 URI uri = url.toURI(); 73 74 validate(uri, expectedErrors); 75 } 76 77 public void testPropertyAlias2() throws Exception { 78 HashSet <String > expectedErrors = new HashSet <String >(); 79 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_ELEMENT")); 80 81 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAlias2.wsdl"; 82 URL url = getClass().getResource(fileName); 83 URI uri = url.toURI(); 84 85 validate(uri, expectedErrors); 86 } 87 88 public void testPropertyAlias3() throws Exception { 89 HashSet <String > expectedErrors = new HashSet <String >(); 90 expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_TYPE")); 91 92 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAlias3.wsdl"; 93 URL url = getClass().getResource(fileName); 94 URI uri = url.toURI(); 95 96 validate(uri, expectedErrors); 97 } 98 99 public void testPortType1() throws Exception { 100 HashSet <String > expectedErrors = new HashSet <String >(); 101 expectedErrors.add(mMessages.getString("VAL_INVALID_PORT_TYPE")); 102 103 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPortType1.wsdl"; 104 URL url = getClass().getResource(fileName); 105 URI uri = url.toURI(); 106 107 validate(uri, expectedErrors); 108 } 109 110 public void testPortType2() throws Exception { 111 HashSet <String > expectedErrors = new HashSet <String >(); 112 expectedErrors.add(mMessages.getString("VAL_INVALID_PORT_TYPE")); 113 114 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPortType2.wsdl"; 115 URL url = getClass().getResource(fileName); 116 URI uri = url.toURI(); 117 118 validate(uri, expectedErrors); 119 } 120 121 public void testPartnerLinkType1() throws Exception { 122 HashSet <String > expectedErrors = new HashSet <String >(); 123 expectedErrors.add(mMessages.getString("VAL_INVALID_PARTNERLINK_TYPE")); 124 125 String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPartnerLinkType1.wsdl"; 126 URL url = getClass().getResource(fileName); 127 URI uri = url.toURI(); 128 129 validate(uri, expectedErrors); 130 } 131 132 private ValidationResult validate(URI relativePath) throws Exception { 133 WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(relativePath); 134 Validation validation = new Validation(); 135 ValidationType validationType = Validation.ValidationType.COMPLETE; 136 BPELExtensionSemanticValidator instance = new BPELExtensionSemanticValidator(); 137 ValidationResult result = 138 instance.validate(model, validation, validationType); 139 return result; 140 } 141 142 private void validate(URI relativePath, HashSet <String > expectedErrors) 143 throws Exception { 144 System.out.println(relativePath); 145 ValidationResult result = validate(relativePath); 146 Iterator <ResultItem> it = result.getValidationResult().iterator(); 147 ValidationHelper.dumpExpecedErrors(expectedErrors); 148 while (it.hasNext()) { 149 ResultItem item = it.next(); 150 assertTrue("Actual Error "+ item.getDescription() + "in " +relativePath, ValidationHelper.containsExpectedError(expectedErrors, item.getDescription())); 152 } 153 if (result.getValidationResult().size() == 0 && expectedErrors.size() > 0) { 154 fail("Expected at least " + expectedErrors.size() + " error(s). Got 0 errors instead"); 155 } 156 } 157 158 } 159 | Popular Tags |