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.staticanalysis;
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 java.util.regex.Pattern;
050: import junit.framework.*;
051: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
052: import org.netbeans.modules.xml.wsdl.model.extensions.TestCatalogModel;
053: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.ValidationHelper;
054: import org.netbeans.modules.xml.xam.spi.Validation;
055: import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
056: import org.netbeans.modules.xml.xam.spi.ValidationResult;
057: import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
058:
059: /**
060: *
061: * @author radval
062: */
063: public class BPELExtensionStaticAnalysisValidatorTest extends TestCase {
064:
065: private static final ResourceBundle mMessages = ResourceBundle
066: .getBundle(BPELExtensionStaticAnalysisValidatorTest.class
067: .getPackage().getName()
068: + ".Bundle");
069:
070: //
071:
072: public BPELExtensionStaticAnalysisValidatorTest(String testName) {
073: super (testName);
074: }
075:
076: protected void setUp() throws Exception {
077: }
078:
079: protected void tearDown() throws Exception {
080: }
081:
082: public void testProperty1() throws Exception {
083: HashSet<String> expectedErrors = new HashSet<String>();
084: expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY"));
085:
086: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidProperty1.wsdl";
087: URL url = getClass().getResource(fileName);
088: URI uri = url.toURI();
089:
090: validate(uri, expectedErrors);
091: }
092:
093: public void testProperty2() throws Exception {
094: HashSet<String> expectedErrors = new HashSet<String>();
095: expectedErrors
096: .add(mMessages
097: .getString("VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE"));
098:
099: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidProperty2.wsdl";
100: URL url = getClass().getResource(fileName);
101: URI uri = url.toURI();
102:
103: validate(uri, expectedErrors);
104: }
105:
106: public void testPropertyAlias() throws Exception {
107: HashSet<String> expectedErrors = new HashSet<String>();
108: expectedErrors.add(mMessages
109: .getString("VAL_INVALID_PROPERTY_ALIAS"));
110:
111: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAlias1.wsdl";
112: URL url = getClass().getResource(fileName);
113: URI uri = url.toURI();
114:
115: validate(uri, expectedErrors);
116: }
117:
118: public void testPropertyAliasMissingMessage() throws Exception {
119: HashSet<String> expectedErrors = new HashSet<String>();
120: expectedErrors
121: .add(mMessages
122: .getString("VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE"));
123:
124: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAliasMissingMessage.wsdl";
125: URL url = getClass().getResource(fileName);
126: URI uri = url.toURI();
127:
128: validate(uri, expectedErrors);
129: }
130:
131: public void testPropertyAliasMissingPart() throws Exception {
132: HashSet<String> expectedErrors = new HashSet<String>();
133: expectedErrors
134: .add(mMessages
135: .getString("VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART"));
136:
137: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAliasMissingMessagePart.wsdl";
138: URL url = getClass().getResource(fileName);
139: URI uri = url.toURI();
140:
141: validate(uri, expectedErrors);
142: }
143:
144: public void testPropertyAliasInvalidPart() throws Exception {
145: HashSet<String> expectedErrors = new HashSet<String>();
146: expectedErrors
147: .add(mMessages
148: .getString("VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE"));
149:
150: String fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAliasInvalidMessagePart.wsdl";
151: URL url = getClass().getResource(fileName);
152: URI uri = url.toURI();
153:
154: validate(uri, expectedErrors);
155: }
156:
157: private ValidationResult validate(URI relativePath)
158: throws Exception {
159: WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(
160: relativePath);
161: Validation validation = new Validation();
162: ValidationType validationType = Validation.ValidationType.COMPLETE;
163: BPELExtensionStaticAnalysisValidator instance = new BPELExtensionStaticAnalysisValidator();
164: ValidationResult result = instance.validate(model, validation,
165: validationType);
166: return result;
167: }
168:
169: private void validate(URI relativePath,
170: HashSet<String> expectedErrors) throws Exception {
171: System.out.println(relativePath);
172: ValidationResult result = validate(relativePath);
173: Iterator<ResultItem> it = result.getValidationResult()
174: .iterator();
175: ValidationHelper.dumpExpecedErrors(expectedErrors);
176: while (it.hasNext()) {
177: ResultItem item = it.next();
178: // System.out.println(" " + item.getDescription());
179: assertTrue("Actual Error " + item.getDescription() + "in "
180: + relativePath, ValidationHelper
181: .containsExpectedError(expectedErrors, item
182: .getDescription()));
183: }
184: if (result.getValidationResult().size() == 0
185: && expectedErrors.size() > 0) {
186: fail("Expected at least " + expectedErrors.size()
187: + " error(s). Got 0 errors instead");
188: }
189: }
190: }
|