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.rdf;
1920import org.junit.Assert;
21import org.junit.Test;
22import org.eclipse.rdf4j.rio.RDFFormat;
2324import javax.xml.datatype.DatatypeConfigurationException;
25import java.io.ByteArrayOutputStream;
26import java.io.OutputStreamWriter;
27import java.io.UnsupportedEncodingException;
28import java.net.URISyntaxException;
29import java.nio.charset.StandardCharsets;
30import java.text.ParseException;
3132/**33 * Reference test class for {@link RDFUtils}.34 *35 * @author Michele Mostarda (mostarda@fbk.eu)36 * @author Davide Palmisano (palmisano@gmail.com)37 */38publicclassRDFUtilsTest {
3940 @Test
41publicvoid testFixAbsoluteIRI() throws UnsupportedEncodingException, URISyntaxException {
42 Assert.assertEquals("Error: passed IRIs are not the same.", "http://example.com/resource/the%20godfather",
43 RDFUtils.fixAbsoluteIRI("http://example.com/resource/the godfather"));
4445 Assert.assertEquals("Error: passed IRIs are not the same.", "http://dbpedia.org/",
46 RDFUtils.fixAbsoluteIRI("http://dbpedia.org"));
47 }
4849 @Test
50publicvoid testGetXSDDate() throws DatatypeConfigurationException, ParseException {
51 Assert.assertEquals("1997-09-01T13:00:00.000Z", RDFUtils.getXSDDate("19970901T1300Z", "yyyyMMdd'T'HHmm'Z'"));
52 }
5354/**55 * Tests the extension support.56 */57 @Test
58publicvoid testGetRDFFormatByExtension() {
59 Assert.assertEquals(RDFFormat.NTRIPLES, RDFUtils.getFormatByExtension("nt").get());
60 Assert.assertEquals(RDFFormat.TURTLE, RDFUtils.getFormatByExtension("ttl").get());
61 Assert.assertEquals(RDFFormat.NQUADS, RDFUtils.getFormatByExtension("nq").get());
62 Assert.assertEquals(RDFFormat.NQUADS, RDFUtils.getFormatByExtension(".nq").get());
63 }
6465/**66 * Tests the <code>NQuads</code> format support.67 */68 @Test
69publicvoid testGetNQuadsFormat() {
70 RDFUtils.getFormats().contains(RDFFormat.NQUADS);
71 }
7273/**74 * Tests the <code>NQuads</code> parsing support.75 */76 @Test
77publicvoid testGetNQuadsParser() {
78 Assert.assertNotNull(RDFUtils.getParser(RDFFormat.NQUADS));
79 }
8081/**82 * Tests the <code>NQuads</code> writing support.83 */84 @Test
85publicvoid testGetNQuadsWriter() {
86 Assert.assertNotNull(RDFUtils.getWriter(RDFFormat.NQUADS,
87new OutputStreamWriter(new ByteArrayOutputStream(), StandardCharsets.UTF_8)));
88 }
8990 }