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  import java.util.HashMap;
23  
24  import org.omwg.ontology.Ontology;
25  import org.wsmo.factory.Factory;
26  import org.wsmo.locator.Locator;
27  import org.wsmo.locator.LocatorManager;
28  import org.wsmo.validator.ValidationError;
29  import org.wsmo.validator.WsmlValidator;
30  
31  /**
32   * Checks if imported WSML files are validated correctly. 
33   * 
34   * <pre>
35   * Created on Aug 21, 2006
36   * Committed by $Author: nathaliest $
37   * $Source$,
38   * </pre>
39   * 
40   * @author nathalie.steinmetz@deri.org
41   * @version $Revision: 1962 $ $Date: 2007-04-23 18:01:05 +0300 (Mon, 23 Apr 2007) $
42   */
43  public class ValidateImportsTests extends ValidatorTestCase {
44  
45  	/**
46       * This test submits a valid wsml-rule file to the validator and asserts
47       * that the validator recognizes the file as valid. This wsml-core test file
48       * only contains the conceptual part and no axioms.
49       */
50  	public void testValidateImportedOntologies()throws Exception {
51          // read test file and parse it 
52          InputStream is = this.getClass().getClassLoader().getResourceAsStream(
53                  "test/wsmo4j/validator/importsOntology.wsml");
54          assertNotNull(is);
55          // assuming first topentity in file is an ontology  
56          ontology = (Ontology)parser.parse(new InputStreamReader(is))[0];  
57          // This map contains a mapping from locigal URIs to physical locations. 
58          // The physical address in this map needs to be changed with respect to 
59          // the real physical location on a test computer
60          HashMap mapping = new HashMap();
61  //        mapping.put("http://www.example.org/ontologies/example8", 
62  //				"file:/C:/Dokumente und Einstellungen/natste/Eigene Dateien/" +
63  //				"Eigene Dokumente/eclipse workspace/wsmo4j/test/test/wsmo4j/" +
64  //				"validator/valid_wsml_rule_test.wsml");
65  //        mapping.put("http://www.example.org/ontologies/example3", 
66  //				"file:/C:/Dokumente und Einstellungen/natste/Eigene Dateien/" +
67  //				"Eigene Dokumente/eclipse workspace/wsmo4j/test/test/wsmo4j/" +
68  //				"validator/invalid_wsml_flight_test.wsml");
69  		HashMap <String, Object> prefs = new HashMap <String, Object> ();
70  		prefs.put(Locator.URI_MAPPING, mapping);
71  		prefs.put(Factory.PROVIDER_CLASS, "org.deri.wsmo4j.locator.LocatorImpl");
72  		Locator locator = LocatorManager.createLocator(prefs);
73  		Factory.getLocatorManager().addLocator(locator);
74  		   
75  		prefs.clear();
76  		prefs.put(WsmlValidator.VALIDATE_IMPORTS, new Boolean(true));
77          WsmlValidator w = Factory.createWsmlValidator(prefs);
78          boolean b = w.isValid(ontology, errors, warnings); 
79  //        printWarning(warnings);
80          ValidationError ve = errors.firstElement();
81  //        printError(errors);
82          Factory.getLocatorManager().removeLocator(locator);
83          assertFalse(b);
84          assertTrue(ve.getReason().startsWith(ValidationError.IMPORT_ERR));
85      }
86  	
87  }
88  /*
89   * $Log$
90   * Revision 1.7  2007/04/23 15:01:05  nathaliest
91   * fixed small bug in dl validation
92   *
93   * Revision 1.6  2007/04/02 12:13:23  morcen
94   * Generics support added to wsmo-api, wsmo4j and wsmo-test
95   *
96   * Revision 1.5  2006/11/27 11:37:14  nathaliest
97   * *** empty log message ***
98   *
99   * Revision 1.4  2006/09/28 13:11:34  nathaliest
100  * added utility method to geet root variable of valid WSML-DL formula and added corresponding tests
101  *
102  * Revision 1.3  2006/08/29 15:19:48  nathaliest
103  * changed the validator to call the memory based locator manager and fixed a problem causing loops at the location of ontologies in the validator
104  *
105  * Revision 1.2  2006/08/22 16:29:38  nathaliest
106  * *** empty log message ***
107  *
108  * Revision 1.1  2006/08/22 16:27:25  nathaliest
109  * added tests for the validation of imported ontologies
110  *
111  * 
112  */
113