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.extractor.rdf;
1920import org.apache.any23.extractor.ExtractionContext;
21import org.apache.any23.extractor.ExtractionException;
22import org.apache.any23.extractor.ExtractionParameters;
23import org.apache.any23.extractor.ExtractionResult;
24import org.apache.any23.extractor.ExtractionResultImpl;
25import org.apache.any23.rdf.RDFUtils;
26import org.apache.any23.writer.RDFXMLWriter;
27import org.apache.any23.writer.TripleHandler;
28import org.apache.any23.writer.TripleHandlerException;
29import org.junit.After;
30import org.junit.Before;
31import org.junit.Test;
32import org.eclipse.rdf4j.model.IRI;
33import org.slf4j.Logger;
34import org.slf4j.LoggerFactory;
3536import java.io.ByteArrayOutputStream;
37import java.io.IOException;
38import java.nio.charset.StandardCharsets;
3940/**41 * Test case for {@link NTriplesExtractor}.42 *43 * @author Michele Mostarda ( michele.mostarda@gmail.com )44 * 45 * @version $Id$46 */47publicclassTurtleExtractorTest {
4849privatestaticfinal Logger logger = LoggerFactory.getLogger(TurtleExtractorTest.class);
5051private TurtleExtractor extractor;
5253 @Before
54publicvoid setUp() {
55 extractor = new TurtleExtractor();
56 }
5758 @After
59publicvoid tearDown() {
60 extractor = null;
61 }
6263/**64 * Tests the correct support for a typed literal with incompatible value.65 * 66 * @throws IOException67 * if there is an error interpreting the input data68 * @throws ExtractionException69 * if there is an exception during extraction70 * @throws TripleHandlerException71 * if there is an error within the {@link org.apache.any23.writer.TripleHandler} implementation72 */73 @Test
74publicvoid testTypedLiteralIncompatibleValueSupport()
75throws IOException, ExtractionException, TripleHandlerException {
76final IRI uri = RDFUtils.iri("http://host.com/test-malformed-literal.turtle");
77 ByteArrayOutputStream baos = new ByteArrayOutputStream();
78final TripleHandler th = new RDFXMLWriter(baos);
79final ExtractionContext extractionContext = new ExtractionContext("turtle-extractor", uri);
80final ExtractionResult result = new ExtractionResultImpl(extractionContext, extractor, th);
81 extractor.setStopAtFirstError(false);
82try {
83 extractor.run(ExtractionParameters.newDefault(), extractionContext,
84this.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 }
9293 }