Parent: [97ae4a] (diff)

Child: [41b73e] (diff)

Download this file

OwlApiFacadeTest.java    844 lines (733 with data), 45.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
/**
* Copyright (c) 2013/2014 Verein zur Foerderung der IT-Sicherheit in Oesterreich (SBA).
* The work has been developed in the TIMBUS Project and the above-mentioned are Members of the TIMBUS Consortium.
* TIMBUS is supported by the European Union under the 7th Framework Programme for research and technological
* development and demonstration activities (FP7/2007-2013) under grant agreement no. 269940.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including without
* limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTIBITLY, or FITNESS FOR A PARTICULAR
* PURPOSE. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise,
* unless required by applicable law or agreed to in writing, shall any Contributor be liable for damages, including
* any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this
* License or out of the use or inability to use the Work.
* See the License for the specific language governing permissions and limitation under the License.
*/
package org.sbaresearch.owl;
import com.hp.hpl.jena.rdf.model.Model;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import net.sf.oval.exception.ConstraintsViolatedException;
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.vocab.OWL2Datatype;
import uk.ac.manchester.cs.owl.owlapi.OWL2DatatypeImpl;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URISyntaxException;
import java.util.*;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.*;
@RunWith(JUnitParamsRunner.class)
public class OwlApiFacadeTest {
@Test
public void testSetIRIMapping_unusedIRI_shouldNotAffectMissingImports() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.setIRIMapping(new HashMap<String, String>() {{
put("unused-import", "some-local-replacement");
}});
owlApi.load(TestUtils.getUri("/test_missing_import.owl"));
Set<OWLOntology> imports = owlApi.getOntology().getImports();
assertThat(imports.size(), is(0));
}
@Test
public void testSetIRIMapping_emptyMapping_shouldNotAffectMissingImports() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.setIRIMapping(new HashMap<String, String>());
owlApi.load(TestUtils.getUri("/test_missing_import.owl"));
Set<OWLOntology> imports = owlApi.getOntology().getImports();
assertThat(imports.size(), is(0));
}
@Test
public void testSetIRIMapping_usedIRI_shouldReplaceImports() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.setIRIMapping(new HashMap<String, String>() {{
put("http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-34", TestUtils.getUri("/test_ab1.owl"));
}});
owlApi.load(TestUtils.getUri("/test_missing_import.owl"));
Set<OWLOntology> imports = owlApi.getOntology().getImports();
assertThat(imports.size(), is(1));
assertThat(imports.iterator().next().getOntologyID().getOntologyIRI().toString(), equalTo("http://localhost/test_ab1.owl"));
}
@Test
public void testSetIRIMapping_validMapping_shouldStoreMapping() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.setIRIMapping(new HashMap<String, String>() {{
put("http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-34", TestUtils.getUri("/test_ab1.owl"));
}});
assertNotNull(owlApi.getIriMapper());
}
@Test
public void testSetIRIMapping_noMapping_shouldReturnNull() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
assertNull(owlApi.getIriMapper());
}
@Test(expected = IllegalArgumentException.class)
public void testLoad_malformedUrl_shouldThrowException() throws OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load("/malformed/url");
}
@Test(expected = OWLOntologyCreationException.class)
public void testLoad_invalidUrl_shouldThrowException() throws OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load("http://invalid.com/blah.owl");
}
@Test
public void testLoad_validUrl_shouldNotRaiseException() {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
try {
owlApi.load(getOwlUri());
} catch (OWLOntologyCreationException | URISyntaxException e) {
Assert.fail("Unexpected exception: " + e.getMessage());
}
}
@Test
public void testLoad_ontologyWithClass_shouldRecognizeClass() throws URISyntaxException, OWLOntologyCreationException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, OWLManager.getOWLDataFactory());
owlApi.load(getOwlUri());
assertTrue(invocationHandler.getOntology().containsClassInSignature(
IRI.create("http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-33#ClassA")));
}
@Test
public void testAddIndividual_shouldAddOnlyThisIndividualToOntology() throws URISyntaxException, OWLOntologyCreationException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, OWLManager.getOWLDataFactory());
owlApi.load(getOwlUri());
owlApi.addIndividual("indiv1");
OWLOntology ontology = invocationHandler.getOntology();
assertTrue(ontology.containsIndividualInSignature(owlApi.createIri("indiv1")));
assertFalse(ontology.containsIndividualInSignature(owlApi.createIri("indiv2")));
}
@Test
public void testAddIndividualByLabel_shouldAddOnlyThisIndividualToOntology() throws URISyntaxException, OWLOntologyCreationException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, OWLManager.getOWLDataFactory());
owlApi.load(getOwlUri());
owlApi.addIndividualByLabel("indiv1", "class1");
assertTrue(owlApi.containsIndividualByLabel("indiv1"));
assertFalse(owlApi.containsIndividualByLabel("indiv2"));
}
@Test
public void testAddIndividualByLabel_usingLabelAndName_shouldAddOnlyThisIndividualToOntology() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, OWLManager.getOWLDataFactory());
owlApi.load(getOwlUri());
owlApi.addIndividualByLabel("indiv1", "indiv1Name", "http://localhost/class1");
assertTrue(owlApi.containsIndividualByLabel("indiv1"));
assertTrue(owlApi.containsIndividual("indiv1Name"));
OWLNamedIndividual indiv = owlApi.getIndividual("indiv1Name");
assertTrue(owlApi.isIndividualOfClass(indiv, IRI.create("http://localhost/class1")));
assertFalse(owlApi.containsIndividualByLabel("indiv2"));
}
@Test
@Parameters({"IndivX"})
public void testFindIndividual_inexistentIndiv_shouldReturnNull(String indivName) throws OWLOntologyCreationException, URISyntaxException {
OwlApiFacade model = TestUtils.createDefaultOwlApiFacade();
model.load(TestUtils.getUri("/test_ab3.owl"), TestResources.createDefaultIriMapping());
IRI iri = model.findIndividualByFragmentAndLabel(indivName);
assertNull(iri);
}
@Test
@Parameters({"IndivD, http://localhost/test_ab3.owl#IndivD"})
public void testFindIndividual_indivInBaseOntology_shouldReturnIRI(String indivName, String expectedIRI) throws OWLOntologyCreationException, URISyntaxException, OwlElementNotFoundException {
OwlApiFacade model = TestUtils.createDefaultOwlApiFacade();
model.load(TestUtils.getUri("/test_ab3.owl"), TestResources.createDefaultIriMapping());
IRI iri = model.findIndividualByFragmentAndLabel(indivName);
assertThat(iri.toString(), equalTo(expectedIRI));
}
@Test
@Parameters({
"IndivA, http://localhost/test_ab1.owl#IndivA",
"IndivB, http://localhost/test_ab2.owl#IndivB"
})
public void testFindIndividual_indivInImportedOntology_shouldReturnIRI(String indivName, String expectedIRI) throws OWLOntologyCreationException, URISyntaxException, OwlElementNotFoundException {
OwlApiFacade model = TestUtils.createDefaultOwlApiFacade();
model.load(TestUtils.getUri("/test_ab3.owl"), TestResources.createDefaultIriMapping());
IRI iri = model.findIndividualByFragmentAndLabel(indivName);
assertThat(iri.toString(), equalTo(expectedIRI));
}
@Test
@Parameters({
"IndivE, http://localhost/test_ab4_usingLabel.owl#bf342340921",
"IndivA, http://localhost/test_ab1_usingLabel.owl#ab1232323"
})
public void testFindIndividual_byLabel_shouldReturnIRI(String indivName, String expectedIRI) throws OWLOntologyCreationException, URISyntaxException, OwlElementNotFoundException {
OwlApiFacade model = TestUtils.createDefaultOwlApiFacade();
model.load(TestUtils.getUri("/test_ab4_usingLabel.owl"), TestResources.createDefaultIriMapping());
IRI actualIRI = model.findIndividualByFragmentAndLabel(indivName);
assertThat(actualIRI.toString(), equalTo(expectedIRI));
}
@Test
public void testCreateIri_shouldReturnCorrectFormattedIri() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(getOwlUri());
String actual = owlApi.createIri("test").toURI().toString();
Assert.assertEquals("http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-33" + "#" + "test", actual);
}
@Test
public void testCreateIri_notAnIri_shouldAppendBaseUrl() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade defaultOwlApiFacade = TestUtils.createDefaultOwlApiFacade();
defaultOwlApiFacade.load(getOwlUri());
IRI actual = defaultOwlApiFacade.createIri("test");
Assert.assertEquals("http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-33#test", actual.toString());
}
@Test
@Parameters({"http://blah#test"})
public void testCreateIri_alreadyAnIri_shouldNotAlterIri(String iri) throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade defaultOwlApiFacade = TestUtils.createDefaultOwlApiFacade();
defaultOwlApiFacade.load(getOwlUri());
IRI actual = defaultOwlApiFacade.createIri(iri);
Assert.assertEquals(iri, actual.toString());
}
@Test
@Parameters({"http://blah#test, test"})
public void testCreateIri_alreadyAnIri_shouldReturnIriWithFragment(String iri, String expectedFragment) throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade defaultOwlApiFacade = TestUtils.createDefaultOwlApiFacade();
defaultOwlApiFacade.load(getOwlUri());
IRI actual = defaultOwlApiFacade.createIri(iri);
Assert.assertEquals(expectedFragment, actual.getFragment());
}
@Test
@Parameters({"http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-33#test, test"})
public void testCreateIri_sameIriAsBaseIriFromModel_shouldReturnIriWithFragment(String iri, String expectedFragment) throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade defaultOwlApiFacade = TestUtils.createDefaultOwlApiFacade();
defaultOwlApiFacade.load(getOwlUri());
IRI actual = defaultOwlApiFacade.createIri(iri);
Assert.assertEquals(expectedFragment, actual.getFragment());
}
@Test
@Ignore("Not implemented because it causes issues with other operations provided by the OwlAPI")
@Parameters({"http://blah#23, http://blah#, 23"})
public void testCreateIri_numericFragment_shouldReturnIriWithFragment(String iri, String expectedNamespace, String expectedFragment) throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade defaultOwlApiFacade = TestUtils.createDefaultOwlApiFacade();
defaultOwlApiFacade.load(getOwlUri());
IRI actual = defaultOwlApiFacade.createIri(iri);
Assert.assertEquals(expectedFragment, actual.getFragment());
Assert.assertEquals(expectedNamespace, actual.getNamespace());
Assert.assertEquals(iri, actual.toString());
}
@Test(expected = ConstraintsViolatedException.class)
public void testCreateIri_passingNull_shouldThrowException() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(getOwlUri());
owlApi.createIri(null);
}
@Test(expected = ConstraintsViolatedException.class)
public void testCreateIri_passingEmptyString_shouldThrowException() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(getOwlUri());
owlApi.createIri("");
}
@Test
public void testCreateIri_namespaceOnly_shouldReturnValidIri() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(getOwlUri());
String actual = owlApi.createIri("http://blah").toString();
Assert.assertEquals(actual, "http://blah");
}
@Test
public void testAddObjectProperty_shouldAddOnlyOneObjectPropertyToOntology() throws URISyntaxException, OWLOntologyCreationException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OWLDataFactory dataFactory = OWLManager.getOWLDataFactory();
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, dataFactory);
owlApi.load(getOwlUri());
OWLNamedIndividual indiv1 = owlApi.addIndividual("indiv1");
OWLNamedIndividual indiv2 = owlApi.addIndividual("indiv2");
OWLNamedIndividual indiv3 = owlApi.addIndividual("indiv3");
String objectPropertyName = "objectProperty";
owlApi.addObjectProperty(indiv1, objectPropertyName, indiv2);
OWLOntology ontology = invocationHandler.getOntology();
assertTrue(ontology.containsAxiom(dataFactory.getOWLObjectPropertyAssertionAxiom(dataFactory.getOWLObjectProperty(owlApi.createIri(objectPropertyName)), indiv1, indiv2)));
assertFalse(ontology.containsAxiom(dataFactory.getOWLObjectPropertyAssertionAxiom(dataFactory.getOWLObjectProperty(owlApi.createIri(objectPropertyName)), indiv3, indiv2)));
}
@Test
public void testAddDataProperty_shouldAddOnlyOneDataPropertyToOntology() throws URISyntaxException, OWLOntologyCreationException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OWLDataFactory dataFactory = OWLManager.getOWLDataFactory();
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, dataFactory);
owlApi.load(getOwlUri());
OWLNamedIndividual indiv1 = owlApi.addIndividual("indiv1");
OWLNamedIndividual indiv2 = owlApi.addIndividual("indiv2");
String dataPropertyName = "dataProperty";
int dataPropertyValue = 23;
owlApi.addDataProperty(indiv1, dataPropertyName, dataFactory.getOWLLiteral(dataPropertyValue));
OWLOntology ontology = invocationHandler.getOntology();
assertTrue(ontology.containsAxiom(dataFactory.getOWLDataPropertyAssertionAxiom(dataFactory.getOWLDataProperty(owlApi.createIri(dataPropertyName)), indiv1, dataPropertyValue)));
assertFalse(ontology.containsAxiom(dataFactory.getOWLDataPropertyAssertionAxiom(dataFactory.getOWLDataProperty(owlApi.createIri(dataPropertyName)), indiv2, dataPropertyValue)));
}
@Test
public void testMakeInstanceOf_unqualifiedClass_shouldAddAffectedIndividualAsMemberToClass() throws URISyntaxException, OWLOntologyCreationException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OWLDataFactory dataFactory = OWLManager.getOWLDataFactory();
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, dataFactory);
owlApi.load(getOwlUri());
OWLNamedIndividual indiv1 = owlApi.addIndividual("indiv1");
OWLNamedIndividual indiv2 = owlApi.addIndividual("indiv2");
String className = "classA";
owlApi.makeInstanceOf(indiv1, className);
OWLOntology ontology = invocationHandler.getOntology();
assertTrue(ontology.containsAxiom(dataFactory.getOWLClassAssertionAxiom(dataFactory.getOWLClass(owlApi.createIri(className)), indiv1)));
assertFalse(ontology.containsAxiom(dataFactory.getOWLClassAssertionAxiom(dataFactory.getOWLClass(owlApi.createIri(className)), indiv2)));
}
@Test
public void testMakeInstanceOf_qualifiedClass_shouldAddAffectedIndividualAsMemberToClass() throws URISyntaxException, OWLOntologyCreationException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OWLDataFactory dataFactory = OWLManager.getOWLDataFactory();
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, dataFactory);
owlApi.load(getOwlUri());
OWLNamedIndividual indiv1 = owlApi.addIndividual("indiv1");
OWLNamedIndividual indiv2 = owlApi.addIndividual("indiv2");
String className = "http://localhost/classA";
owlApi.makeInstanceOf(indiv1, className);
OWLOntology ontology = invocationHandler.getOntology();
assertTrue(ontology.containsAxiom(dataFactory.getOWLClassAssertionAxiom(dataFactory.getOWLClass(IRI.create(className)), indiv1)));
assertFalse(ontology.containsAxiom(dataFactory.getOWLClassAssertionAxiom(dataFactory.getOWLClass(owlApi.createIri(className)), indiv2)));
}
@Test
public void testAddInvidvidual_providingBaseClass_shouldAddIndividualAndAddAsMemberToClass() throws URISyntaxException, OWLOntologyCreationException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OWLDataFactory dataFactory = OWLManager.getOWLDataFactory();
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, dataFactory);
owlApi.load(getOwlUri());
String indivName = "indiv1";
String className = "classA";
OWLNamedIndividual indiv1 = owlApi.addIndividual(indivName, className);
OWLOntology ontology = invocationHandler.getOntology();
assertTrue(ontology.containsIndividualInSignature(owlApi.createIri(indivName)));
assertTrue(ontology.containsAxiom(dataFactory.getOWLClassAssertionAxiom(dataFactory.getOWLClass(owlApi.createIri(className)), indiv1)));
}
@Test
public void testGetOWLLiteral() {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
String literal = "literal";
OWLLiteral actual = owlApi.getOWLLiteral(literal, OWL2DatatypeImpl.getDatatype(OWL2Datatype.XSD_STRING));
Assert.assertEquals(actual, OWLManager.getOWLDataFactory().getOWLLiteral(literal));
}
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void testSave_shouldPersistOntologyToFile() throws OWLOntologyStorageException, URISyntaxException, OWLOntologyCreationException, IOException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(getOwlUri());
owlApi.addIndividual("indiv1");
File tmpFile = File.createTempFile("owl-api-facade-tests-", null);
tmpFile.deleteOnExit();
String filename = tmpFile.getAbsolutePath();
owlApi.save(filename);
OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntology(IRI.create("file:" + filename));
assertTrue(ontology.containsIndividualInSignature(owlApi.createIri("indiv1")));
assertFalse(ontology.containsIndividualInSignature(owlApi.createIri("indiv2")));
new File(filename).delete();
}
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void testCreate_shouldCreateEmptyOntology() throws OWLOntologyStorageException, URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.create("http;//test");
owlApi.addIndividual("indiv1");
OWLOntology ontology = owlApi.getOntology();
assertTrue(ontology.containsIndividualInSignature(owlApi.createIri("indiv1")));
assertFalse(ontology.containsIndividualInSignature(owlApi.createIri("indiv2")));
Assert.assertEquals(1, ontology.getIndividualsInSignature().size());
Assert.assertEquals(0, ontology.getClassesInSignature().size());
Assert.assertEquals(1, ontology.getSignature().size());
}
@Test(expected = ConstraintsViolatedException.class)
public void testAddOntology_noOntologyLoaded_shouldThrowException() throws URISyntaxException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.addOntology(TestUtils.getUri("/test2.owl"));
}
@Test
public void testAddOntology_ontologyLoaded_shouldAddOntology() throws URISyntaxException, OWLOntologyCreationException, OWLOntologyStorageException {
OwlManagerInvocationHandler invocationHandler = new OwlManagerInvocationHandler(OWLManager.createOWLOntologyManager());
OWLDataFactory dataFactory = OWLManager.getOWLDataFactory();
OwlApiFacade owlApi = TestUtils.getOwlApiFacadeUsingProxy(invocationHandler, dataFactory);
owlApi.load(getOwlUri());
owlApi.addOntology(TestUtils.getUri("/test2.owl"));
OWLOntology ontology = invocationHandler.getOntology();
assertTrue(ontology.getDirectImportsDocuments().contains(IRI.create(TestUtils.getUri("/test2.owl"))));
}
@Test
public void testMethods_noOntology_shouldThrowException() throws InvocationTargetException, IllegalAccessException, InstantiationException {
testExecMethod(getMethodsThatNeedOntology(), TestUtils.createDefaultOwlApiFacade());
}
@Test
public void testMethods_noOntologyManager_shouldThrowException() throws InvocationTargetException, IllegalAccessException, InstantiationException {
testExecMethod(getMethodsThatNeedOntologyManager(), new OwlApiFacade(null, OWLManager.getOWLDataFactory()));
}
@Test
public void testMethods_noDataFactory_shouldThrowException() throws InvocationTargetException, IllegalAccessException, InstantiationException {
testExecMethod(getMethodsThatNeedDataFactory(), new OwlApiFacade(OWLManager.createOWLOntologyManager(), null));
}
@SuppressWarnings("ResultOfMethodCallIgnored")
private void testExecMethod(List<String> methods, OwlApiFacade owlApi) throws IllegalAccessException {
String defaultStringArg = "str";
Boolean defaultBooleanArg = false;
for (Method method : OwlApiFacade.class.getDeclaredMethods()) {
if (!Modifier.isPublic(method.getModifiers())) continue;
if (!methods.contains(method.getName())) continue;
try {
Object[] args = new Object[method.getParameterTypes().length];
for (int i = 0; i < method.getParameterTypes().length; ++i) {
if (method.getParameterTypes()[i].equals(String.class)) {
args[i] = defaultStringArg;
} else if (method.getParameterTypes()[i].equals(boolean.class)) {
args[i] = defaultBooleanArg;
} else args[i] = null;
}
method.invoke(owlApi, args);
} catch (InvocationTargetException e) {
if (!(e.getTargetException() instanceof ConstraintsViolatedException)) {
Assert.fail(String.format("Unexpected exception of method %s: %s - %s", method.getName(),
e.getTargetException().getClass().getName(), e.getTargetException().getMessage()));
}
}
}
// cleanup
new File(defaultStringArg).delete();
}
// TODO: test getJenaModel with missing imports
private List<String> getMethodsThatNeedOntology() {
return new ArrayList<String>() {{
add("save");
add("addDataProperty");
add("addObjectProperty");
add("makeInstanceOf");
add("createIri");
add("addIndividual");
add("addOntology");
add("containsIndividual");
add("getIndividual");
add("getJenaModel");
add("getClassesOfIndividual");
add("isIndividualOfClass");
add("containsIndividualByLabel");
}};
}
private List<String> getMethodsThatNeedOntologyManager() {
return new ArrayList<String>() {{
add("load");
add("create");
add("addIndividual");
add("makeInstanceOf");
add("addObjectProperty");
add("addDataProperty");
add("save");
add("addOntology");
add("getJenaModel");
add("setIRIMapping");
}};
}
private List<String> getMethodsThatNeedDataFactory() {
return new ArrayList<String>() {{
add("addIndividual");
add("getIndividual");
add("makeInstanceOf");
add("addObjectProperty");
add("addDataProperty");
add("getOWLLiteral");
add("addOntology");
}};
}
@Test
public void testLoad_missingImports_shouldBeResolvedUsingIriMapping() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
Map<String, String> iriMapping = new HashMap<String, String>() {{
put("http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-34", TestUtils.getUri("/test2.owl"));
}};
owlApiFacade.load(TestUtils.getUri("/test_missing_import.owl"), iriMapping);
}
@Test
public void testLoad_missingImports_shouldNotThrowException() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(TestUtils.getUri("/test_missing_import.owl"));
Assert.assertNotNull(owlApiFacade.getOntology());
}
@Test
@Parameters(
{"test", "23"}
)
public void testGetIndividual_individualExists_shouldReturnIndividual(String indivName) throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
OWLNamedIndividual testIndiv = owlApiFacade.addIndividual(indivName);
Assert.assertEquals(testIndiv, owlApiFacade.getIndividual(indivName));
}
@Test(expected = OwlElementNotFoundException.class)
public void testGetIndividual_individualDoesNotExist_shouldThrowException() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
owlApiFacade.getIndividual("blah");
}
@Test(expected = OwlElementNotFoundException.class)
@Parameters(
{"http://blah#, test"}
)
public void testGetIndividual_fullyQualifiedIndividualWrongIri_shouldThrowException(String namespace, String fragment) throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
OWLNamedIndividual testIndiv = owlApiFacade.addIndividual(fragment);
Assert.assertEquals(testIndiv, owlApiFacade.getIndividual(namespace + fragment));
}
@Test
@Parameters({
"http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-33#, test",
"http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-33#, 23",
"http://blah#, test",
"http://blah#, 23"
})
public void testGetIndividual_fullyQualifiedIndividual_shouldReturnIndividual(String namespace, String fragment) throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
OWLNamedIndividual testIndiv = owlApiFacade.addIndividual(namespace + fragment);
Assert.assertEquals(testIndiv, owlApiFacade.getIndividual(namespace + fragment));
}
@Test
@Parameters(
{"http://importtest, test"}
)
public void testGetIndividualByUnqualifiedName_individualInImportedNamespace_shouldReturnIndividual(String url, String indivName) throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
owlApiFacade.addOntology(url);
OWLNamedIndividual testIndiv = owlApiFacade.addIndividual(url + "#" + indivName);
Assert.assertEquals(testIndiv, owlApiFacade.getIndividualByUnqualifiedName(indivName, true));
}
@Test(expected = ConstraintsViolatedException.class)
public void testGetIndividualByLabel_labelIsNull_shouldThrowException() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(TestUtils.getUri("/test_ab4_usingLabel.owl"));
owlApiFacade.getIndividualByLabel(null);
}
@Test(expected=OwlElementNotFoundException.class)
public void testGetIndividualByLabel_individualDoesNotExists_shouldReturnFalse() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
owlApiFacade.getIndividualByLabel("testblah");
}
@Test
public void testGetIndividualByLabel_individualExists_shouldReturn() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(TestUtils.getUri("/test_ab4_usingLabel.owl"));
Assert.assertEquals("http://localhost/test_ab4_usingLabel.owl#bf342340921", owlApiFacade.getIndividualByLabel("IndivE").getIRI().toString());
}
@Test
public void testGetdividualByLabel_individualInImportedOntology_shouldReturnTrue() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(TestUtils.getUri("/test_ab4_usingLabel.owl"), new HashMap<String, String>() {{
put("http://localhost/test_ab1_usingLabel.owl", TestUtils.getUri("/test_ab1_usingLabel.owl"));
put("http://localhost/test_ab2.owl", TestUtils.getUri("/test_ab2.owl"));
}});
Assert.assertEquals("http://localhost/test_ab1_usingLabel.owl#ab1232323", owlApiFacade.getIndividualByLabel("IndivA").getIRI().toString());
}
@Test
@Parameters({
"http://blah#, b", "http://blah#, 23", "http://timbus.teco.edu/ontologies/Scenarios/MusicClassification.owl#, 7cb4eeb2"
})
public void testGetFragment_shouldReturnFragment(String namespace, String fragment) throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
Assert.assertEquals(OwlApiFacade.getFragment(IRI.create(namespace + fragment)), fragment);
Assert.assertEquals(OwlApiFacade.getFragment(IRI.create(namespace, fragment)), fragment);
}
@Test
@Parameters({
"http://blah#, b", "http://blah#, 23", "http://timbus.teco.edu/ontologies/Scenarios/MusicClassification.owl#, 7cb4eeb2"
})
public void testGetNamespace_shouldReturnNamespace(String namespace, String fragment) throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
Assert.assertEquals(OwlApiFacade.getNamespace(IRI.create(namespace + fragment)), namespace);
Assert.assertEquals(OwlApiFacade.getNamespace(IRI.create(namespace, fragment)), namespace);
}
@Test
public void testContainsIndividual_individualExists_shouldReturnTrue() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
String testIndivName = "test";
owlApiFacade.addIndividual(testIndivName);
Assert.assertEquals(true, owlApiFacade.containsIndividual(testIndivName));
}
@Test
public void testContainsIndividual_individualDoesNotExists_shouldReturnFalse() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
String testIndivName = "testblah";
Assert.assertEquals(false, owlApiFacade.containsIndividual(testIndivName));
}
@Test
@Parameters(
{"http://importtest, test"}
)
public void testContainsndividual_individualInImportedNamespace_shouldReturnTrue(String url, String indivName) throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
owlApiFacade.addOntology(url);
owlApiFacade.addIndividual(url + "#" + indivName);
Assert.assertEquals(true, owlApiFacade.containsIndividual(indivName));
}
@Test(expected = ConstraintsViolatedException.class)
public void testContainsIndividualByLabel_labelIsNull_shouldThrowException() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(TestUtils.getUri("/test_ab4_usingLabel.owl"));
owlApiFacade.containsIndividualByLabel(null);
}
@Test
public void testContainsIndividualByLabel_individualExists_shouldReturnTrue() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(TestUtils.getUri("/test_ab4_usingLabel.owl"));
Assert.assertEquals(true, owlApiFacade.containsIndividualByLabel("IndivE"));
}
@Test
public void testContainsIndividualByLabel_individualDoesNotExists_shouldReturnFalse() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(getOwlUri());
Assert.assertEquals(false, owlApiFacade.containsIndividualByLabel("testblah"));
}
@Test
public void testContainsndividualByLabel_individualInImportedOntology_shouldReturnTrue() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApiFacade = TestUtils.createDefaultOwlApiFacade();
owlApiFacade.load(TestUtils.getUri("/test_ab4_usingLabel.owl"), new HashMap<String, String>() {{
put("http://localhost/test_ab1_usingLabel.owl", TestUtils.getUri("/test_ab1_usingLabel.owl"));
put("http://localhost/test_ab2.owl", TestUtils.getUri("/test_ab2.owl"));
}});
Assert.assertEquals(true, owlApiFacade.containsIndividualByLabel("IndivA"));
}
@Test
public void testConstructor_shouldInitOwlApiCompletely() throws OWLOntologyStorageException, URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(getOwlUri());
owlApi.addIndividual("indiv1");
OwlApiFacade owlApiUnderTest = new OwlApiFacade(owlApi.getOntology());
assertTrue("Ontology is not most likely not initialized.", owlApiUnderTest.containsIndividual(owlApi.createIri("indiv1").toString()));
assertFalse("Ontology is not most likely initialized.", owlApiUnderTest.containsIndividual(owlApi.createIri("indiv2").toString()));
owlApiUnderTest.addIndividual("indiv2"); // Manager is likely not initialized if this throws an exception.
assertTrue("DataFactory is most likely not initialized.", owlApiUnderTest.containsIndividual(owlApi.createIri("indiv2").toString())); // DataFactory is likely not initialized if this throws an exception.
Assert.assertNotNull("DataFactory is most likely not initialized.", owlApiUnderTest.getIndividual("indiv2"));
}
@Test
public void testLoad_fromStream_shouldLoadOntology() throws OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(this.getClass().getResourceAsStream("/test.owl"));
assertTrue(owlApi.getOntology().containsClassInSignature(
IRI.create("http://www.semanticweb.org/test/ontologies/2013/6/untitled-ontology-33#ClassA")));
assertThat(owlApi.getOntology().getClassesInSignature().size(), Is.is(2));
}
@Test
@Ignore
public void testGetJenaModel_validModel_shouldReturnJenaModel() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(this.getClass().getResourceAsStream("/test.owl"));
Model jenaModel = owlApi.getJenaModel(false);
Assert.assertNotNull(jenaModel);
Assert.assertEquals(29, jenaModel.size());
}
@Test
public void testGetClassesOfIndividual_classDefinedInSameOntology_shouldReturnClasses() throws OWLOntologyCreationException, OwlElementNotFoundException {
IRI[] expected = new IRI[] { IRI.create("http://localhost/test_ab1.owl#ClassA") };
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(this.getClass().getResourceAsStream("/test_ab1.owl"));
OWLNamedIndividual indiv = owlApi.getIndividualByUnqualifiedName("IndivA", false);
List<IRI> actual = owlApi.getClassesOfIndividual(indiv);
assertThat(actual, containsInAnyOrder(expected));
}
@Test
public void testGetClassesOfIndividual_classesDefinedInDifferentOntology_shouldReturnClasses() throws OWLOntologyCreationException, OwlElementNotFoundException, URISyntaxException {
IRI[] expected = new IRI[] {
IRI.create("http://localhost/test_ab1.owl#ClassA"),
IRI.create("http://localhost/test_ab2.owl#ClassB"),
IRI.create("http://localhost/test_ab3.owl#ClassD")
};
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.setIRIMapping(new HashMap<String, String>() {{
put("http://localhost/test_ab1.owl", TestUtils.getUri("/test_ab1.owl"));
put("http://localhost/test_ab2.owl", TestUtils.getUri("/test_ab2.owl"));
put("http://localhost/test_ab3.owl", TestUtils.getUri("/test_ab3.owl"));
}});
owlApi.load(this.getClass().getResourceAsStream("/test_ab4.owl"));
OWLNamedIndividual indiv = owlApi.getIndividualByUnqualifiedName("IndivE", false);
List<IRI> actual = owlApi.getClassesOfIndividual(indiv);
assertThat(actual, containsInAnyOrder(expected));
}
@Test
public void testGetClassesOfIndividual_noClassDefined_shouldReturnEmptyList() throws OWLOntologyCreationException, OwlElementNotFoundException, URISyntaxException {
IRI[] expected = new IRI[] { };
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(TestUtils.getUri("/test_ab4.owl"));
OWLNamedIndividual indiv = owlApi.getIndividualByUnqualifiedName("IndivF", false);
List<IRI> actual = owlApi.getClassesOfIndividual(indiv);
assertThat(actual, containsInAnyOrder(expected));
}
@Test(expected = ConstraintsViolatedException.class)
public void testGetClassesOfIndividual_indivNull_shouldThrowException() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(TestUtils.getUri("/test_ab4.owl"));
owlApi.getClassesOfIndividual(null);
}
@Test(expected = ConstraintsViolatedException.class)
public void testIsIndividualOfClass_indivNull_shouldThrowException() throws URISyntaxException, OWLOntologyCreationException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(TestUtils.getUri("/test_ab4.owl"));
owlApi.isIndividualOfClass(null, IRI.create("blah"));
}
@Test(expected = ConstraintsViolatedException.class)
public void testIsIndividualOfClass_classIriNull_shouldThrowException() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(TestUtils.getUri("/test_ab4.owl"));
OWLNamedIndividual indiv = owlApi.getIndividualByUnqualifiedName("IndivF", false);
owlApi.isIndividualOfClass(indiv, null);
}
@Test
public void testIsIndividualOfClass_validIndivAndClass_shouldReturnAsExpected() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
OwlApiFacade owlApi = TestUtils.createDefaultOwlApiFacade();
owlApi.load(TestUtils.getUri("/test_ab4.owl"));
OWLNamedIndividual indiv = owlApi.getIndividualByUnqualifiedName("IndivE", false);
assertTrue(owlApi.isIndividualOfClass(indiv, IRI.create("http://localhost/test_ab1.owl#ClassA")));
assertTrue(owlApi.isIndividualOfClass(indiv, IRI.create("http://localhost/test_ab2.owl#ClassB")));
assertTrue(owlApi.isIndividualOfClass(indiv, IRI.create("http://localhost/test_ab3.owl#ClassD")));
assertFalse(owlApi.isIndividualOfClass(indiv, IRI.create("http://localhost/test_ab4.owl#ClassE")));
}
@Test(expected = ConstraintsViolatedException.class)
public void testToXMLString_ontologyNull_shouldThrowException() throws IOException, OWLOntologyStorageException {
OwlApiFacade.toXMLString(null);
}
@Test
public void testToXMLString_validOntology_shouldReturnOntologyAsXML() throws IOException, OWLOntologyStorageException, OWLOntologyCreationException {
OwlApiFacade expected = TestUtils.createDefaultOwlApiFacade();
expected.load(new ByteArrayInputStream(TestResources.testOntology.getBytes("UTF-8")));
String xmlString = OwlApiFacade.toXMLString(expected.getOntology());
OwlApiFacade actual = TestUtils.createDefaultOwlApiFacade();
actual.load(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
assertThat(actual.getOntology().getAxiomCount(), equalTo(expected.getOntology().getAxiomCount()));
}
//<editor-fold desc="helper methods">
private String getOwlUri() throws URISyntaxException {
return TestUtils.getUri("/test.owl");
}
//</editor-fold>
}