KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > soap > validation > SOAPComponentValidatorTest


1 /*
2  * SOAPComponentValidatorTest.java
3  * JUnit based test
4  *
5  * Created on June 12, 2006, 6:37 PM
6  */

7
8 package org.netbeans.modules.xml.wsdl.model.extensions.soap.validation;
9
10 import junit.framework.*;
11 import java.io.File JavaDoc;
12 import java.io.FileFilter JavaDoc;
13 import java.net.URI JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.ResourceBundle JavaDoc;
17
18 import org.netbeans.modules.xml.wsdl.model.Util;
19 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
20 import org.netbeans.modules.xml.xam.spi.Validation;
21 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
22 import org.netbeans.modules.xml.xam.spi.ValidationResult;
23 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
24
25 import org.netbeans.modules.xml.wsdl.model.TestCatalogModel;
26
27 /**
28  *
29  * @author afung
30  */

31 public class SOAPComponentValidatorTest extends TestCase {
32
33     private static final ResourceBundle JavaDoc mMessages =
34         ResourceBundle.getBundle("org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.Bundle");
35
36     public SOAPComponentValidatorTest(String JavaDoc testName) {
37         super(testName);
38     }
39
40     protected void setUp() throws Exception JavaDoc {
41     }
42
43     protected void tearDown() throws Exception JavaDoc {
44         TestCatalogModel.getDefault().clearDocumentPool();
45     }
46
47     private ValidationResult validate(String JavaDoc relativePath) throws Exception JavaDoc {
48         WSDLModel model = Util.loadWSDLModel(relativePath);
49         Validation validation = new Validation();
50         ValidationType validationType = Validation.ValidationType.COMPLETE;
51         SOAPComponentValidator instance = new SOAPComponentValidator();
52         ValidationResult result =
53             instance.validate(model, validation, validationType);
54         return result;
55     }
56     
57     private void validate(String JavaDoc relativePath, HashSet JavaDoc<String JavaDoc> expectedErrors)
58         throws Exception JavaDoc {
59         System.out.println(relativePath);
60         ValidationResult result = validate(relativePath);
61         Iterator JavaDoc<ResultItem> it = result.getValidationResult().iterator();
62         while (it.hasNext()) {
63             ResultItem item = it.next();
64             System.out.println(" " + item.getDescription());
65             assertTrue(item.getDescription(), expectedErrors.contains(item.getDescription()));
66         }
67         if (result.getValidationResult().size() == 0 && expectedErrors.size() > 0) {
68             fail("Expected at least " + expectedErrors.size() + " error(s). Got 0 errors instead");
69         }
70     }
71     /**
72      * Test of getName method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
73      */

74     public void testGetName() throws Exception JavaDoc {
75         SOAPComponentValidator instance = new SOAPComponentValidator();
76         
77         String JavaDoc expResult = instance.getClass().getName();
78         String JavaDoc result = instance.getName();
79         assertEquals(expResult, result);
80     }
81
82     /**
83      * Test of validate method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
84      */

85     public void testValidWSDLs() throws Exception JavaDoc {
86         // Grab all our WSDL files to test using a known WSDL
87
URI JavaDoc resource = Util.getResourceURI("extensions/soap/validation/resources/valid/AccountTransaction.wsdl");
88         File JavaDoc resourceFile = new File JavaDoc(resource);
89         File JavaDoc[] wsdls = resourceFile.getParentFile().listFiles(new FileFilter JavaDoc() {
90             public boolean accept(File JavaDoc pathname) {
91                 return pathname.getName().endsWith(".wsdl");
92             }});
93         for (int ii = 0; ii < wsdls.length; ii++) {
94             String JavaDoc relativePath =
95                 "extensions/soap/validation/resources/valid/" +
96                 wsdls[ii].getName();
97             ValidationResult result = validate(relativePath);
98             assertTrue(result.getValidationResult().size() == 0);
99         }
100     }
101     
102     public void testSOAPAddressBadLocation() throws Exception JavaDoc {
103         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
104         expectedErrors.add(mMessages.getString("SOAPAddressValidator.Unsupported_location_attribute"));
105         
106         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPAddressBadLocation.wsdl";
107         validate(relativePath, expectedErrors);
108     }
109     
110     public void testSOAPAddressMissingLocation() throws Exception JavaDoc {
111         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
112         expectedErrors.add(mMessages.getString("SOAPAddressValidator.Missing_location"));
113         
114         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPAddressMissingLocation.wsdl";
115         validate(relativePath, expectedErrors);
116     }
117     
118     public void testSOAPBindingBadStyle() throws Exception JavaDoc {
119         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
120         expectedErrors.add(mMessages.getString("SOAPBindingValidator.Unsupported_style_attribute"));
121         expectedErrors.add(mMessages.getString("SOAPOperationValidator.Unsupported_style_attribute"));
122                 
123         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingBadStyle.wsdl";
124         validate(relativePath, expectedErrors);
125     }
126
127     public void testSOAPBindingBadTransportURI() throws Exception JavaDoc {
128         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
129         expectedErrors.add(mMessages.getString("SOAPBindingValidator.Unsupported_transport"));
130                 
131         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingBadTransportURI.wsdl";
132         validate(relativePath, expectedErrors);
133     }
134     
135     public void testSOAPBindingMissingTransportURI() throws Exception JavaDoc {
136         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
137         expectedErrors.add(mMessages.getString("SOAPBindingValidator.Transport_URI_required"));
138                 
139         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingMissingTransportURI.wsdl";
140         validate(relativePath, expectedErrors);
141     }
142     
143     public void testSOAPBindingMissingAddress() throws Exception JavaDoc {
144         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
145         expectedErrors.add(mMessages.getString("SOAPAddressValidator.Missing_SoapAddress"));
146         
147         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingInvalidAddress.wsdl";
148         validate(relativePath, expectedErrors);
149     }
150     
151     public void testSOAPBindingMultipleAddresses() throws Exception JavaDoc {
152         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
153         expectedErrors.add(mMessages.getString("SOAPAddressValidator.Only_one_SoapAddress_allowed"));
154         
155         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPBindingMultipleSoapAddress.wsdl";
156         validate(relativePath, expectedErrors);
157     }
158     
159     public void testSOAPBodyBadUse() throws Exception JavaDoc {
160         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
161         expectedErrors.add(mMessages.getString("SOAPBodyValidator.Unsupported_use_attribute"));
162                 
163         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPBodyBadUse.wsdl";
164         validate(relativePath, expectedErrors);
165     }
166
167     public void testSOAPBodyMultipleElements() throws Exception JavaDoc {
168         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
169         expectedErrors.add(mMessages.getString("SOAPBodyValidator.Only_one_body_allowed"));
170                 
171         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPBodyMultipleElements.wsdl";
172         validate(relativePath, expectedErrors);
173         
174         relativePath = "extensions/soap/validation/resources/invalid/SOAPBodyMultipleElements1.wsdl";
175         validate(relativePath, expectedErrors);
176     }
177         
178     public void testSOAPFaultBadUse() throws Exception JavaDoc {
179         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
180         expectedErrors.add(mMessages.getString("SOAPFaultValidator.Unsupported_use_attribute"));
181                 
182         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPFaultBadUse.wsdl";
183         validate(relativePath, expectedErrors);
184     }
185     
186     public void testSOAPFaultMissingName() throws Exception JavaDoc {
187         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
188         expectedErrors.add(mMessages.getString("SOAPFaultValidator.Missing_name"));
189                 
190         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPFaultMissingName.wsdl";
191         validate(relativePath, expectedErrors);
192     }
193
194     public void testSOAPFaultMultipleElements() throws Exception JavaDoc {
195         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
196         expectedErrors.add(mMessages.getString("SOAPFaultValidator.Only_one_fault_allowed"));
197                 
198         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPFaultMultipleElements.wsdl";
199         validate(relativePath, expectedErrors);
200     }
201         
202     public void testSOAPHeaderBadUse() throws Exception JavaDoc {
203         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
204         expectedErrors.add(mMessages.getString("SOAPHeaderValidator.Unsupported_header_use_attribute"));
205                 
206         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderBadUse.wsdl";
207         validate(relativePath, expectedErrors);
208     }
209  
210     public void testSOAPHeaderMissingMessage() throws Exception JavaDoc {
211         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
212         expectedErrors.add(mMessages.getString("SOAPHeaderValidator.Missing_message"));
213                 
214         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderMissingMessage.wsdl";
215         validate(relativePath, expectedErrors);
216     }
217     
218     public void testSOAPHeaderMissingPart() throws Exception JavaDoc {
219         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
220         expectedErrors.add(mMessages.getString("SOAPHeaderValidator.Missing_part"));
221                 
222         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderMissingPart.wsdl";
223         validate(relativePath, expectedErrors);
224     }
225     
226     public void testSOAPHeaderMissingUse() throws Exception JavaDoc {
227         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
228         expectedErrors.add(mMessages.getString("SOAPHeaderValidator.Missing_use"));
229                 
230         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderMissingUse.wsdl";
231         validate(relativePath, expectedErrors);
232     }
233     
234     public void testSOAPHeaderFaultBadUse() throws Exception JavaDoc {
235         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
236         expectedErrors.add(mMessages.getString("SOAPHeaderFaultValidator.Unsupported_header_fault_use_attribute"));
237                 
238         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderFaultBadUse.wsdl";
239         validate(relativePath, expectedErrors);
240     }
241     
242     public void testSOAPHeaderFaultMissingMessage() throws Exception JavaDoc {
243         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
244         expectedErrors.add(mMessages.getString("SOAPHeaderFaultValidator.Missing_header_fault_message"));
245                 
246         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderFaultMissingMessage.wsdl";
247         validate(relativePath, expectedErrors);
248     }
249     
250     public void testSOAPHeaderFaultMissingPart() throws Exception JavaDoc {
251         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
252         expectedErrors.add(mMessages.getString("SOAPHeaderFaultValidator.Missing_header_fault_part"));
253                 
254         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderFaultMissingPart.wsdl";
255         validate(relativePath, expectedErrors);
256     }
257     
258     public void testSOAPHeaderFaultMissingUse() throws Exception JavaDoc {
259         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
260         expectedErrors.add(mMessages.getString("SOAPHeaderFaultValidator.Missing_header_fault_use"));
261                 
262         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPHeaderFaultMissingUse.wsdl";
263         validate(relativePath, expectedErrors);
264     }
265     
266     public void testSOAPOperationBadStyle() throws Exception JavaDoc {
267         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
268         expectedErrors.add(mMessages.getString("SOAPOperationValidator.Unsupported_style_attribute"));
269                 
270         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPOperationBadStyle.wsdl";
271         validate(relativePath, expectedErrors);
272         
273         relativePath = "extensions/soap/validation/resources/invalid/SOAPOperationBadStyle1.wsdl";
274         validate(relativePath, expectedErrors);
275     }
276     
277     public void testSOAPOperationMissingBody() throws Exception JavaDoc {
278         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
279         expectedErrors.add(mMessages.getString("SOAPBodyValidator.Atleast_one_body_Required"));
280         
281         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/SOAPOperationMissingBody.wsdl";
282         validate(relativePath, expectedErrors);
283     }
284     
285     /**
286      * Test of validate method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
287      */

288     public void test6399367() throws Exception JavaDoc {
289         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
290         expectedErrors.add(mMessages.getString("SOAPOperationValidator.Unsupported_style_attribute"));
291         expectedErrors.add(mMessages.getString("SOAPBindingValidator.Unsupported_style_attribute"));
292         
293         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/6399367.wsdl";
294         validate(relativePath, expectedErrors);
295     }
296     
297     /**
298      * Test of validate method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
299      */

300     public void test6400567() throws Exception JavaDoc {
301         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
302         expectedErrors.add(mMessages.getString("SOAPBodyValidator.Unsupported_use_attribute"));
303         
304         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/6400567.wsdl";
305         validate(relativePath, expectedErrors);
306     }
307     
308     /**
309      * Test of validate method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
310      */

311     public void test6400569() throws Exception JavaDoc {
312         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
313         expectedErrors.add(mMessages.getString("SOAPAddressValidator.Unsupported_location_attribute"));
314         
315         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/6400569.wsdl";
316         validate(relativePath, expectedErrors);
317     }
318     
319     /**
320      * Test of validate method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
321      */

322 // public void test6400573() throws Exception {
323
// HashSet<String> expectedErrors = new HashSet<String>();
324
// expectedErrors.add(mMessages.getString("SOAPBodyValidator.No_abstract_message"));
325
//
326
// String relativePath = "extensions/soap/validation/resources/invalid/6400573.wsdl";
327
// validate(relativePath, expectedErrors);
328
// }
329

330     /**
331      * Test of validate method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
332      */

333     public void test6400574() throws Exception JavaDoc {
334         HashSet JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
335         expectedErrors.add(mMessages.getString("SOAPBindingValidator.Only_one_binding_allowed"));
336         
337         String JavaDoc relativePath = "extensions/soap/validation/resources/invalid/6400574.wsdl";
338         validate(relativePath, expectedErrors);
339     }
340     
341     /**
342      * Test of validate method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
343      */

344 // public void test6400597() throws Exception {
345
// HashSet<String> expectedErrors = new HashSet<String>();
346
// String relativePath = "extensions/soap/validation/resources/invalid/6400597.wsdl";
347
// validate(relativePath, expectedErrors);
348
// }
349

350     /**
351      * Test of validate method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
352      */

353 // public void test6400598() throws Exception {
354
// String relativePath = "extensions/soap/validation/resources/invalid/6400598.wsdl";
355
// ValidationResult result = validate(relativePath);
356
// Iterator<ResultItem> it = result.getValidationResult().iterator();
357
// System.out.println("6400598");
358
// while (it.hasNext()) {
359
// ResultItem item = it.next();
360
// System.out.println(item.getDescription());
361
// }
362
// }
363

364     /**
365      * Test of validate method, of class org.netbeans.modules.xml.wsdl.model.extensions.soap.validation.SOAPComponentValidator.
366      */

367 // public void test6400610() throws Exception {
368
// HashSet<String> expectedErrors = new HashSet<String>();
369
// String relativePath = "extensions/soap/validation/resources/invalid/6400610.wsdl";
370
// validate(relativePath, expectedErrors);
371
// }
372
}
373
Popular Tags