1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */1718package org.apache.any23.vocab;
1920import org.apache.any23.rdf.RDFUtils;
21import org.junit.After;
22import org.junit.Assert;
23import org.junit.Before;
24import org.junit.Test;
25import org.eclipse.rdf4j.model.IRI;
2627import java.util.ArrayList;
28import java.util.Arrays;
29import java.util.List;
3031/**32 * Test case for {@link Vocabulary} class.33 *34 * @author Michele Mostarda (mostarda@fbk.eu)35 */36publicclassVocabularyTest {
3738privatestaticfinal String namespace = "http://test/vocab#";
3940private Vocabulary target;
4142 @Before
43publicvoid setUp() {
44 target = new TargetVocabulary();
45 }
4647 @After
48publicvoid tearDown() {
49 target = null;
50 }
5152 @Test
53publicvoid testGetProperties() {
54final IRI[] props = target.getProperties();
55 Assert.assertEquals(3, props.length);
56final 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 }
6162 @Test
63publicvoid testGetClasses() {
64final IRI[] classes = target.getClasses();
65 Assert.assertEquals(3, classes.length);
66final 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 }
7172 @Test
73publicvoid 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 }
8081/**82 * Target test class.83 */84staticclass TargetVocabulary extends Vocabulary {
8586 @Comment("Comment prop 1.")
87publicfinal IRI property1 = createProperty(namespace, "prop1");
88 @Comment("Comment prop 2.")
89publicfinal IRI property2 = createProperty(namespace, "prop2");
9091publicfinal IRI property3 = createProperty(namespace, "prop3");
9293 @Comment("Comment class 1.")
94publicfinal IRI class1 = createClass(namespace, "Class1");
95 @Comment("Comment class 2.")
96publicfinal IRI class2 = createClass(namespace, "Class2");
9798publicfinal IRI class3 = createClass(namespace, "Class3");
99100/**101 * Constructor.102 */103public TargetVocabulary() {
104super(namespace);
105 }
106107 }
108109 }