1   /*
2   wsmo4j - a WSMO API and Reference Implementation
3   
4   Copyright (c) 2004-2005 , OntoText Lab. / SIRMA
5                             University of Innsbruck, Austria  
6   
7   This library is free software; you can redistribute it and/or modify it under
8   the terms of the GNU Lesser General Public License as published by the Free
9   Software Foundation; either version 2.1 of the License, or (at your option)
10  any later version.
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  details.
15  You should have received a copy of the GNU Lesser General Public License along
16  with this library; if not, write to the Free Software Foundation, Inc.,
17  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19  
20  /**
21   * <p>Title: WSMO4J</p>
22   * <p>Description: WSMO API and a Reference Implementation</p>
23   * <p>Copyright:  Copyright (c) 2004</p>
24   * <p>Company: OntoText Lab. / SIRMA </p>
25   * @author not attributable
26   * @version 1.0
27   *
28   */
29  
30  package test.wsmo4j.locator;
31  
32  import java.util.*;
33  
34  import org.omwg.ontology.*;
35  import org.wsmo.common.*;
36  import org.wsmo.common.exception.*;
37  import org.wsmo.factory.*;
38  import org.wsmo.locator.*;
39  
40  import com.ontotext.wsmo4j.parser.*;
41  
42  import test.wsmo4j.*;
43  
44  public class LocatorTest extends Wsmo4jTestCase {
45      
46      private final static String PREFIX = "http://importedOntology#"; 
47      
48      public void setUp() throws Exception {
49          super.setUp();
50          Locator locator = new BogusLocator();
51          Factory.getLocatorManager().addLocator(locator);
52      }
53      
54      public void testLocator() throws Exception {
55          Concept c = factory.getConcept(factory.createIRI(PREFIX + "concept"));
56          
57          // verify the created concept has a NFP property added by BogusLocator
58          Set s = c.listNFPValues(factory.createIRI("http://locator#addedBy"));
59          assertTrue(s.contains(dataFactory.createWsmlString("Located by BogusLocator")));
60          
61          // verify if the created entity by the BogusLocator is registered in the EntityRegistry
62          assertEquals(factory.createConcept(factory.createIRI(PREFIX + "concept")), c);
63          assertEquals(factory.getConcept(factory.createIRI(PREFIX + "concept")), c);
64      }
65      
66      public class BogusLocator implements Locator {
67          
68          public Set <Entity> lookup(Identifier id) throws SynchronisationException {
69              throw new UnsupportedOperationException();
70          }
71          
72          public Entity lookup(Identifier id, Class clazz) throws SynchronisationException {
73              if (id.toString().startsWith(PREFIX) 
74                      && clazz == Concept.class) {
75                  Concept c = factory.createConcept(id);
76                  
77                  try {
78                      c.addNFPValue(factory.createIRI("http://locator#addedBy"), 
79                          dataFactory.createWsmlString("Located by BogusLocator"));
80                      return c;
81                  }
82                  catch (InvalidModelException e) {
83                      throw new WrappedInvalidModelException(e);
84                  }
85              }
86              return null;
87          }
88      }
89  }
90  
91  /*
92   * $Log$
93   * Revision 1.2  2007/04/02 12:13:22  morcen
94   * Generics support added to wsmo-api, wsmo4j and wsmo-test
95   *
96   * Revision 1.1  2006/01/03 12:15:14  vassil_momtchev
97   * locator test
98   *
99  */