|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 SPARQL Anything Contributors @ http://github.com/sparql-anything |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +package io.github.sparqlanything.xml; |
| 20 | + |
| 21 | +import io.github.sparqlanything.model.BaseFacadeXGraphBuilder; |
| 22 | +import io.github.sparqlanything.model.FacadeXGraphBuilder; |
| 23 | +import io.github.sparqlanything.model.IRIArgument; |
| 24 | +import io.github.sparqlanything.model.TriplifierHTTPException; |
| 25 | +import org.apache.jena.graph.NodeFactory; |
| 26 | +import org.apache.jena.sparql.core.DatasetGraph; |
| 27 | +import org.apache.jena.sparql.core.Quad; |
| 28 | +import org.apache.jena.vocabulary.RDF; |
| 29 | +import org.junit.Assert; |
| 30 | +import org.junit.Test; |
| 31 | +import org.slf4j.Logger; |
| 32 | +import org.slf4j.LoggerFactory; |
| 33 | + |
| 34 | +import java.io.IOException; |
| 35 | +import java.net.URL; |
| 36 | +import java.util.Iterator; |
| 37 | +import java.util.Objects; |
| 38 | +import java.util.Properties; |
| 39 | + |
| 40 | +public class Issue619Test { |
| 41 | + |
| 42 | + final static Logger logger = LoggerFactory.getLogger(Issue619Test.class); |
| 43 | + |
| 44 | + @Test |
| 45 | + public void newlinesAndWhitespacePreservedWhenTrimStringsIsFalse() |
| 46 | + throws TriplifierHTTPException, IOException { |
| 47 | + Properties properties = new Properties(); |
| 48 | + URL xml = getClass().getClassLoader().getResource("./Issue619.xml"); |
| 49 | + properties.setProperty(IRIArgument.LOCATION.toString(), |
| 50 | + Objects.requireNonNull(xml).toString()); |
| 51 | + properties.setProperty(IRIArgument.TRIM_STRINGS.toString(), "false"); |
| 52 | + |
| 53 | + FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(properties); |
| 54 | + XMLTriplifier triplifier = new XMLTriplifier(); |
| 55 | + triplifier.triplify(properties, builder); |
| 56 | + |
| 57 | + DatasetGraph graph = builder.getDatasetGraph(); |
| 58 | + logger.debug("{}", graph); |
| 59 | + |
| 60 | + String expected = "Line 1\n Line 2"; |
| 61 | + Iterator<Quad> it = graph.find(null, null, RDF.li(1).asNode(), |
| 62 | + NodeFactory.createLiteralString(expected)); |
| 63 | + Assert.assertTrue( |
| 64 | + "Expected literal preserving the newline and indentation between 'Line 1' and 'Line 2'", |
| 65 | + it.hasNext()); |
| 66 | + } |
| 67 | +} |
0 commit comments