Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to test the sparql recipes with both snapshot 4.0.0-beta-03 and snapshot 4.0.0-beta-04-SNAPSHOT. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions src/test/java/org/fcrepo/it/SparqlRecipesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* The tests mirror the manual tests described on the Fedora 4 wiki.
* https://wiki.duraspace.org/display/FF/SPARQL+Recipes
*
* @author lsitu
* @author Mike Durbin
* @since Sep 19, 2014
*/
Expand All @@ -43,9 +44,13 @@ public class SparqlRecipesIT {

private static String CARGO_PORT = System.getProperty("cargo.port");

protected static HttpClient client = createClient();
private static short FCREPO_SNAPSHOT_NUMBER = 4;
private static String DATASTREAM_URL_SUFIX = "/fcr:metadata";
private static String DATASTREAM_CONTENT_URL_SUFIX = "";

protected static HttpClient createClient() {
private static HttpClient client = createClient();

private static HttpClient createClient() {
return HttpClientBuilder.create().setMaxConnPerRoute(MAX_VALUE)
.setMaxConnTotal(MAX_VALUE).build();
}
Expand All @@ -54,8 +59,29 @@ protected static HttpClient createClient() {

@BeforeClass
public static void startFuseki() throws InterruptedException, IOException {
File commandFile = new File("target/jena-fuseki-1.0.1/fuseki-server");
ProcessBuilder b = new ProcessBuilder().inheritIO()

//Determine the snapshot used for testing and its REST api,
//make it default for snapshot 4 for the current version
final String fcrepoSnapshot = System.getProperty("fcrepo.version");
if (fcrepoSnapshot != null
&& fcrepoSnapshot.indexOf("-") > 0
&& fcrepoSnapshot.indexOf("4.0.0-beta") >= 0) {
final String[] verTokens = fcrepoSnapshot.split("-");
if (verTokens.length >= 3) {
try {
FCREPO_SNAPSHOT_NUMBER = Short.parseShort(verTokens[2]);
} catch (final NumberFormatException ne) {
FCREPO_SNAPSHOT_NUMBER = 4;
}
}
}
if (FCREPO_SNAPSHOT_NUMBER < 4) {
DATASTREAM_URL_SUFIX = "";
DATASTREAM_CONTENT_URL_SUFIX = "/fcr:content";
}

final File commandFile = new File("target/jena-fuseki-1.0.1/fuseki-server");
final ProcessBuilder b = new ProcessBuilder().inheritIO()
.directory(commandFile.getParentFile())
.command("./fuseki-server", "--update", "--mem", "/test" );
fuseki = b.start();
Expand Down Expand Up @@ -105,16 +131,20 @@ public static void setUpTestObjects() throws IOException, InterruptedException {
System.out.println("Adding test objects...");
putObject(pid101);
markAsIndexable(pid101);
putDummyDatastream(pid101 + "/master/fcr:content", "application/pdf");
putDummyDatastream(pid101 + "/master" + DATASTREAM_CONTENT_URL_SUFIX, "application/pdf");
markAsIndexable(pid101 + "/master" + DATASTREAM_URL_SUFIX);

putObject(pid102);
markAsIndexable(pid102);
putDummyDatastream(pid102 + "/master/fcr:content", "text/plain");
putDummyDatastream(pid102 + "/master" + DATASTREAM_CONTENT_URL_SUFIX, "text/plain");
markAsIndexable(pid102 + "/master" + DATASTREAM_URL_SUFIX);

putObject(pid103);
markAsIndexable(pid103);
putDummyDatastream(pid103 + "/master/fcr:content", "application/pdf");
putDummyDatastream(pid103 + "/text/fcr:content", "text/plain");
putDummyDatastream(pid103 + "/master" + DATASTREAM_CONTENT_URL_SUFIX, "application/pdf");
putDummyDatastream(pid103 + "/text" + DATASTREAM_CONTENT_URL_SUFIX, "text/plain");
markAsIndexable(pid103 + "/text" + DATASTREAM_URL_SUFIX);
markAsIndexable(pid103 + "/master" + DATASTREAM_URL_SUFIX);

putObject(pid201);
markAsIndexable(pid201);
Expand Down Expand Up @@ -158,7 +188,7 @@ public void testSparqlQueries1() throws IOException, InterruptedException {
"select ?object where { \n" +
" ?ds fcrepo:mixinTypes \"fedora:datastream\" .\n" +
" ?ds fcrepo:hasParent ?object . \n" +
" filter(str(?ds)=concat(str(?object),'/text')) \n" +
" filter(str(?ds)=concat(str(?object),'/text" + DATASTREAM_URL_SUFIX + "')) \n" +
"}";
final ByteArrayOutputStream response1b = new ByteArrayOutputStream();
queryFuseki(fusekiQuery1b).getEntity().writeTo(response1b);
Expand Down Expand Up @@ -324,11 +354,11 @@ private static class FusekiResponse {
final private List<List<String>> rows;

public FusekiResponse(final String csvResponse) {
String[] rowArray = csvResponse.split("\\n");
final String[] rowArray = csvResponse.split("\\n");
this.rows = new ArrayList<List<String>>();
for (String row : rowArray) {
ArrayList<String> rowList = new ArrayList<String>();
for (String cell : row.split(",")) {
for (final String row : rowArray) {
final ArrayList<String> rowList = new ArrayList<String>();
for (final String cell : row.split(",")) {
rowList.add(cell.trim());
}
this.rows.add(rowList);
Expand Down