1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package test.wsmo4j.locator;
19
20 import java.io.InputStream;
21 import java.io.InputStreamReader;
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.Set;
26
27 import org.omwg.ontology.Ontology;
28 import org.wsmo.common.exception.SynchronisationException;
29 import org.wsmo.factory.Factory;
30 import org.wsmo.locator.Locator;
31 import org.wsmo.locator.LocatorManager;
32 import org.wsmo.wsml.Parser;
33
34 import test.wsmo4j.Wsmo4jTestCase;
35 import static test.wsmo4j.Utils.*
36 ;
37
38
39
40
41
42
43
44
45
46
47
48 public class LocatorImplTest extends Wsmo4jTestCase {
49
50 Parser wsmlParser = null;
51
52 protected void setUp() throws Exception {
53 wsmlParser = Factory.createParser(null);
54 }
55
56
57
58
59
60
61
62 public void testImportOntologies()throws Exception {
63
64 InputStream is = this.getClass().getClassLoader().getResourceAsStream(
65 "test/wsmo4j/locator/importsOntology.wsml");
66 assertNotNull(is);
67
68 Ontology ontology = (Ontology)wsmlParser.parse(new InputStreamReader(is))[0];
69
70
71
72
73
74 HashMap <String, String> mapping = new HashMap <String, String>();
75 mapping.put("http://www.example.org/ontologies/example7",
76 getResource("test/wsmo4j/validator/valid_wsml_flight_test.wsml").toString());
77
78 HashMap <String, Object> prefs = new HashMap <String, Object> ();
79 prefs.put(Locator.URI_MAPPING, mapping);
80 prefs.put(Factory.PROVIDER_CLASS, "org.deri.wsmo4j.locator.LocatorImpl");
81
82 Locator locator = LocatorManager.createLocator(prefs);
83 Factory.getLocatorManager().addLocator(locator);
84
85 Set <Ontology> ontologies = new HashSet <Ontology> ();
86
87 if (ontology.listOntologies().size() > 0) {
88 for (Iterator it = ontology.listOntologies().iterator(); it.hasNext();){
89 Ontology ont = (Ontology) it.next();
90 try {
91 ont.getWsmlVariant();
92 if (ont != null) {
93 ontologies.add(ont);
94 }
95 } catch (SynchronisationException e) {}
96 }
97 }
98
99 for (Iterator it = ontologies.iterator(); it.hasNext();) {
100 Ontology ont = (Ontology) it.next();
101 if (ont != null) {
102 System.out.println("Successfully imported ontology: "
103 + ont.getIdentifier().toString());
104 System.out.println("The ontology contains " +
105 ont.listConcepts().size() + " concepts, " +
106 ont.listInstances().size() + " instances, " +
107 ont.listRelations().size() + " relations and " +
108 ont.listAxioms().size() + " axioms.");
109 }
110 }
111 Factory.getLocatorManager().removeLocator(locator);
112 }
113
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130