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 org.omwg.ontology.Concept;
21  import org.wsmo.common.IRI;
22  import org.wsmo.common.TopEntity;
23  import org.wsmo.common.WSML;
24  import org.wsmo.factory.Factory;
25  import org.wsmo.validator.WsmlValidator;
26  
27  /**
28   * Different error types are tested via constructed invalid 
29   * ontology element definitions.
30   * 
31   * <pre>
32   * Created on Dec 19, 2005
33   * Committed by $Author: nathaliest $
34   * $Source$,
35   * </pre>
36   * 
37   * @author nathalie.steinmetz@deri.org
38   * @version $Revision: 1840 $ $Date: 2006-10-05 19:23:39 +0300 (Thu, 05 Oct 2006) $
39   */
40  public class ValidatorConceptualTests extends ValidatorTestCase {
41  
42  	/* Full Conceptual Tests */
43  	
44  	/**
45  	 * This tests checks if attribute features are allowed on attributes with 
46  	 * a datatype on their range.
47  	 */
48  	public void testAttributeFeatures() throws Exception {
49  		String test = getOntHeader() + 
50  				"concept a " +
51  				"  rel symmetric impliesType _integer ";
52  		TopEntity te = parser.parse(new StringBuffer(test))[0];
53  		WsmlValidator w = Factory.createWsmlValidator(null);
54  		boolean b = w.isValid(te, WSML.WSML_RULE, errors, warnings);
55  //		printWarning(warnings);
56  //		printError(errors);
57  		assertFalse(b);
58  		
59  		errors.clear();
60          warnings.clear();
61          test = getOntHeader() + 
62                  "concept a " +
63                  "  rel1 inverseOf(rel2) impliesType _string ";
64          te = parser.parse(new StringBuffer(test))[0];
65  		w = Factory.createWsmlValidator(null);
66  		b = w.isValid(te, WSML.WSML_FLIGHT, errors, warnings);
67  //		printWarning(warnings);
68  //		printError(errors);
69  		assertFalse(b);
70  	}
71  	
72      /* Core Conceptual Tests */
73      
74      /**
75       * This tests checks for ids, that are used for more than one single type.
76       */
77      public void testSameID() throws Exception{
78          String test = getOntHeader() +
79                  "concept c  subConceptOf Human\n" +
80                  "relation a/2 subRelationOf Human "; 
81          TopEntity te = parser.parse(new StringBuffer(test))[0];
82          WsmlValidator w = Factory.createWsmlValidator(null);
83          boolean b = w.isValid(te, WSML.WSML_CORE, errors, warnings);
84  //        printWarning(warnings);
85  //        printError(errors);
86          assertFalse(b);
87  
88          errors.clear();
89          warnings.clear();
90          test = getOntHeader() + 
91                  "concept a \n" +
92                  "instance a ";
93          te = parser.parse(new StringBuffer(test))[0];
94          b = w.isValid(te, WSML.WSML_CORE, errors, warnings); 
95  //        printWarning(warnings);
96  //        printError(errors);
97          assertFalse(b);
98  
99          errors.clear();
100         warnings.clear();
101         test = getOntHeader() + 
102                 "concept a \n" +
103                 "relation a/2 ";
104         te = parser.parse(new StringBuffer(test))[0];
105         b = w.isValid(te, WSML.WSML_CORE, errors, warnings); 
106 //        printWarning(warnings);
107 //        printError(errors);
108         assertFalse(b);
109 
110         errors.clear();
111         warnings.clear();
112         test = getOntHeader() + 
113                 "concept a \n" +
114                 " a ofType _date ";
115         te = parser.parse(new StringBuffer(test))[0];
116         b = w.isValid(te, WSML.WSML_CORE, errors, warnings); 
117 //        printWarning(warnings);
118 //        printError(errors);
119         assertFalse(b);
120     }
121     
122     /**
123      * This test checks for the validity of constraining attributes.
124      */
125     public void testConstrainingDataType() throws Exception{
126         WsmlValidator w = Factory.createWsmlValidator(null);
127         String test = getOntHeader() + 
128                 "concept a12 \n" +
129                 " at12 ofType _date ";
130         TopEntity te = parser.parse(new StringBuffer(test))[0];
131         boolean b = w.isValid(te, WSML.WSML_CORE, errors, warnings); 
132 //        printWarning(warnings);
133 //        printError(errors);
134         assertTrue(b);
135 
136         errors.clear();
137         warnings.clear();
138         test = getOntHeader() + 
139                 "concept c15 \n" +
140                 " att15 ofType beta ";
141         te = parser.parse(new StringBuffer(test))[0];
142         b = w.isValid(te, WSML.WSML_CORE, errors, warnings); 
143 //        printWarning(warnings);
144 //        printError(errors);
145         assertFalse(b);
146 
147         errors.clear();
148         warnings.clear();
149         test = getOntHeader() + 
150                 "axiom definedBy \n" +
151                 " c13[at13 ofType beta]. ";
152         te = parser.parse(new StringBuffer(test))[0];
153         b = w.isValid(te, WSML.WSML_CORE, errors, warnings); 
154 //        printWarning(warnings);
155 //        printError(errors);
156         assertFalse(b);
157 
158         System.gc();
159         errors.clear();
160         warnings.clear();
161         test = getOntHeader() + 
162                 "axiom definedBy \n" +
163                 " c145[at145 ofType _date]. ";
164         te = parser.parse(new StringBuffer(test))[0];
165         b = w.isValid(te, WSML.WSML_CORE, errors, warnings); 
166 //        printWarning(warnings);
167         printError(errors);
168         assertTrue(b);
169     }
170     
171     /* Full Conceptual Tests */
172     
173     /**
174      * Tests an attribute without a range.
175      */
176     public void testIncompleteAttribute() throws Exception{
177         IRI a = factory.createIRI(ns+"a");
178         IRI b = factory.createIRI(ns+"b");
179         Concept c = factory.createConcept(a);
180         c.createAttribute(b);
181         ontology.addConcept(c);
182         WsmlValidator w = Factory.createWsmlValidator(null);
183         boolean bool = w.isValid(ontology, errors, warnings);
184 //        printWarning(warnings);
185 //        printError(errors);
186         assertFalse(bool);
187     }
188     
189     /**
190      * Tests a relation with only some of the parameters defined.
191      */
192     public void testRelationDef() throws Exception{
193         String test = getOntHeader() +
194                 "relation a/3 \n" +
195                 "relation a(ofType b) ";
196         TopEntity te = parser.parse(new StringBuffer(test))[0];
197         WsmlValidator w = Factory.createWsmlValidator(null);
198         boolean b = w.isValid(te, errors, warnings);
199 //        printWarning(warnings);
200 //        printError(errors);
201         assertFalse(b);
202     }
203     
204 }
205 
206 /*
207  *$Log$
208  *Revision 1.5  2006/10/05 16:23:38  nathaliest
209  *added check for attribute features on attributes with a datatype at their range
210  *
211  *Revision 1.4  2006/03/23 16:04:09  nathaliest
212  *changed imports
213  *
214  *Revision 1.3  2006/03/21 10:36:43  nathaliest
215  **** empty log message ***
216  *
217  *Revision 1.2  2005/12/19 13:36:17  nathaliest
218  **** empty log message ***
219  *
220  *Revision 1.1  2005/12/19 11:23:01  nathaliest
221  *restructured validator tests
222  *
223  */
224