1 /*
2 wsmo4j - a WSMO API and Reference Implementation
3
4 Copyright (c) 2005, University of Innsbruck, Austria
5
6 This library is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the Free
8 Software Foundation; either version 2.1 of the License, or (at your option)
9 any later version.
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 details.
14 You should have received a copy of the GNU Lesser General Public License along
15 with this library; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 package test.wsmo4j.validator;
19
20 import java.io.InputStream;
21 import java.io.InputStreamReader;
22
23 import org.omwg.ontology.Ontology;
24 import org.wsmo.factory.Factory;
25 import org.wsmo.validator.WsmlValidator;
26
27
28 /**
29 * Checks if WSML files are valid and checks the error messages if not.
30 * One of the given testfiles checks only for the conceptual model, the
31 * others for the logical expressions.
32 *
33 * <pre>
34 * Created on Dec 19, 2005
35 * Committed by $Author: nathaliest $
36 * $Source$,
37 * </pre>
38 *
39 * @author nathalie.steinmetz@deri.org
40 * @version $Revision: 1839 $ $Date: 2006-10-05 16:09:28 +0300 (Thu, 05 Oct 2006) $
41 */
42 public class ValidatorFileTests extends ValidatorTestCase {
43
44 /**
45 * This test submits a valid wsml-core file to the validator and asserts
46 * that the validator recognizes the file as valid.
47 */
48 public void testValidCoreModel()throws Exception {
49 // read test file and parse it
50 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
51 "test/wsmo4j/validator/valid_wsml_core_test.wsml");
52 assertNotNull(is);
53 // assuming first topentity in file is an ontology
54 ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];
55
56 WsmlValidator w = Factory.createWsmlValidator(null);
57 boolean b = w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml-core", errors, warnings);
58 // printWarning(warnings);
59 // printError(errors);
60 assertTrue(b);
61 }
62
63 /**
64 * This test submits a valid wsml-core file to the validator and asserts
65 * that the validator recognizes the file as valid. This wsml-core test file
66 * only contains the conceptual part and no axioms.
67 */
68 public void testValidConceptModel()throws Exception {
69 // read test file and parse it
70 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
71 "test/wsmo4j/validator/valid_wsml_core_conceptual_test.wsml");
72 assertNotNull(is);
73 // assuming first topentity in file is an ontology
74 ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];
75
76 WsmlValidator w = Factory.createWsmlValidator(null);
77 boolean b = w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml-core", errors, warnings);
78 // printWarning(warnings);
79 // printError(errors);
80 assertTrue(b);
81 }
82
83 /**
84 * This test submits an invalid wsml-core file to the validator. It gives out
85 * the received error messages and asserts that the validator recognizes the
86 * file as invalid. This wsml-core test file only contains the conceptual part
87 * and no axioms.
88 */
89 public void testInvalidConceptModel() throws Exception {
90 // read test file and parse it
91 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
92 "test/wsmo4j/validator/invalid_wsml_core_conceptual_test.wsml");
93 assertNotNull(is);
94 // assuming first topentity in file is an ontology
95 ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];
96
97 WsmlValidator w = Factory.createWsmlValidator(null);
98 boolean b = w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml-core", errors, warnings);
99 // printWarning(warnings);
100 // printError(errors);
101 assertFalse(b);
102 }
103
104 /**
105 * This test submits an invalid wsml-core file to the validator. It gives out
106 * the received error messages and asserts that the validator recognizes the
107 * file as invalid. The given wsml-core test file only contains errors in the
108 * axioms.
109 */
110 public void testInvalidCoreModel()throws Exception {
111 // read test file and parse it
112 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
113 "test/wsmo4j/validator/invalid_wsml_core_test.wsml");
114 assertNotNull(is);
115 // assuming first topentity in file is an ontology
116 ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];
117
118 WsmlValidator w = Factory.createWsmlValidator(null);
119 boolean b = w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml-core", errors, warnings);
120 // printWarning(warnings);
121 // printError(errors);
122 assertFalse(b);
123 }
124
125 /**
126 * This test submits a valid wsml-dl file to the validator and asserts
127 * that the validator recognizes the file as valid.
128 */
129 public void testValidDLModel()throws Exception {
130 // read test file and parse it
131 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
132 "test/wsmo4j/validator/valid_wsml_dl_test.wsml");
133 assertNotNull(is);
134 // assuming first topentity in file is an ontology
135 ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];
136
137 WsmlValidator w = Factory.createWsmlValidator(null);
138 boolean b = w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml-dl", errors, warnings);
139 // printWarning(warnings);
140 // printError(errors);
141 assertTrue(b);
142 }
143
144 /**
145 * This test submits a valid wsml-flight file to the validator and asserts
146 * that the validator recognizes the file as valid.
147 */
148 public void testFlightModel()throws Exception {
149 // read test file and parse it
150 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
151 "test/wsmo4j/validator/valid_wsml_flight_test.wsml");
152 assertNotNull(is);
153 // assuming first topentity in file is an ontology
154 ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];
155 WsmlValidator w = Factory.createWsmlValidator(null);
156 boolean b = w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml-flight", errors, warnings);
157 // printWarning(warnings);
158 // printError(errors);
159 assertTrue(b);
160 }
161
162 /**
163 * This test submits an invalid wsml-flight file to the validator. It gives out
164 * the received error messages and asserts that the validator recognizes the
165 * file as invalid. The given wsml-flight test file only contains errors in the
166 * axioms.
167 */
168 public void testInvalidFlightModel()throws Exception {
169 // read test file and parse it
170 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
171 "test/wsmo4j/validator/invalid_wsml_flight_test.wsml");
172 assertNotNull(is);
173 // assuming first topentity in file is an ontology
174 ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];
175
176 WsmlValidator w = Factory.createWsmlValidator(null);
177 boolean b = w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml-flight", errors, warnings);
178 // printWarning(warnings);
179 // printError(errors);
180 assertFalse(b);
181 }
182
183 /**
184 * This test submits a valid wsml-rule file to the validator and asserts
185 * that the validator recognizes the file as valid.
186 */
187 public void testRuleModel()throws Exception {
188 // read test file and parse it
189 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
190 "test/wsmo4j/validator/valid_wsml_rule_test.wsml");
191 assertNotNull(is);
192 // assuming first topentity in file is an ontology
193 ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];
194
195 WsmlValidator w = Factory.createWsmlValidator(null);
196 boolean b = w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml-rule", errors, warnings);
197 // printWarning(warnings);
198 // printError(errors);
199 assertTrue(b);
200 }
201
202 /**
203 * This test submits an invalid wsml-rule file to the validator. It gives out
204 * the received error messages and asserts that the validator recognizes the
205 * file as invalid. The given wsml-rule test file only contains errors in the
206 * axioms.
207 */
208 public void testInvalidRuleModel()throws Exception {
209 // read test file and parse it
210 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
211 "test/wsmo4j/validator/invalid_wsml_rule_test.wsml");
212 assertNotNull(is);
213 // assuming first topentity in file is an ontology
214 ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];
215
216 WsmlValidator w = Factory.createWsmlValidator(null);
217 boolean b = w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml-rule", errors, warnings);
218 // printWarning(warnings);
219 // printError(errors);
220 assertFalse(b);
221 }
222
223 }
224
225 /*
226 *$Log$
227 *Revision 1.2 2006/10/05 13:09:28 nathaliest
228 *fixed metamodelling bug
229 *
230 *Revision 1.1 2005/12/19 11:23:01 nathaliest
231 *restructured validator tests
232 *
233 */