KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > validator > WSDLSchemaValidatorTest


1 /*
2  * WSDLSchemaValidatorTest.java
3  * JUnit based test
4  *
5  * Created on January 29, 2007, 10:47 AM
6  */

7
8 package org.netbeans.modules.xml.wsdl.validator;
9
10 import java.net.URI JavaDoc;
11 import java.net.URL JavaDoc;
12 import junit.framework.*;
13 import javax.xml.validation.Schema JavaDoc;
14 import org.netbeans.modules.xml.wsdl.model.TestCatalogModel;
15 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
16 import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory;
17 import org.netbeans.modules.xml.xam.ModelSource;
18 import org.netbeans.modules.xml.xam.spi.Validation;
19 import org.netbeans.modules.xml.xam.spi.ValidationResult;
20
21 /**
22  *
23  * @author radval
24  */

25 public class WSDLSchemaValidatorTest extends TestCase {
26     
27     public WSDLSchemaValidatorTest(String JavaDoc testName) {
28         super(testName);
29     }
30
31     protected void setUp() throws Exception JavaDoc {
32     }
33
34     protected void tearDown() throws Exception JavaDoc {
35     }
36
37     /**
38      * Test of getName method, of class org.netbeans.modules.xml.wsdl.validator.WSDLSchemaValidator.
39      */

40     public void testGetName() {
41         System.out.println("getName");
42         
43         WSDLSchemaValidator instance = new WSDLSchemaValidator();
44         
45         String JavaDoc expResult = "WSDLSchemaValidator";
46         String JavaDoc result = instance.getName();
47         assertEquals(expResult, result);
48         
49     }
50
51     /**
52      * Test of getSchema method, of class org.netbeans.modules.xml.wsdl.validator.WSDLSchemaValidator.
53      */

54     public void testGetSchema() throws Exception JavaDoc {
55         System.out.println("getSchema");
56         
57         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/visitor/resources/valid/AccountTransaction.wsdl";
58         URL JavaDoc url = getClass().getResource(fileName);
59         URI JavaDoc uri = url.toURI();
60         
61         WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(uri);
62         
63         WSDLSchemaValidator instance = new WSDLSchemaValidator();
64         
65         Schema JavaDoc expResult = null;
66         Schema JavaDoc result = instance.getSchema(model);
67         assertNotNull(result);
68         
69     }
70     
71     
72     public void testValidateImportMultiLocation() throws Exception JavaDoc {
73         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/importWSDLtests/importMultiLocation_error.wsdl";
74         URL JavaDoc url = getClass().getResource(fileName);
75         URI JavaDoc uri = url.toURI();
76         
77         validate(uri, 1);
78     }
79     
80     public void testValidateImportMultiNamespace() throws Exception JavaDoc {
81         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/importWSDLtests/importMultiNamespace_error.wsdl";
82         URL JavaDoc url = getClass().getResource(fileName);
83         URI JavaDoc uri = url.toURI();
84         
85         validate(uri, 1);
86     }
87     
88     public void testValidateImportNoLocation() throws Exception JavaDoc {
89         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/importWSDLtests/importNoLocation_error.wsdl";
90         URL JavaDoc url = getClass().getResource(fileName);
91         URI JavaDoc uri = url.toURI();
92         
93         validate(uri, 1);
94     }
95     
96     
97     public void testValidateImportNoNamespace() throws Exception JavaDoc {
98         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/importWSDLtests/importNoNamespace_error.wsdl";
99         URL JavaDoc url = getClass().getResource(fileName);
100         URI JavaDoc uri = url.toURI();
101         
102         validate(uri, 2);
103     }
104     
105     public void testValidateMessageMultiDocumentation() throws Exception JavaDoc {
106         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/messageTests/messageMultiDocumentation_error.wsdl";
107         URL JavaDoc url = getClass().getResource(fileName);
108         URI JavaDoc uri = url.toURI();
109         
110         validate(uri, 1);
111     }
112     
113     public void testValidateMessageMultiName() throws Exception JavaDoc {
114         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/messageTests/messageMultiName_error.wsdl";
115         URL JavaDoc url = getClass().getResource(fileName);
116         URI JavaDoc uri = url.toURI();
117         
118         validate(uri, 1);
119     }
120     
121     public void testValidateMessageNoName() throws Exception JavaDoc {
122         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/messageTests/messageNoName_error.wsdl";
123         URL JavaDoc url = getClass().getResource(fileName);
124         URI JavaDoc uri = url.toURI();
125         
126         validate(uri, 2);
127     }
128    
129      public void testValidateMessageNonUniqueName() throws Exception JavaDoc {
130         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/messageTests/messageNonUniqueName_error.wsdl";
131         URL JavaDoc url = getClass().getResource(fileName);
132         URI JavaDoc uri = url.toURI();
133         
134         validate(uri, 1);
135     }
136      
137             
138      private void validate(URI JavaDoc uri, int expectedErrorCount)
139         throws Exception JavaDoc {
140         Validation v = new Validation();
141         
142         ModelSource ms = TestCatalogModel.getDefault().getModelSource(uri);
143         MyModelSource source = new MyModelSource(ms.getLookup(), ms.isEditable(), uri);
144         
145         WSDLModel model = WSDLModelFactory.getDefault().getModel(source);
146         
147         WSDLSchemaValidator instance = new WSDLSchemaValidator();
148         ValidationResult vr = instance.validate(model, v, Validation.ValidationType.COMPLETE);
149         assertNotNull(vr.getValidationResult());
150         
151         ValidationHelper.dumpErrors(vr);
152         assertTrue("expect error " + expectedErrorCount, vr.getValidationResult().size() == expectedErrorCount);
153      }
154      
155      
156     
157 }
158
Popular Tags