1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.any23.vocab;
19
20 import org.apache.any23.rdf.RDFUtils;
21 import org.junit.After;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.eclipse.rdf4j.model.IRI;
26
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
30
31
32
33
34
35
36 public class VocabularyTest {
37
38 private static final String namespace = "http://test/vocab#";
39
40 private Vocabulary target;
41
42 @Before
43 public void setUp() {
44 target = new TargetVocabulary();
45 }
46
47 @After
48 public void tearDown() {
49 target = null;
50 }
51
52 @Test
53 public void testGetProperties() {
54 final IRI[] props = target.getProperties();
55 Assert.assertEquals(3, props.length);
56 final List<IRI> propsList = new ArrayList<IRI>(Arrays.asList(props));
57 Assert.assertTrue(propsList.contains(RDFUtils.iri("http://test/vocab#prop1")));
58 Assert.assertTrue(propsList.contains(RDFUtils.iri("http://test/vocab#prop2")));
59 Assert.assertTrue(propsList.contains(RDFUtils.iri("http://test/vocab#prop3")));
60 }
61
62 @Test
63 public void testGetClasses() {
64 final IRI[] classes = target.getClasses();
65 Assert.assertEquals(3, classes.length);
66 final List<IRI> propsList = new ArrayList<IRI>(Arrays.asList(classes));
67 Assert.assertTrue(propsList.contains(RDFUtils.iri("http://test/vocab#Class1")));
68 Assert.assertTrue(propsList.contains(RDFUtils.iri("http://test/vocab#Class2")));
69 Assert.assertTrue(propsList.contains(RDFUtils.iri("http://test/vocab#Class3")));
70 }
71
72 @Test
73 public void testGetComments() {
74 Assert.assertEquals("Comment class 1.", target.getCommentFor(RDFUtils.iri("http://test/vocab#Class1")));
75 Assert.assertEquals("Comment class 2.", target.getCommentFor(RDFUtils.iri("http://test/vocab#Class2")));
76 Assert.assertEquals("Comment prop 1.", target.getCommentFor(RDFUtils.iri("http://test/vocab#prop1")));
77 Assert.assertEquals("Comment prop 2.", target.getCommentFor(RDFUtils.iri("http://test/vocab#prop2")));
78 Assert.assertEquals(4, target.getComments().size());
79 }
80
81
82
83
84 static class TargetVocabulary extends Vocabulary {
85
86 @Comment("Comment prop 1.")
87 public final IRI property1 = createProperty(namespace, "prop1");
88 @Comment("Comment prop 2.")
89 public final IRI property2 = createProperty(namespace, "prop2");
90
91 public final IRI property3 = createProperty(namespace, "prop3");
92
93 @Comment("Comment class 1.")
94 public final IRI class1 = createClass(namespace, "Class1");
95 @Comment("Comment class 2.")
96 public final IRI class2 = createClass(namespace, "Class2");
97
98 public final IRI class3 = createClass(namespace, "Class3");
99
100
101
102
103 public TargetVocabulary() {
104 super(namespace);
105 }
106
107 }
108
109 }