Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
change test model extraction to check response media type
  • Loading branch information
barmintor committed Nov 7, 2013
1 parent 6903c9e commit b05db67
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Expand Up @@ -20,14 +20,16 @@
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.parseInt;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.jena.riot.WebContent.contentTypeToLang;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import javax.ws.rs.core.MediaType;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
Expand All @@ -38,6 +40,7 @@
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.fcrepo.http.commons.domain.RDFMediaType;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
Expand Down Expand Up @@ -126,14 +129,19 @@ protected int getStatus(final HttpUriRequest method)
}

protected Model extract(final String serialization) throws IOException {
logger.debug("Reading RDF:\n{}", serialization);
try (

final InputStream rdf =
new ByteArrayInputStream(serialization.getBytes(Charset
.forName("UTF8")))) {
return createDefaultModel().read(rdf, null);
}
return extract(serialization, RDFMediaType.TURTLE_TYPE);
}

protected Model extract(final String serialization,
final MediaType mediaType)
throws IOException {
String lang = contentTypeToLang(mediaType.toString()).getName();
logger.debug("Reading {} RDF:\n{}", lang, serialization);
return createDefaultModel().read(new StringReader(serialization), null,lang);
}

protected static MediaType getMediaType(HttpEntity entity) {
return MediaType.valueOf(entity.getContentType().getValue());
}

}
Expand Up @@ -39,14 +39,14 @@ public void testGetObjectVersionProfile() throws Exception {
final String pid = "FedoraDatastreamsTest1";

execute(postObjMethod(pid));
final HttpGet method =
final HttpGet getVersion =
new HttpGet(serverAddress + pid + "/fcr:versions");
final HttpResponse resp = execute(method);
final HttpResponse resp = execute(getVersion);
final String profile = EntityUtils.toString(resp.getEntity());
assertEquals("Failed to retrieve version profile!\n" + profile, 200,
resp.getStatusLine().getStatusCode());
logger.debug("Retrieved version profile:");
final Model results = extract(profile);
final Model results = extract(profile, getMediaType(resp.getEntity()));
final Resource subject =
createResource(serverAddress + pid + "/fcr:versions");
assertTrue("Didn't find a version triple!", results.contains(subject,
Expand All @@ -72,7 +72,7 @@ public void testAddVersion() throws Exception {
assertEquals("Failed to retrieve new version!\n" + version, 200, resp
.getStatusLine().getStatusCode());
logger.info("Got version profile:");
final Model results = extract(version);
final Model results = extract(version, getMediaType(resp.getEntity()));
assertTrue("Found no version!", results.contains(null,
HAS_PRIMARY_TYPE, "nt:frozenNode"));
}
Expand Down

0 comments on commit b05db67

Please sign in to comment.