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.extractor.rdf;
    19
    20  import org.apache.any23.extractor.ExtractionContext;
    21  import org.apache.any23.extractor.ExtractionParameters;
    22  import org.apache.any23.extractor.ExtractionResult;
    23  import org.apache.any23.extractor.ExtractionResultImpl;
    24  import org.apache.any23.rdf.RDFUtils;
    25  import org.apache.any23.writer.RDFXMLWriter;
    26  import org.apache.any23.writer.TripleHandler;
    27  import org.junit.After;
    28  import org.junit.Before;
    29  import org.junit.Test;
    30  import org.eclipse.rdf4j.model.IRI;
    31  import org.slf4j.Logger;
    32  import org.slf4j.LoggerFactory;
    33
    34  import java.io.ByteArrayOutputStream;
    35  import java.nio.charset.StandardCharsets;
    36
    37  /**
    38   * Test case for {@link ManchesterSyntaxExtractor}.
    39   *
    40   * @author Peter Ansell
    41   */
    42  public class ManchesterSyntaxExtractorTest {
    43
    44      private static final Logger logger = LoggerFactory.getLogger(ManchesterSyntaxExtractorTest.class);
    45
    46      private ManchesterSyntaxExtractor extractor;
    47
    48      @Before
    49      public void setUp() {
    50          extractor = new ManchesterSyntaxExtractor();
    51      }
    52
    53      @After
    54      public void tearDown() {
    55          extractor = null;
    56      }
    57
    58      @Test
    59      public void testExampleManchesterSyntax() throws Exception {
    60          final IRI uri = RDFUtils.iri("http://example.org/example-manchestersyntax.omn");
    61          ByteArrayOutputStream baos = new ByteArrayOutputStream();
    62          final TripleHandler th = new RDFXMLWriter(baos);
    63          final ExtractionContext extractionContext = new ExtractionContext("owl-manchestersyntax-extractor", uri);
    64          final ExtractionResult result = new ExtractionResultImpl(extractionContext, extractor, th);
    65          extractor.setStopAtFirstError(false);
    66          try {
    67              extractor.run(ExtractionParameters.newDefault(), extractionContext,
    68                      this.getClass().getResourceAsStream("/text/owl-manchester/example-manchestersyntax.omn"), result);
    69          } finally {
    70              logger.debug(baos.toString(StandardCharsets.UTF_8));
    71              th.close();
    72              result.close();
    73          }
    74      }
    75
    76  }