KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * WSDLInlineSchemaValidatorTest.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.URL JavaDoc;
11 import java.util.Set JavaDoc;
12 import junit.framework.*;
13 import java.net.URI JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import javax.xml.validation.Schema JavaDoc;
17 import org.netbeans.modules.xml.wsdl.model.TestCatalogModel;
18 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
19 import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory;
20 import org.netbeans.modules.xml.xam.Model;
21 import org.netbeans.modules.xml.xam.ModelSource;
22 import org.netbeans.modules.xml.xam.spi.Validation;
23 import org.netbeans.modules.xml.xam.spi.ValidationResult;
24 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
25 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
26
27 /**
28  *
29  * @author radval
30  */

31 public class WSDLInlineSchemaValidatorTest extends TestCase {
32     
33     public WSDLInlineSchemaValidatorTest(String JavaDoc testName) {
34         super(testName);
35     }
36
37     protected void setUp() throws Exception JavaDoc {
38     }
39
40     protected void tearDown() throws Exception JavaDoc {
41     }
42
43     /**
44      * Test of getName method, of class org.netbeans.modules.xml.wsdl.validator.WSDLInlineSchemaValidator.
45      */

46     public void testGetName() {
47         System.out.println("getName");
48         
49         WSDLInlineSchemaValidator instance = new WSDLInlineSchemaValidator();
50         
51         String JavaDoc expResult = "WSDLInlineSchemaValidator";
52         String JavaDoc result = instance.getName();
53         assertEquals(expResult, result);
54         
55
56     }
57
58     /**
59      * Test of validate method, of class org.netbeans.modules.xml.wsdl.validator.WSDLInlineSchemaValidator.
60      */

61     public void testValidate() throws Exception JavaDoc {
62         System.out.println("validate");
63         
64         String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/visitor/resources/valid/AccountTransaction.wsdl";
65         URL JavaDoc url = getClass().getResource(fileName);
66         URI JavaDoc uri = url.toURI();
67         
68         Set JavaDoc<String JavaDoc> expectedErrors = new HashSet JavaDoc<String JavaDoc>();
69         validate(uri, expectedErrors);
70         
71     }
72
73     /**
74      * Test of getSchema method, of class org.netbeans.modules.xml.wsdl.validator.WSDLInlineSchemaValidator.
75      */

76     public void testGetSchema() {
77         System.out.println("getSchema");
78         
79         Model model = null;
80         WSDLInlineSchemaValidator instance = new WSDLInlineSchemaValidator();
81         
82         Schema JavaDoc expResult = null;
83         Schema JavaDoc result = instance.getSchema(model);
84         assertEquals(expResult, result);
85         
86     }
87
88     /**
89      * Test of resolveResource method, of class org.netbeans.modules.xml.wsdl.validator.WSDLInlineSchemaValidator.
90      */

91 // public void testResolveResource() {
92
// System.out.println("resolveResource");
93
//
94
// String systemId = "";
95
// Model currentModel = null;
96
// WSDLInlineSchemaValidator instance = new WSDLInlineSchemaValidator();
97
//
98
// DocumentModel expResult = null;
99
// DocumentModel result = instance.resolveResource(systemId, currentModel);
100
// assertEquals(expResult, result);
101
//
102
//
103
// }
104

105     public void testSapInlineCrossReferenceValid() throws Exception JavaDoc {
106          String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/typesTests/inlineSchemaTests/Z_Flight.wsdl";
107         URL JavaDoc url = getClass().getResource(fileName);
108         URI JavaDoc uri = url.toURI();
109         
110         validate(uri, 0);
111     }
112     
113     
114     public void testInlineCrossReferenceValid() throws Exception JavaDoc {
115           String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/typesTests/inlineSchemaTests/InlineSchemaCrossReference.wsdl";
116         URL JavaDoc url = getClass().getResource(fileName);
117         URI JavaDoc uri = url.toURI();
118         
119         validate(uri, 0);
120     }
121     
122       public void testInlineSchemaImportingAnotherSchemaValid() throws Exception JavaDoc {
123           String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/typesTests/inlineSchemaTests/Z_FlightWSD_EUC_SAP.wsdl";
124         URL JavaDoc url = getClass().getResource(fileName);
125         URI JavaDoc uri = url.toURI();
126         
127         validate(uri, 0);
128     }
129       
130             
131       public void testInlineSchemaImportingAnotherSchemaUsingCatalogValid() throws Exception JavaDoc {
132           //this test is to mimic wsdl importing xsd which imports another xsd from different projevt
133
//so it uses catalog.xml at project level
134
String JavaDoc fileName = "/org/netbeans/modules/xml/wsdl/validator/resources/typesTests/inlineSchemaTests/InventoryService.wsdl";
135           URL JavaDoc url = getClass().getResource(fileName);
136           URI JavaDoc uri = url.toURI();
137           
138           validate(uri, 0);
139       }
140     
141     private void validate(URI JavaDoc uri, int expectedErrorCount)
142         throws Exception JavaDoc {
143         Validation v = new Validation();
144         
145         ModelSource ms = TestCatalogModel.getDefault().getModelSource(uri);
146         MyModelSource source = new MyModelSource(ms.getLookup(), ms.isEditable(), uri);
147         
148         WSDLModel model = WSDLModelFactory.getDefault().getModel(source);
149         
150         WSDLSchemaValidator instance = new WSDLSchemaValidator();
151         ValidationResult vr = instance.validate(model, v, Validation.ValidationType.COMPLETE);
152         assertNotNull(vr.getValidationResult());
153         
154         ValidationHelper.dumpErrors(vr);
155         assertTrue("expect error " + expectedErrorCount, vr.getValidationResult().size() == expectedErrorCount);
156      }
157      
158     
159     private ValidationResult validate(URI JavaDoc relativePath) throws Exception JavaDoc {
160         WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(relativePath);
161         Validation validation = new Validation();
162         ValidationType validationType = Validation.ValidationType.COMPLETE;
163         WSDLInlineSchemaValidator instance = new WSDLInlineSchemaValidator();
164         
165         ValidationResult result =
166             instance.validate(model, validation, validationType);
167         return result;
168     }
169     
170     private void validate(URI JavaDoc relativePath, Set JavaDoc<String JavaDoc> expectedErrors)
171         throws Exception JavaDoc {
172         System.out.println(relativePath);
173         ValidationResult result = validate(relativePath);
174         Iterator JavaDoc<ResultItem> it = result.getValidationResult().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 " +relativePath, ValidationHelper.containsExpectedError(expectedErrors, item.getDescription()));
180         }
181         if (result.getValidationResult().size() == 0 && expectedErrors.size() > 0) {
182             fail("Expected at least " + expectedErrors.size() + " error(s). Got 0 errors instead");
183         }
184     }
185 }
186
Popular Tags