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.deri.wsmo4j.common.ClearTopEntity;
24  import org.omwg.logicalexpression.LogicalExpression;
25  import org.omwg.ontology.Ontology;
26  import org.wsmo.common.WSML;
27  import org.wsmo.factory.Factory;
28  import org.wsmo.validator.WsmlValidator;
29  
30  /**
31   * General validator tests
32   * 
33   * @author nathalie.steinmetz@deri.org
34   * @author holger.lausen@deri.org
35   */
36  public class VariantsTest extends ValidatorTestCase {
37  
38      /**
39       * Checks if the indicated variant is a valid variant.
40       */
41      public void testWrongVariant(){
42          WsmlValidator w = Factory.createWsmlValidator(null);
43          try {
44              w.isValid(ontology, "http://www.wsmo.org/wsml/wsml-syntax/wsml", errors, warnings);
45              fail("Should fail because the specified variant is invalid!");
46          } catch (IllegalArgumentException iae){iae.getMessage();} 
47      }
48       
49      /**
50       * Checks if the validator determines the right variant. 
51       */
52      public void testDetermineRightVariant() throws Exception {
53          // read test file and parse it 
54          InputStream is = this.getClass().getClassLoader().getResourceAsStream(
55                  "test/wsmo4j/validator/valid_wsml_rule_test.wsml");
56          assertNotNull(is);
57          // assuming first topentity in file is an ontology  
58          ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];  
59  
60          WsmlValidator w = Factory.createWsmlValidator(null);
61          String variant = w.determineVariant(ontology, errors, warnings); 
62  //        printWarning(warnings);
63  //        printError(errors);
64          assertEquals(variant, "http://www.wsmo.org/wsml/wsml-syntax/wsml-rule");
65          assertNotSame(variant, "http://www.wsmo.org/wsml/wsml-syntax/wsml-flight");
66      }
67      
68      public void testMetaModeling() throws Exception{
69          WsmlValidator w = Factory.createWsmlValidator(null);
70  
71          String test = "concept human " +
72          		"  hasChild impliesType human " +
73          		"instance human ";
74          ontology = (Ontology)parser.parse(new StringBuffer(getOntHeader()+test))[0];  
75          ontology.setWsmlVariant(WSML.WSML_CORE);
76          w.isValid(ontology, errors, warnings);
77  //        printError(errors);
78          assertTrue(errors.size()>0);
79          
80          errors.clear();
81          ClearTopEntity.clearTopEntity(ontology);
82          
83          test = "concept human " +
84  				"  hasChild impliesType human " +
85  				"instance Mary " + 
86  				"  hasChild hasValue human";
87          ontology = (Ontology)parser.parse(new StringBuffer(getOntHeader()+test))[0];  
88          ontology.setWsmlVariant(WSML.WSML_CORE);
89          w.isValid(ontology, errors, warnings);
90  //        printError(errors);
91          assertTrue(errors.size()>0);
92  
93          errors.clear();
94          ClearTopEntity.clearTopEntity(ontology);
95          
96          test = "instance Mary " +
97  			"  Mary hasValue John ";
98          ontology = (Ontology)parser.parse(new StringBuffer(getOntHeader()+test))[0];  
99          ontology.setWsmlVariant(WSML.WSML_CORE);
100         w.isValid(ontology, errors, warnings);
101 //        printError(errors);
102         assertTrue(errors.size()>0);
103 
104         errors.clear();
105         ClearTopEntity.clearTopEntity(ontology);
106         
107         //String 
108         test = "concept human " +
109                 "  relative impliesType marge " +
110                 "instance marge ";
111         ontology = (Ontology)parser.parse(new StringBuffer(getOntHeader()+test))[0];  
112         ontology.setWsmlVariant(WSML.WSML_CORE);
113         w.isValid(ontology, errors, warnings);
114 //        printError(errors);
115         assertTrue(errors.size()>0);
116         
117         errors.clear();
118         ClearTopEntity.clearTopEntity(ontology);
119         
120         test = "instance foo " +
121         	"  relative hasValue marge " +
122         	"  concept marge ";
123         ontology = (Ontology)parser.parse(new StringBuffer(getOntHeader()+test))[0];  
124         ontology.setWsmlVariant(WSML.WSML_CORE);
125         w.isValid(ontology, errors, warnings);
126 //        printError(errors);
127         assertTrue(errors.size()>0);
128         
129         errors.clear();
130         ClearTopEntity.clearTopEntity(ontology);
131         
132         test = "axiom definedBy human[relative impliesType marge]. marge memberOf human. ";
133         ontology = (Ontology)parser.parse(new StringBuffer(getOntHeader()+test))[0];  
134         ontology.setWsmlVariant(WSML.WSML_CORE);
135         w.isValid(ontology, errors, warnings);
136 //        printError(errors);
137         assertTrue(errors.size()>0);
138         
139         errors.clear();
140         ClearTopEntity.clearTopEntity(ontology);
141         
142         test = "relation distance(impliesType test, impliesType test) instance test ";
143         ontology = (Ontology)parser.parse(new StringBuffer(getOntHeader()+test))[0];  
144         ontology.setWsmlVariant(WSML.WSML_CORE);
145         w.isValid(ontology, errors, warnings);
146 //        printError(errors);
147         assertTrue(errors.size()>0);
148         
149         errors.clear();
150         
151         // metamodelling check for singe logical expression
152         LogicalExpression logExpr = leFactory.createLogicalExpression(
153 				"_\"http://ex.org#Human\" memberOf _\"http://ex.org#Human\".  ");
154 		w.isValid(logExpr, WSML.WSML_DL, errors, warnings);
155 //		printError(errors);
156         assertTrue(errors.size()>0);
157     }
158     
159 }