lift to module path based compiling and testing
parent
6811c4a8e0
commit
2805b97026
@ -0,0 +1,11 @@
|
||||
|
||||
def moduleName = 'org.xbib.content.csv.test'
|
||||
def patchArgs = ['--patch-module', "$moduleName=" + files(sourceSets.test.resources.srcDirs).asPath ]
|
||||
|
||||
tasks.named('compileTestJava') {
|
||||
options.compilerArgs += patchArgs
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
jvmArgs += patchArgs
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
module org.xbib.content.csv.test {
|
||||
requires org.junit.jupiter.api;
|
||||
requires org.xbib.content.csv;
|
||||
exports org.xbib.content.csv.test;
|
||||
opens org.xbib.content.csv.test to org.junit.platform.commons;
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for testing CSV content.
|
||||
*/
|
||||
package org.xbib.content.csv;
|
@ -1,6 +1,8 @@
|
||||
package org.xbib.content.csv;
|
||||
package org.xbib.content.csv.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.csv.CSVGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
@ -1,4 +1,4 @@
|
||||
package org.xbib.content.csv;
|
||||
package org.xbib.content.csv.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.io.BufferedReader;
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration status="OFF">
|
||||
<appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%-25c][%t] %m%n"/>
|
||||
</Console>
|
||||
</appenders>
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</configuration>
|
Can't render this file because it is too large.
|
@ -1,5 +1,15 @@
|
||||
dependencies {
|
||||
api project(':content-core')
|
||||
api libs.jackson.databind
|
||||
testImplementation libs.mockito.inline
|
||||
testImplementation testLibs.mockito.core
|
||||
}
|
||||
|
||||
def patchArgs = ['--patch-module', "org.xbib.content.json.test=" + sourceSets.test.resources.sourceDirectories.singleFile]
|
||||
|
||||
tasks.named('compileTestJava') {
|
||||
options.compilerArgs += patchArgs
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
jvmArgs += patchArgs
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
module org.xbib.content.json.test {
|
||||
requires com.fasterxml.jackson.core;
|
||||
requires com.fasterxml.jackson.databind;
|
||||
requires java.logging;
|
||||
requires jdk.unsupported; // sun.reflect for objenesis in mockito
|
||||
requires org.mockito;
|
||||
requires org.junit.jupiter.api;
|
||||
requires org.xbib.content.api;
|
||||
requires org.xbib.content.core;
|
||||
requires org.xbib.content.json;
|
||||
exports org.xbib.content.json.test;
|
||||
exports org.xbib.content.json.test.jackson;
|
||||
exports org.xbib.content.json.test.pointer;
|
||||
opens org.xbib.content.json.test to org.junit.platform.commons;
|
||||
opens org.xbib.content.json.test.jackson to org.junit.platform.commons;
|
||||
opens org.xbib.content.json.test.pointer to org.junit.platform.commons;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
/**
|
||||
* Classes for testing JSON jackson.
|
||||
*/
|
||||
package org.xbib.content.json.jackson;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.xbib.content.json;
|
||||
package org.xbib.content.json.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
@ -1,8 +1,10 @@
|
||||
package org.xbib.content.json;
|
||||
package org.xbib.content.json.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.XContentParser;
|
||||
import org.xbib.content.json.JsonXContent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
@ -1,7 +1,9 @@
|
||||
package org.xbib.content.json.jackson;
|
||||
package org.xbib.content.json.test.jackson;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import org.xbib.content.json.jackson.JacksonUtils;
|
||||
import org.xbib.content.json.jackson.NodeType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
@ -1,9 +1,12 @@
|
||||
package org.xbib.content.json.pointer;
|
||||
package org.xbib.content.json.test.pointer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.json.pointer.JsonPointerException;
|
||||
import org.xbib.content.json.pointer.ReferenceToken;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for RDF JSON.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.json;
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for RDF N-Quads.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.nquads;
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for RDF N-Triples.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.ntriple;
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for RDF XML.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.rdfxml;
|
@ -0,0 +1,17 @@
|
||||
module org.xbib.content.rdf.test {
|
||||
requires java.logging;
|
||||
requires java.xml;
|
||||
requires org.junit.jupiter.api;
|
||||
requires org.xbib.content.rdf;
|
||||
requires org.xbib.content.resource;
|
||||
requires org.xbib.net;
|
||||
opens org.xbib.content.rdf.test to org.junit.platform.commons;
|
||||
opens org.xbib.content.rdf.test.internal to org.junit.platform.commons;
|
||||
opens org.xbib.content.rdf.test.io to org.junit.platform.commons;
|
||||
opens org.xbib.content.rdf.test.io.json to org.junit.platform.commons;
|
||||
opens org.xbib.content.rdf.test.io.ntriple to org.junit.platform.commons;
|
||||
opens org.xbib.content.rdf.test.io.rdfxml to org.junit.platform.commons;
|
||||
opens org.xbib.content.rdf.test.io.turtle to org.junit.platform.commons;
|
||||
opens org.xbib.content.rdf.test.io.xml to org.junit.platform.commons;
|
||||
opens org.xbib.content.rdf.test.util to org.junit.platform.commons;
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for testing internal RDF.
|
||||
*/
|
||||
package org.xbib.content.rdf.internal;
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for testing RDF JSON.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.json;
|
@ -1,29 +0,0 @@
|
||||
package org.xbib.content.rdf.io.ntriple;
|
||||
|
||||
import static org.xbib.content.rdf.RdfContentFactory.ntripleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentBuilder;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class NTripleReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testReader() throws Exception {
|
||||
String filename = "list.nt";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
if (in == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder();
|
||||
NTripleContentParser<NTripleContentParams> reader = new NTripleContentParser<>(in);
|
||||
reader.setBuilder(builder);
|
||||
reader.parse();
|
||||
assertStream("", getClass().getResource("rdfxml.ttl").openStream(),
|
||||
builder.streamInput());
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for testing RDF N-Triples.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.ntriple;
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for testing RDF input/output.
|
||||
*/
|
||||
package org.xbib.content.rdf.io;
|
@ -1,54 +0,0 @@
|
||||
package org.xbib.content.rdf.io.rdfxml;
|
||||
|
||||
import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentFactory;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParams;
|
||||
import org.xbib.content.rdf.io.turtle.TurtleContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class GNDRdfXmlReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testGNDfromRdfXmltoTurtle() throws Exception {
|
||||
String filename = "GND.rdf";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
TurtleContentParams params = new TurtleContentParams(IRINamespaceContext.newInstance(), false);
|
||||
RdfXmlContentParser<TurtleContentParams> reader = new RdfXmlContentParser<>(in);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
reader.setRdfContentBuilderProvider(() -> turtleBuilder(params));
|
||||
reader.setRdfContentBuilderHandler(builder -> sb.append(builder.string()));
|
||||
reader.parse();
|
||||
assertStream("gnd.ttl", getClass().getResourceAsStream("gnd.ttl"), sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnotherGNDfromRdfXmltoTurtle() throws Exception {
|
||||
String filename = "GND.rdf";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
TurtleContentParams params = new TurtleContentParams(IRINamespaceContext.newInstance(), false);
|
||||
RdfXmlContentParser<TurtleContentParams> reader = new RdfXmlContentParser<>(in);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
reader.setRdfContentBuilderProvider(() -> turtleBuilder(params));
|
||||
reader.setRdfContentBuilderHandler(builder -> sb.append(builder.string()));
|
||||
reader.parse();
|
||||
assertStream("gnd.ttl", getClass().getResourceAsStream("gnd.ttl"), sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGNDtoNtriple() throws Exception {
|
||||
String filename = "GND.rdf";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
RdfXmlContentParser<NTripleContentParams> reader = new RdfXmlContentParser<>(in);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
reader.setRdfContentBuilderProvider(RdfContentFactory::ntripleBuilder);
|
||||
reader.setRdfContentBuilderHandler(builder -> sb.append(builder.string()));
|
||||
reader.parse();
|
||||
assertStream("GND.nt", getClass().getResourceAsStream("GND.nt"), sb.toString());
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package org.xbib.content.rdf.io.rdfxml;
|
||||
|
||||
import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.internal.DefaultAnonymousResource;
|
||||
import org.xbib.content.rdf.io.turtle.TurtleContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class RdfXmlReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testReader() throws Exception {
|
||||
String filename = "118540238.xml";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
DefaultAnonymousResource.reset();
|
||||
TurtleContentParams params = new TurtleContentParams(IRINamespaceContext.getInstance(), false);
|
||||
RdfXmlContentParser<TurtleContentParams> reader = new RdfXmlContentParser<>(in);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
reader.setRdfContentBuilderProvider(() -> turtleBuilder(params));
|
||||
reader.setRdfContentBuilderHandler(builder -> sb.append(builder.string()));
|
||||
reader.parse();
|
||||
assertStream("118540238.ttl", getClass().getResourceAsStream("118540238.ttl"), sb.toString());
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package org.xbib.content.rdf.io.rdfxml;
|
||||
|
||||
import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.io.turtle.TurtleContentParams;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class VIAFRdfXmlReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testVIAF() throws Exception {
|
||||
InputStream in = getClass().getResource("VIAF.rdf").openStream();
|
||||
if (in == null) {
|
||||
throw new IOException("VIAF.rdf not found");
|
||||
}
|
||||
TurtleContentParams params = new TurtleContentParams(IRINamespaceContext.newInstance(), false);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
new RdfXmlContentParser<TurtleContentParams>(in)
|
||||
.setRdfContentBuilderProvider(() -> turtleBuilder(params))
|
||||
.setRdfContentBuilderHandler(builder -> sb.append(builder.string()))
|
||||
.parse();
|
||||
assertStream("viaf.ttl", getClass().getResource("viaf.ttl").openStream(), sb.toString());
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for testing RDF XML.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.rdfxml;
|
@ -1,30 +0,0 @@
|
||||
package org.xbib.content.rdf.io.turtle;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentFactory;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TurtleConformanceTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void conformance() throws Exception {
|
||||
for (int n = 0; n < 30; n++) {
|
||||
String testNum = String.format("%02d", n);
|
||||
InputStream in = getClass().getResource("/turtle/test-" + testNum + ".ttl").openStream();
|
||||
TurtleContentParser<TurtleContentParams> turtleParser = new TurtleContentParser<TurtleContentParams>(in)
|
||||
.setBaseIRI(IRI.create("http://example/base/"));
|
||||
turtleParser.setRdfContentBuilderProvider(RdfContentFactory::turtleBuilder);
|
||||
turtleParser.setRdfContentBuilderHandler(b -> {
|
||||
//logger.log(Level.INFO, MessageFormat.format("turtle test {0}", b.string()));
|
||||
});
|
||||
turtleParser.parse();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for testing RDF Turtle.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.turtle;
|
@ -1,217 +0,0 @@
|
||||
package org.xbib.content.rdf.io.xml;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.xbib.content.rdf.RdfContentFactory.turtleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentBuilder;
|
||||
import org.xbib.content.rdf.Resource;
|
||||
import org.xbib.content.rdf.Triple;
|
||||
import org.xbib.content.rdf.internal.DefaultAnonymousResource;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContent;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParams;
|
||||
import org.xbib.content.rdf.io.turtle.TurtleContentParams;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
import org.xbib.content.resource.NamespaceContext;
|
||||
import org.xbib.content.rdf.StreamTester;
|
||||
import org.xbib.net.PercentEncoders;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class XmlReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testOAIDC() throws Exception {
|
||||
String filename = "oro-eprint-25656.xml";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
if (in == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance();
|
||||
namespaceContext.addNamespace("oaidc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
|
||||
namespaceContext.addNamespace("dc", "http://purl.org/dc/elements/1.1/");
|
||||
|
||||
XmlContentParams params = new XmlContentParams(namespaceContext);
|
||||
XmlHandler<TurtleContentParams> xmlHandler = new AbstractXmlResourceHandler<>(params) {
|
||||
|
||||
@Override
|
||||
public boolean isResourceDelimiter(QName name) {
|
||||
return "oai_dc".equals(name.getLocalPart());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void identify(QName name, String value, IRI identifier) {
|
||||
if ("identifier".equals(name.getLocalPart()) && DefaultResource.isBlank(getResource())) {
|
||||
try {
|
||||
// make sure we can build an opaque IRI, whatever is out there
|
||||
getResource().setId(IRI.create("id:" +
|
||||
PercentEncoders.getRegNameEncoder(StandardCharsets.UTF_8).encode(value)));
|
||||
} catch (IOException e) {
|
||||
// swallow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skip(QName name) {
|
||||
// skip dc:dc element
|
||||
return "dc".equals(name.getLocalPart());
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlHandler<TurtleContentParams> setNamespaceContext(NamespaceContext namespaceContext) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRINamespaceContext getNamespaceContext() {
|
||||
return namespaceContext;
|
||||
}
|
||||
};
|
||||
TurtleContentParams turtleParams = new TurtleContentParams(namespaceContext, true);
|
||||
RdfContentBuilder<TurtleContentParams> builder = turtleBuilder(turtleParams);
|
||||
xmlHandler.setBuilder(builder);
|
||||
new XmlContentParser<TurtleContentParams>(in)
|
||||
.setHandler(xmlHandler)
|
||||
.parse();
|
||||
assertStream("dc.ttl", getClass().getResource("dc.ttl").openStream(),
|
||||
builder.streamInput());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlArray() throws Exception {
|
||||
String filename = "array.xml";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
if (in == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance();
|
||||
XmlContentParams params = new XmlContentParams(namespaceContext);
|
||||
AbstractXmlHandler<NTripleContentParams> xmlHandler = new AbstractXmlResourceHandler<>(params) {
|
||||
|
||||
@Override
|
||||
public boolean isResourceDelimiter(QName name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void identify(QName name, String value, IRI identifier) {
|
||||
getResource().setId(IRI.create("id:1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skip(QName name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlHandler<NTripleContentParams> setNamespaceContext(NamespaceContext namespaceContext) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRINamespaceContext getNamespaceContext() {
|
||||
return namespaceContext;
|
||||
}
|
||||
};
|
||||
|
||||
MyBuilder builder = new MyBuilder();
|
||||
xmlHandler.setDefaultNamespace("xml", "http://xmltest")
|
||||
.setBuilder(builder);
|
||||
DefaultAnonymousResource.reset();
|
||||
new XmlContentParser<NTripleContentParams>(in)
|
||||
.setHandler(xmlHandler)
|
||||
.parse();
|
||||
assertEquals("[id:1 xml:dates _:b2, _:b2 xml:date 2001, _:b2 xml:date 2002, _:b2 xml:date 2003]",
|
||||
builder.getTriples().toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlAttribute() throws Exception {
|
||||
String filename = "attribute.xml";
|
||||
InputStream in = getClass().getResourceAsStream(filename);
|
||||
if (in == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance();
|
||||
XmlContentParams params = new XmlContentParams(namespaceContext);
|
||||
AbstractXmlHandler<NTripleContentParams> xmlHandler = new AbstractXmlResourceHandler<>(params) {
|
||||
@Override
|
||||
public boolean isResourceDelimiter(QName name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void identify(QName name, String value, IRI identifier) {
|
||||
getResource().setId(IRI.create("id:1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skip(QName name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlHandler<NTripleContentParams> setNamespaceContext(NamespaceContext namespaceContext) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRINamespaceContext getNamespaceContext() {
|
||||
return namespaceContext;
|
||||
}
|
||||
};
|
||||
|
||||
MyBuilder builder = new MyBuilder();
|
||||
|
||||
xmlHandler.setDefaultNamespace("xml", "http://localhost")
|
||||
.setBuilder(builder);
|
||||
DefaultAnonymousResource.reset();
|
||||
new XmlContentParser<NTripleContentParams>(in)
|
||||
.setHandler(xmlHandler)
|
||||
.parse();
|
||||
assertEquals("[id:1 xml:dates _:b2, _:b2 xml:date _:b3, _:b3 xml:@href 1, _:b2 xml:date _:b5, "
|
||||
+ "_:b5 xml:@href 2, _:b2 xml:date _:b7, _:b7 xml:@href 3, _:b2 xml:date _:b9, _:b9 xml:hello World]",
|
||||
builder.getTriples().toString()
|
||||
);
|
||||
}
|
||||
|
||||
private static class MyBuilder extends RdfContentBuilder<NTripleContentParams> {
|
||||
|
||||
final List<Triple> triples = new LinkedList<>();
|
||||
|
||||
MyBuilder() throws IOException {
|
||||
super(NTripleContent.nTripleContent(), NTripleContentParams.N_TRIPLE_CONTENT_PARAMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyBuilder receive(Triple triple) {
|
||||
triples.add(triple);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyBuilder receive(Resource resource) throws IOException {
|
||||
triples.addAll(resource.triples());
|
||||
return this;
|
||||
}
|
||||
|
||||
List<Triple> getTriples() {
|
||||
return triples;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for testing XML to RDF.
|
||||
*/
|
||||
package org.xbib.content.rdf.io.xml;
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Classes for testing RDF content.
|
||||
*/
|
||||
package org.xbib.content.rdf;
|
@ -1,4 +1,4 @@
|
||||
package org.xbib.content.rdf;
|
||||
package org.xbib.content.rdf.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import java.io.ByteArrayInputStream;
|
@ -1,20 +1,19 @@
|
||||
package org.xbib.content.rdf.internal;
|
||||
package org.xbib.content.rdf.test.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.Resource;
|
||||
import org.xbib.content.rdf.Triple;
|
||||
import org.xbib.content.rdf.internal.DefaultAnonymousResource;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.resource.IRI;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BlankNodeTest {
|
||||
|
||||
@Test
|
||||
public void testBlankNodeRenumbering() throws Exception {
|
||||
public void testBlankNodeRenumbering() {
|
||||
DefaultAnonymousResource.reset();
|
||||
Resource r = new DefaultResource(IRI.create("urn:meta1"));
|
||||
// test order of adding
|
@ -1,7 +1,8 @@
|
||||
package org.xbib.content.rdf.internal;
|
||||
package org.xbib.content.rdf.test.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.internal.DefaultLiteral;
|
||||
import org.xbib.content.resource.IRI;
|
||||
|
||||
/**
|
@ -1,8 +1,11 @@
|
||||
package org.xbib.content.rdf.internal;
|
||||
package org.xbib.content.rdf.test.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.Resource;
|
||||
import org.xbib.content.rdf.internal.DefaultLiteral;
|
||||
import org.xbib.content.rdf.internal.DefaultResource;
|
||||
import org.xbib.content.rdf.internal.DefaultTriple;
|
||||
import org.xbib.content.resource.IRI;
|
||||
import org.xbib.content.resource.Node;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.xbib.content.rdf.io;
|
||||
package org.xbib.content.rdf.test.io;
|
||||
|
||||
/**
|
||||
*
|
@ -0,0 +1,34 @@
|
||||
package org.xbib.content.rdf.test.io.ntriple;
|
||||
|
||||
import static org.xbib.content.rdf.RdfContentFactory.ntripleBuilder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.content.rdf.RdfContentBuilder;
|
||||
import org.xbib.content.rdf.test.StreamTester;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParams;
|
||||
import org.xbib.content.rdf.io.ntriple.NTripleContentParser;
|
||||
import org.xbib.content.resource.IRINamespaceContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class NTripleReaderTest extends StreamTester {
|
||||
|
||||
@Test
|
||||
public void testReader() throws Exception {
|
||||
String filename = "list.nt";
|
||||
IRINamespaceContext namespaceContext = IRINamespaceContext.newInstance(getClass());
|
||||
NTripleContentParams params = new NTripleContentParams(namespaceContext);
|
||||
try (InputStream inputStream = getClass().getResourceAsStream(filename)) {
|
||||
if (inputStream == null) {
|
||||
throw new IOException("file " + filename + " not found");
|
||||
}
|
||||
RdfContentBuilder<NTripleContentParams> builder = ntripleBuilder(params);
|
||||
NTripleContentParser<NTripleContentParams> reader = new NTripleContentParser<>(params, inputStream);
|
||||
reader.setBuilder(builder);
|
||||
reader.parse();
|
||||
assertStream("", getClass().getResource("rdfxml.ttl").openStream(),
|
||||
builder.streamInput());
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue