View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *  http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * 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 and
    15   * limitations under the License.
    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   * Test case for {@link Vocabulary} class.
    33   *
    34   * @author Michele Mostarda (mostarda@fbk.eu)
    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       * Target test class.
    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          * Constructor.
    102          */
    103         public TargetVocabulary() {
    104             super(namespace);
    105         }
    106
    107     }
    108
    109 }