This project has retired. For details please refer to its Attic page.
TurtleExtractorTest xref
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.ExtractionException;
22  import org.apache.any23.extractor.ExtractionParameters;
23  import org.apache.any23.extractor.ExtractionResult;
24  import org.apache.any23.extractor.ExtractionResultImpl;
25  import org.apache.any23.rdf.RDFUtils;
26  import org.apache.any23.writer.RDFXMLWriter;
27  import org.apache.any23.writer.TripleHandler;
28  import org.apache.any23.writer.TripleHandlerException;
29  import org.junit.After;
30  import org.junit.Before;
31  import org.junit.Test;
32  import org.eclipse.rdf4j.model.IRI;
33  import org.slf4j.Logger;
34  import org.slf4j.LoggerFactory;
35  
36  import java.io.ByteArrayOutputStream;
37  import java.io.IOException;
38  import java.nio.charset.StandardCharsets;
39  
40  /**
41   * Test case for {@link NTriplesExtractor}.
42   *
43   * @author Michele Mostarda ( michele.mostarda@gmail.com )
44   * 
45   * @version $Id$
46   */
47  public class TurtleExtractorTest {
48  
49      private static final Logger logger = LoggerFactory.getLogger(TurtleExtractorTest.class);
50  
51      private TurtleExtractor extractor;
52  
53      @Before
54      public void setUp() {
55          extractor = new TurtleExtractor();
56      }
57  
58      @After
59      public void tearDown() {
60          extractor = null;
61      }
62  
63      /**
64       * Tests the correct support for a typed literal with incompatible value.
65       * 
66       * @throws IOException
67       *             if there is an error interpreting the input data
68       * @throws ExtractionException
69       *             if there is an exception during extraction
70       * @throws TripleHandlerException
71       *             if there is an error within the {@link org.apache.any23.writer.TripleHandler} implementation
72       */
73      @Test
74      public void testTypedLiteralIncompatibleValueSupport()
75              throws IOException, ExtractionException, TripleHandlerException {
76          final IRI uri = RDFUtils.iri("http://host.com/test-malformed-literal.turtle");
77          ByteArrayOutputStream baos = new ByteArrayOutputStream();
78          final TripleHandler th = new RDFXMLWriter(baos);
79          final ExtractionContext extractionContext = new ExtractionContext("turtle-extractor", uri);
80          final ExtractionResult result = new ExtractionResultImpl(extractionContext, extractor, th);
81          extractor.setStopAtFirstError(false);
82          try {
83              extractor.run(ExtractionParameters.newDefault(), extractionContext,
84                      this.getClass().getResourceAsStream("/org/apache/any23/extractor/rdf/testMalformedLiteral"),
85                      result);
86          } finally {
87              logger.debug(baos.toString(StandardCharsets.UTF_8));
88              th.close();
89              result.close();
90          }
91      }
92  
93  }