1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package test.wsmo4j.factory;
21
22
23
24
25
26
27
28
29
30
31 import java.net.URI;
32
33 import org.omwg.ontology.*;
34 import org.wsmo.common.*;
35 import org.wsmo.common.exception.InvalidModelException;
36 import org.wsmo.mediator.*;
37 import org.wsmo.service.*;
38
39 import test.wsmo4j.Wsmo4jTestCase;
40
41 public class WSMOFactoryTest extends Wsmo4jTestCase {
42
43 private String ns = "http://example.org/";
44
45 public void testMetaModeling() {
46 IRI iri = factory.createIRI(ns+"duplicatedIRI");
47 WebService ws = factory.getWebService(iri);
48 Ontology ont = null;
49
50 try {
51 ont = factory.getOntology(iri);
52 fail();
53 }
54 catch (Exception e) {
55 }
56
57 IRI iri2 = factory.createIRI(ns+"duplicatedIRI2");
58 ws = factory.createWebService(iri2);
59
60 try {
61 ont = factory.createOntology(iri2);
62 fail();
63 }
64 catch (Exception e) {
65 }
66 }
67
68 public void testCreateAnonymousID() {
69 UnnumberedAnonymousID id = factory.createAnonymousID();
70 assertNotNull(id);
71
72
73 UnnumberedAnonymousID anotherID = factory.createAnonymousID();
74 assertFalse("Bad equals()", id.equals(anotherID));
75 }
76
77 public void testCreateAxiom() throws InvalidModelException{
78 IRI axiomID = factory.createIRI(ns+"testAxiom");
79
80 Axiom result = factory.createAxiom(axiomID);
81 assertNotNull("Unable to create Axiom!", result);
82 assertEquals("return value", result.getIdentifier(), axiomID);
83
84 IRI anotherAxiomID = factory.createIRI(ns+"testAxiom(1)");
85 Axiom neqAxiom = factory.createAxiom(anotherAxiomID);
86 Axiom eqAxiom = factory.createAxiom(axiomID);
87
88 assertSame("Bad axiom - should be identical", result, eqAxiom);
89 assertFalse("Bad equals()", result.equals(neqAxiom));
90
91 boolean check = false;
92 try {
93 factory.createAxiom(null);
94 }
95 catch (IllegalArgumentException iae) {
96 check = true;
97 }
98 assertTrue("preconditions not checked!", check);
99 }
100
101 public void testCreateCapability() {
102 IRI capID = factory.createIRI(ns+"testCapability");
103
104 Capability result = factory.createCapability(capID);
105 assertNotNull("Unable to create Capability!", result);
106 assertEquals("return value", result.getIdentifier(), capID);
107
108 IRI anotherCapID = factory.createIRI(ns+"testCapability(1)");
109 Capability neqCap = factory.createCapability(anotherCapID);
110 Capability eqCap = factory.createCapability(capID);
111
112 assertSame("Bad capability - should be identical", result, eqCap);
113 assertFalse("Bad equals()", result.equals(neqCap));
114
115 boolean check = false;
116 try {
117 factory.createCapability(null);
118 }
119 catch (IllegalArgumentException iae) {
120 check = true;
121 }
122 assertTrue("preconditions not checked!", check);
123
124 }
125
126 public void testCreateConcept() throws InvalidModelException {
127
128 IRI ontURI = factory.createIRI(ns+"testCreateConcept#ontology01");
129 Ontology owner = factory.createOntology(ontURI);
130
131 IRI conceptID = factory
132 .createIRI(ns+"testCreateConcept#concept01");
133 Concept result = factory.createConcept(conceptID);
134 owner.addConcept(result);
135
136 assertEquals("return value", result.getIdentifier(), conceptID);
137 assertEquals(result.getOntology(), owner);
138 assertEquals(owner.findConcept(conceptID), result);
139
140 IRI anotherConceptID = factory.createIRI(ns+"testConcept(1)");
141 Concept neqConcept = factory.createConcept(anotherConceptID);
142 Concept eqConcept = factory.createConcept(conceptID);
143
144 assertSame("Bad concept - should be identical", result, eqConcept);
145 assertFalse("Bad equals()", result.equals(neqConcept));
146
147
148 boolean check1 = false;
149 try {
150 factory.createConcept(null);
151 }
152 catch (IllegalArgumentException ex) {
153 check1 = true;
154 }
155
156 assertTrue("preconditions not checked!",
157 true == check1);
158 }
159
160
161 public void testCreateGGMediator() {
162 IRI medID = factory.createIRI(ns+"testGGMediator");
163
164 GGMediator result = factory.createGGMediator(medID);
165 assertNotNull("Unable to create mediator!", result);
166 assertEquals("return value", result.getIdentifier(), medID);
167
168 IRI anotherMedID = factory.createIRI(ns+"testGGMediator(2)");
169 GGMediator neqMed = factory.createGGMediator(anotherMedID);
170 GGMediator eqMed = factory.createGGMediator(medID);
171
172 assertSame("Bad GGMediator - should be identical", result, eqMed);
173 assertFalse("Bad equals()", result.equals(neqMed));
174
175 boolean check = false;
176 try {
177 factory.createGGMediator(null);
178 }
179 catch (IllegalArgumentException iae) {
180 check = true;
181 }
182 assertTrue("preconditions not checked!", check);
183 }
184
185 public void testCreateGoal() {
186 IRI goalID = factory.createIRI(ns+"testGoal");
187
188 Goal result = factory.createGoal(goalID);
189 assertNotNull("Unable to create goal!", result);
190 assertEquals("return value", result.getIdentifier(), goalID);
191
192 IRI anotherGoalID = factory.createIRI(ns+"testGoal1");
193 assertTrue(factory.createGoal(goalID).equals(result));
194 assertFalse(factory.createGoal(anotherGoalID).equals(result));
195
196 boolean check = false;
197 try {
198 factory.createGoal(null);
199 }
200 catch (IllegalArgumentException iae) {
201 check = true;
202 }
203 assertTrue("preconditions not checked!", check);
204 }
205
206 public void testCreateInstance() throws InvalidModelException {
207
208
209 IRI ontURI = factory
210 .createIRI(ns+"testCreateInstance#ontology01");
211 Ontology owner = factory.createOntology(ontURI);
212
213 IRI conceptID = factory
214 .createIRI(ns+"testCreateInstance#concept01");
215 Concept concept = factory.createConcept(conceptID);
216 owner.addConcept(concept);
217
218 IRI instanceID = factory
219 .createIRI(ns+"testCreateInstance#instance01");
220 Instance result = factory.createInstance(instanceID, concept);
221 owner.addInstance(result);
222
223 assertEquals("return value", result.getIdentifier(), instanceID);
224 assertEquals(result.getOntology(), owner);
225 assertEquals(result.listConcepts().iterator().next(), concept);
226 assertEquals(owner.findInstance(instanceID), result);
227
228 IRI anotherInstID = factory.createIRI(ns+"testCreateInstance#instance1.2");
229 Instance neqInst = factory.createInstance(anotherInstID);
230 Instance eqInst = factory.createInstance(instanceID);
231
232 assertSame("Bad Instance - should be identical", result, eqInst);
233 assertFalse("Bad equals()", result.equals(neqInst));
234
235
236 IRI yetAnotherInstID = factory.createIRI(ns+"testCreateInstance#instance2.2");
237 Instance neqInst2 = factory.createInstance(yetAnotherInstID);
238 Instance eqInst2 = factory.createInstance(instanceID);
239
240 assertSame("Bad Instance - should be identical", result, eqInst2);
241 assertFalse("Bad equals()", result.equals(neqInst2));
242
243 assertFalse("Bad equals()", result.equals(neqInst));
244
245
246 boolean check2 = false;
247
248 try {
249 factory.createInstance(null);
250 }
251 catch (IllegalArgumentException ex) {
252 check2 = true;
253 }
254 assertTrue("precondition not checked",check2);
255
256 }
257
258 public void testCreateInterface() {
259 IRI interfaceID = factory.createIRI(ns+ns+"testInterface");
260 Interface result = factory.createInterface(interfaceID);
261 assertNotNull("Unable to create Interface!", result);
262 assertEquals("Unable to create Interface!", result.getIdentifier(),
263 interfaceID);
264
265 IRI anotherInterfaceID = factory.createIRI(ns+"testInterface(1)");
266 Interface neqInterface = factory.createInterface(anotherInterfaceID);
267 Interface eqInterface = factory.createInterface(interfaceID);
268
269 assertSame("Bad Interface - should be identical", result, eqInterface);
270 assertFalse("Bad equals()", result.equals(neqInterface));
271
272 boolean check = false;
273 try {
274 factory.createInterface(null);
275 }
276 catch (IllegalArgumentException iae) {
277 check = true;
278 }
279 assertTrue("preconditions not checked!", check);
280 }
281
282 public void testCreateOOMediator() {
283 IRI medID = factory.createIRI(ns+"testOOMediator");
284
285 OOMediator result = factory.createOOMediator(medID);
286 assertEquals("return value", result.getIdentifier(), medID);
287
288 IRI anotherMedID = factory.createIRI(ns+"testOOMediator(1)");
289 OOMediator neqOOMediator = factory.createOOMediator(anotherMedID);
290 OOMediator eqOOMediator = factory.createOOMediator(medID);
291
292 assertSame("Bad OOMediator - should be identical", result, eqOOMediator);
293 assertFalse("Bad equals()", result.equals(neqOOMediator));
294
295 boolean check = false;
296 try {
297 factory.createOOMediator(null);
298 }
299 catch (IllegalArgumentException iae) {
300 check = true;
301 }
302 assertTrue("preconditions not checked!", check);
303
304 }
305
306 public void testCreateOntology() {
307 IRI ontoID = factory.createIRI(ns+"testOntology");
308
309 Ontology result = factory.createOntology(ontoID);
310 assertNotNull("Failed to create ontology", result);
311 assertEquals("invalid ontology", result.getIdentifier(), ontoID);
312
313 IRI anotherOntoID = factory.createIRI(ns+"testOntology(1)");
314 Ontology neqOntology = factory.createOntology(anotherOntoID);
315 Ontology eqOntology = factory.createOntology(ontoID);
316
317 assertSame("Bad Ontology - should be identical", result, eqOntology);
318 assertFalse("Bad equals()", result.equals(neqOntology));
319
320 boolean check = false;
321 try {
322 factory.createOntology(null);
323 }
324 catch (IllegalArgumentException iae) {
325 check = true;
326 }
327 assertTrue("preconditions not checked!", check);
328 }
329
330
331 public void testCreateRelation() throws InvalidModelException {
332 IRI relationID = factory
333 .createIRI(ns+"testCreateConcept#relation01");
334 Relation result = factory.createRelation(relationID);
335
336 assertNotNull("Failed to create Relation", result);
337 assertEquals("return value", result.getIdentifier(), relationID);
338
339 IRI anotherRelID = factory.createIRI(ns+"testCreateConcept#relation02");
340 Relation neqRelation = factory.createRelation(anotherRelID);
341 Relation eqRelation = factory.createRelation(relationID);
342
343 assertSame("Bad Relation - should be identical", result, eqRelation);
344 assertFalse("Bad equals()", result.equals(neqRelation));
345
346 }
347
348 public void testCreateRelationInstance() throws InvalidModelException {
349 IRI relationID = factory
350 .createIRI(ns+"testCreateConcept#relation01");
351 Relation relation = factory.createRelation(relationID);
352
353 IRI relInstID = factory
354 .createIRI(ns+"testCreateConcept#rel_inst01");
355 RelationInstance result = factory.createRelationInstance(relInstID, relation);
356
357 assertNotNull("Failed to create Relation Instance", result);
358 assertEquals("return value", result.getIdentifier(), relInstID);
359 assertEquals("Invalid instanceOf", result.getRelation(), relation);
360
361 IRI anotherRelInstID = factory.createIRI(ns+"testCreateConcept#rel_inst02");
362 RelationInstance neqRelInst = factory.createRelationInstance(anotherRelInstID, relation);
363 RelationInstance eqRelInst = factory.createRelationInstance(relInstID, relation);
364
365 assertSame("Bad RelationInstance - should be identical", result, eqRelInst);
366 assertFalse("Bad equals()", result.equals(neqRelInst));
367
368
369 boolean check1 = false;
370
371 try {
372 Identifier anotherID = factory.createAnonymousID();
373 factory.createRelationInstance(anotherID, null);
374 }
375 catch (InvalidModelException ex) {
376 check1 = true;
377 }
378 assertTrue("no relation instance without relation",check1);
379 }
380
381 public void testCreateIRI() throws Exception {
382
383 URI uri = new URI("http://wsmo4j.sourceforge.net/");
384
385 IRI result = factory.createIRI(uri.toString());
386 assertNotNull("Failed to create IRI", result);
387 assertEquals("return value", uri.toString(), result.toString());
388
389 boolean check = false;
390 try {
391 factory.createIRI(null);
392 }
393 catch (IllegalArgumentException iae) {
394 check = true;
395 }
396 assertTrue("preconditions not checked!", check);
397 }
398
399
400 public void testCreateWGMediator() {
401 IRI medID = factory.createIRI(ns+"testWGMediator");
402
403 WGMediator result = factory.createWGMediator(medID);
404 assertNotNull("failed to create mediator", result);
405 assertEquals("return value", result.getIdentifier(), medID);
406
407 boolean check = false;
408 try {
409 factory.createWGMediator(null);
410 }
411 catch (IllegalArgumentException iae) {
412 check = true;
413 }
414 assertTrue("preconditions not checked!", check);
415 }
416
417 public void testCreateWWMediator() {
418 IRI medID = factory.createIRI(ns+"testWWMediator");
419
420 WWMediator result = factory.createWWMediator(medID);
421 assertNotNull("failed to create mediator", result);
422 assertEquals("return value", result.getIdentifier(), medID);
423
424 boolean check = false;
425 try {
426 factory.createWWMediator(null);
427 }
428 catch (IllegalArgumentException iae) {
429 check = true;
430 }
431 assertTrue("preconditions not checked!", check);
432 }
433
434 public void testCreateWebService() {
435 IRI wsID = factory.createIRI(ns+"testWebService");
436
437 WebService result = factory.createWebService(wsID);
438 assertNotNull("Failed to create WS!", result);
439 assertEquals("return value", result.getIdentifier(), wsID);
440
441 boolean check = false;
442 try {
443 factory.createWebService(null);
444 }
445 catch (IllegalArgumentException iae) {
446 check = true;
447 }
448 assertTrue("preconditions not checked!", check);
449 }
450 }
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513