KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > bpel > validation > staticanalysis > BPELExtensionStaticAnalysisValidatorTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.staticanalysis;
21
22 import java.net.URI JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27 import java.util.regex.Pattern JavaDoc;
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 /**
38  *
39  * @author radval
40  */

41 public class BPELExtensionStaticAnalysisValidatorTest extends TestCase {
42     
43     private static final ResourceBundle JavaDoc mMessages =
44         ResourceBundle.getBundle(BPELExtensionStaticAnalysisValidatorTest.class.getPackage().getName()+".Bundle");
45 //
46

47     public BPELExtensionStaticAnalysisValidatorTest(String JavaDoc testName) {
48         super(testName);
49     }
50
51     protected void setUp() throws Exception JavaDoc {
52     }
53
54     protected void tearDown() throws Exception JavaDoc {
55     }
56     
57     public void testProperty1() throws Exception JavaDoc {
58          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
59         expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY"));
60         
61         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidProperty1.wsdl";
62         URL JavaDoc url = getClass().getResource(fileName);
63         URI JavaDoc uri = url.toURI();
64         
65         validate(uri, expectedErrors);
66     }
67     
68     public void testProperty2() throws Exception JavaDoc {
69          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
70          expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE"));
71         
72         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidProperty2.wsdl";
73         URL JavaDoc url = getClass().getResource(fileName);
74         URI JavaDoc uri = url.toURI();
75         
76         validate(uri, expectedErrors);
77     }
78     
79     
80             
81     public void testPropertyAlias() throws Exception JavaDoc {
82          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
83         expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS"));
84         
85         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAlias1.wsdl";
86         URL JavaDoc url = getClass().getResource(fileName);
87         URI JavaDoc uri = url.toURI();
88         
89         validate(uri, expectedErrors);
90     }
91  
92     public void testPropertyAliasMissingMessage() throws Exception JavaDoc {
93          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
94         expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE"));
95         
96         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAliasMissingMessage.wsdl";
97         URL JavaDoc url = getClass().getResource(fileName);
98         URI JavaDoc uri = url.toURI();
99         
100         validate(uri, expectedErrors);
101     }
102  
103     public void testPropertyAliasMissingPart() throws Exception JavaDoc {
104          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
105         expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART"));
106         
107         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAliasMissingMessagePart.wsdl";
108         URL JavaDoc url = getClass().getResource(fileName);
109         URI JavaDoc uri = url.toURI();
110         
111         validate(uri, expectedErrors);
112     }
113     
114     public void testPropertyAliasInvalidPart() throws Exception JavaDoc {
115          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
116         expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE"));
117         
118         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/staticanalysis/resources/invalid/invalidPropertyAliasInvalidMessagePart.wsdl";
119         URL JavaDoc url = getClass().getResource(fileName);
120         URI JavaDoc uri = url.toURI();
121         
122         validate(uri, expectedErrors);
123     }
124     
125     
126     private ValidationResult validate(URI JavaDoc relativePath) throws Exception JavaDoc {
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 JavaDoc relativePath, HashSet JavaDoc<String JavaDoc> expectedErrors)
137         throws Exception JavaDoc {
138         System.out.println(relativePath);
139         ValidationResult result = validate(relativePath);
140         Iterator JavaDoc<ResultItem> it = result.getValidationResult().iterator();
141         ValidationHelper.dumpExpecedErrors(expectedErrors);
142         while (it.hasNext()) {
143             ResultItem item = it.next();
144 // System.out.println(" " + item.getDescription());
145
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