001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.semantic;
043:
044: import java.net.URI;
045: import java.net.URL;
046: import java.util.HashSet;
047: import java.util.Iterator;
048: import java.util.ResourceBundle;
049: import junit.framework.*;
050: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
051: import org.netbeans.modules.xml.wsdl.model.extensions.TestCatalogModel;
052: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.ValidationHelper;
053: import org.netbeans.modules.xml.xam.spi.Validation;
054: import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
055: import org.netbeans.modules.xml.xam.spi.ValidationResult;
056: import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
057:
058: /**
059: *
060: * @author radval
061: */
062: public class BPELExtensionSemanticValidatorTest extends TestCase {
063:
064: private static final ResourceBundle mMessages = ResourceBundle
065: .getBundle(BPELExtensionSemanticValidatorTest.class
066: .getPackage().getName()
067: + ".Bundle");
068:
069: public BPELExtensionSemanticValidatorTest(String testName) {
070: super (testName);
071: }
072:
073: protected void setUp() throws Exception {
074: }
075:
076: protected void tearDown() throws Exception {
077: }
078:
079: public void testPropertyAliasMissingProperty() throws Exception {
080: HashSet<String> expectedErrors = new HashSet<String>();
081: expectedErrors.add(mMessages
082: .getString("VAL_INVALID_PROPERTY_NAME"));
083:
084: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAliasMissingProperty.wsdl";
085: URL url = getClass().getResource(fileName);
086: URI uri = url.toURI();
087:
088: validate(uri, expectedErrors);
089: }
090:
091: public void testPropertyAlias1() throws Exception {
092: HashSet<String> expectedErrors = new HashSet<String>();
093: expectedErrors.add(mMessages
094: .getString("VAL_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE"));
095:
096: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAlias1.wsdl";
097: URL url = getClass().getResource(fileName);
098: URI uri = url.toURI();
099:
100: validate(uri, expectedErrors);
101: }
102:
103: public void testPropertyAlias2() throws Exception {
104: HashSet<String> expectedErrors = new HashSet<String>();
105: expectedErrors.add(mMessages
106: .getString("VAL_INVALID_PROPERTY_ALIAS_ELEMENT"));
107:
108: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAlias2.wsdl";
109: URL url = getClass().getResource(fileName);
110: URI uri = url.toURI();
111:
112: validate(uri, expectedErrors);
113: }
114:
115: public void testPropertyAlias3() throws Exception {
116: HashSet<String> expectedErrors = new HashSet<String>();
117: expectedErrors.add(mMessages
118: .getString("VAL_INVALID_PROPERTY_ALIAS_TYPE"));
119:
120: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAlias3.wsdl";
121: URL url = getClass().getResource(fileName);
122: URI uri = url.toURI();
123:
124: validate(uri, expectedErrors);
125: }
126:
127: public void testPortType1() throws Exception {
128: HashSet<String> expectedErrors = new HashSet<String>();
129: expectedErrors
130: .add(mMessages.getString("VAL_INVALID_PORT_TYPE"));
131:
132: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPortType1.wsdl";
133: URL url = getClass().getResource(fileName);
134: URI uri = url.toURI();
135:
136: validate(uri, expectedErrors);
137: }
138:
139: public void testPortType2() throws Exception {
140: HashSet<String> expectedErrors = new HashSet<String>();
141: expectedErrors
142: .add(mMessages.getString("VAL_INVALID_PORT_TYPE"));
143:
144: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPortType2.wsdl";
145: URL url = getClass().getResource(fileName);
146: URI uri = url.toURI();
147:
148: validate(uri, expectedErrors);
149: }
150:
151: public void testPartnerLinkType1() throws Exception {
152: HashSet<String> expectedErrors = new HashSet<String>();
153: expectedErrors.add(mMessages
154: .getString("VAL_INVALID_PARTNERLINK_TYPE"));
155:
156: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPartnerLinkType1.wsdl";
157: URL url = getClass().getResource(fileName);
158: URI uri = url.toURI();
159:
160: validate(uri, expectedErrors);
161: }
162:
163: private ValidationResult validate(URI relativePath)
164: throws Exception {
165: WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(
166: relativePath);
167: Validation validation = new Validation();
168: ValidationType validationType = Validation.ValidationType.COMPLETE;
169: BPELExtensionSemanticValidator instance = new BPELExtensionSemanticValidator();
170: ValidationResult result = instance.validate(model, validation,
171: validationType);
172: return result;
173: }
174:
175: private void validate(URI relativePath,
176: HashSet<String> expectedErrors) throws Exception {
177: System.out.println(relativePath);
178: ValidationResult result = validate(relativePath);
179: Iterator<ResultItem> it = result.getValidationResult()
180: .iterator();
181: ValidationHelper.dumpExpecedErrors(expectedErrors);
182: while (it.hasNext()) {
183: ResultItem item = it.next();
184: // System.out.println(" " + item.getDescription());
185: assertTrue("Actual Error " + item.getDescription() + "in "
186: + relativePath, ValidationHelper
187: .containsExpectedError(expectedErrors, item
188: .getDescription()));
189: }
190: if (result.getValidationResult().size() == 0
191: && expectedErrors.size() > 0) {
192: fail("Expected at least " + expectedErrors.size()
193: + " error(s). Got 0 errors instead");
194: }
195: }
196:
197: }
|