-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ITs that pass with RDF4J 2.2.2, but fail with 2.2.4. (#222)
* Use an empty base url; none of the URIs are relative in the data. * Share HTTP-based methods for depositing and updating discos in BaseHttpIT. * Prepare BaseHttpIT for additonal integration tests - Utility classes with methods for manipulating RDF and working with OkHttp - Additional properties for working with the RDF4J server * IT which queries the RDF4J "size" endpoint, which counts the number of statements in a context. Related to #221
- Loading branch information
1 parent
4c73d95
commit 11c8a92
Showing
7 changed files
with
462 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
integration/src/test/java/info/rmapproject/integration/OkHttpUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package info.rmapproject.integration; | ||
|
||
import okhttp3.Request; | ||
import okio.Buffer; | ||
import org.apache.commons.io.input.NullInputStream; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Utilities for working with the OkHttp platform. | ||
*/ | ||
class OkHttpUtil { | ||
|
||
/** | ||
* Returns true if the supplied request builder has a body. | ||
* | ||
* @param reqBuilder | ||
* @return | ||
*/ | ||
static boolean hasBody(Request.Builder reqBuilder) { | ||
Request req = reqBuilder.build(); | ||
return req.body() != null; | ||
} | ||
|
||
/** | ||
* Obtain an InputStream to the request body. | ||
* | ||
* @param reqBuilder the request builder that may have a body | ||
* @return a (potentially empty) InputStream for the request body | ||
*/ | ||
static InputStream getBody(Request.Builder reqBuilder) { | ||
if (!hasBody(reqBuilder)) { | ||
return new NullInputStream(0L); | ||
} | ||
|
||
Request req = reqBuilder.build(); | ||
Buffer buf = new Buffer(); | ||
try { | ||
req.body().writeTo(buf); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Unable to read HTTP body: " + e.getMessage(), e); | ||
} | ||
|
||
return buf.inputStream(); | ||
} | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
integration/src/test/java/info/rmapproject/integration/Rdf4jUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package info.rmapproject.integration; | ||
|
||
import org.apache.commons.io.output.ByteArrayOutputStream; | ||
import org.eclipse.rdf4j.model.Model; | ||
import org.eclipse.rdf4j.model.Statement; | ||
import org.eclipse.rdf4j.model.impl.LinkedHashModel; | ||
import org.eclipse.rdf4j.repository.RepositoryConnection; | ||
import org.eclipse.rdf4j.repository.RepositoryResult; | ||
import org.eclipse.rdf4j.rio.RDFFormat; | ||
import org.eclipse.rdf4j.rio.RDFParser; | ||
import org.eclipse.rdf4j.rio.RDFWriter; | ||
import org.eclipse.rdf4j.rio.Rio; | ||
import org.eclipse.rdf4j.rio.helpers.StatementCollector; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* Utility methods for working with the RDF4J platform. | ||
*/ | ||
class Rdf4jUtil { | ||
|
||
/** | ||
* Reads the supplied RDF into an RDF4J {@link Model}. | ||
* | ||
* @param rdfIn the RDF to read into the {@code Model} | ||
* @param format the format that the RDF is in | ||
* @param baseUri the URI used to resolve any relative URI references in the supplied RDF | ||
* @return | ||
*/ | ||
static Model readModel(InputStream rdfIn, RDFFormat format, String baseUri) { | ||
RDFParser parser = Rio.createParser(format); | ||
Model model = new LinkedHashModel(); | ||
parser.setRDFHandler(new StatementCollector(model)); | ||
|
||
try { | ||
parser.parse(rdfIn, baseUri); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Unable to create an RDF Model: " + e.getMessage(), e); | ||
} | ||
|
||
return model; | ||
} | ||
|
||
/** | ||
* Converts RDF from the format in {@code fromFormat} to the format specified by {@code toFormat}. | ||
* | ||
* @param from the source RDF | ||
* @param fromFormat the format of the source RDF | ||
* @param baseUri the base URI used to resolve any relative URI references in the source RDF | ||
* @param toFormat the format to convert the RDF to | ||
* @return an InputStream to the converted RDF | ||
*/ | ||
static InputStream convertRdf(InputStream from, RDFFormat fromFormat, String baseUri, RDFFormat toFormat) { | ||
if (fromFormat == toFormat) { | ||
return from; | ||
} | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(8192); | ||
Model m = readModel(from, fromFormat, baseUri); | ||
RDFWriter writer = Rio.createWriter(toFormat, out); | ||
writer.startRDF(); | ||
m.forEach(writer::handleStatement); | ||
writer.endRDF(); | ||
try { | ||
out.close(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Unable to close output stream after writing RDF: " + e.getMessage(), e); | ||
} | ||
|
||
return new ByteArrayInputStream(out.toByteArray()); | ||
} | ||
|
||
|
||
/** | ||
* Dumps the contents of the triplestore to the provided output stream. | ||
* | ||
* @param connection the connection to the triplestore | ||
* @param outputStream the output stream which contains the dumped triples | ||
*/ | ||
public static void dumpTriplestore(RepositoryConnection connection, OutputStream outputStream) { | ||
RepositoryResult<Statement> result = connection.getStatements(null, null, null, true); | ||
while (result.hasNext()) { | ||
try { | ||
outputStream.write(result.next().toString().getBytes("UTF-8")); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error encoding bytes from the triplestore to UTF-8: " + e.getMessage(), e); | ||
} | ||
|
||
try { | ||
outputStream.write("\n".getBytes()); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error writing the triples to the output stream: " + e.getMessage(), e); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.