Skip to content
Permalink
Browse files
COMMONSRDF-66: merged PR by @christopher-johnson, closes #42
* pan-dora/commonsrdf-66:
  fixes RIOT exception thrown by JenaDatasetImpl.toString() adds test

Signed-off-by: Sergio Fernández <sergio@wikier.org>
  • Loading branch information
wikier committed Nov 2, 2017
2 parents ecc81fa + f284e28 commit 895718276b8bba064679b3ee97f95ab2ff70bfc0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
@@ -149,7 +149,7 @@ public Stream<? extends Quad> stream(final Optional<BlankNodeOrIRI> g, final Bla
@Override
public String toString() {
final StringWriter sw = new StringWriter();
RDFDataMgr.write(sw, datasetGraph, Lang.NT);
RDFDataMgr.write(sw, datasetGraph, Lang.NQUADS);
return sw.toString();
}

@@ -15,11 +15,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.rdf.jena;

import static org.junit.Assert.assertEquals;

import org.apache.commons.rdf.api.AbstractDatasetTest;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Literal;
import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.simple.Types;
import org.junit.Test;

public class DatasetJenaTest extends AbstractDatasetTest {

@@ -28,4 +33,18 @@ public RDF createFactory() {
return new JenaRDF();
}

@Test
public void datasetImplToStringTest() {
RDF rdf = createFactory();
JenaDataset jena = (JenaDataset) rdf.createDataset();
final IRI graph = rdf.createIRI("http://example.com/");
final IRI s = rdf.createIRI("http://example.com/s");
final IRI p = rdf.createIRI("http://example.com/p");
final Literal literal123 = rdf.createLiteral("123", Types.XSD_INTEGER);
jena.add(graph, s, p, literal123);
String out = jena.toString();
assertEquals("<http://example.com/s> <http://example.com/p> \"123\"^^<http://www"
+ ".w3.org/2001/XMLSchema#integer> <http://example.com/> .\n", out);
assertEquals(10L, dataset.size());
}
}

0 comments on commit 8957182

Please sign in to comment.