KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > bpel > validation > semantic > BPELExtensionSemanticValidatorTest


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.semantic;
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 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 /**
37  *
38  * @author radval
39  */

40 public class BPELExtensionSemanticValidatorTest extends TestCase {
41     
42       private static final ResourceBundle JavaDoc mMessages =
43         ResourceBundle.getBundle(BPELExtensionSemanticValidatorTest.class.getPackage().getName()+".Bundle");
44
45     public BPELExtensionSemanticValidatorTest(String JavaDoc testName) {
46         super(testName);
47     }
48
49     protected void setUp() throws Exception JavaDoc {
50     }
51
52     protected void tearDown() throws Exception JavaDoc {
53     }
54
55     public void testPropertyAliasMissingProperty() throws Exception JavaDoc {
56          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
57         expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_NAME"));
58         
59         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAliasMissingProperty.wsdl";
60         URL JavaDoc url = getClass().getResource(fileName);
61         URI JavaDoc uri = url.toURI();
62         
63         validate(uri, expectedErrors);
64     }
65     
66     public void testPropertyAlias1() throws Exception JavaDoc {
67          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
68         expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE"));
69         
70         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAlias1.wsdl";
71         URL JavaDoc url = getClass().getResource(fileName);
72         URI JavaDoc uri = url.toURI();
73         
74         validate(uri, expectedErrors);
75     }
76     
77     public void testPropertyAlias2() throws Exception JavaDoc {
78          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
79         expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_ELEMENT"));
80         
81         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAlias2.wsdl";
82         URL JavaDoc url = getClass().getResource(fileName);
83         URI JavaDoc uri = url.toURI();
84         
85         validate(uri, expectedErrors);
86     }
87     
88     public void testPropertyAlias3() throws Exception JavaDoc {
89          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
90         expectedErrors.add(mMessages.getString("VAL_INVALID_PROPERTY_ALIAS_TYPE"));
91         
92         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPropertyAlias3.wsdl";
93         URL JavaDoc url = getClass().getResource(fileName);
94         URI JavaDoc uri = url.toURI();
95         
96         validate(uri, expectedErrors);
97     }
98
99     public void testPortType1() throws Exception JavaDoc {
100          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
101         expectedErrors.add(mMessages.getString("VAL_INVALID_PORT_TYPE"));
102         
103         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPortType1.wsdl";
104         URL JavaDoc url = getClass().getResource(fileName);
105         URI JavaDoc uri = url.toURI();
106         
107         validate(uri, expectedErrors);
108     }
109     
110     public void testPortType2() throws Exception JavaDoc {
111          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
112         expectedErrors.add(mMessages.getString("VAL_INVALID_PORT_TYPE"));
113         
114         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPortType2.wsdl";
115         URL JavaDoc url = getClass().getResource(fileName);
116         URI JavaDoc uri = url.toURI();
117         
118         validate(uri, expectedErrors);
119     }
120     
121     public void testPartnerLinkType1() throws Exception JavaDoc {
122          HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
123         expectedErrors.add(mMessages.getString("VAL_INVALID_PARTNERLINK_TYPE"));
124         
125         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/model/extensions/bpel/validation/semantic/resources/invalid/invalidPartnerLinkType1.wsdl";
126         URL JavaDoc url = getClass().getResource(fileName);
127         URI JavaDoc uri = url.toURI();
128         
129         validate(uri, expectedErrors);
130     }
131     
132     private ValidationResult validate(URI JavaDoc relativePath) throws Exception JavaDoc {
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 JavaDoc relativePath, HashSet JavaDoc<String JavaDoc> expectedErrors)
143         throws Exception JavaDoc {
144         System.out.println(relativePath);
145         ValidationResult result = validate(relativePath);
146         Iterator JavaDoc<ResultItem> it = result.getValidationResult().iterator();
147         ValidationHelper.dumpExpecedErrors(expectedErrors);
148         while (it.hasNext()) {
149             ResultItem item = it.next();
150 // System.out.println(" " + item.getDescription());
151
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