Skip to content

Commit

Permalink
test fixup to deal with previously-created PIDs better
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Nov 11, 2013
1 parent d5bc9d1 commit 6e883c8
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 147 deletions.
Expand Up @@ -106,15 +106,15 @@ public Response modifyDatastreams(@PathParam("path")
final String path = toPath(pathList);
try {
for (final String dsid : dsidList) {
logger.debug("Purging datastream: " + dsid);
logger.debug("Purging datastream: {}", dsid);
nodeService.deleteObject(session, path + "/" + dsid);
}

for (final BodyPart part : multipart.getBodyParts()) {
final String dsid =
part.getContentDisposition().getParameters()
.get("name");
logger.debug("Adding datastream: " + dsid);
logger.debug("Adding datastream: {}", dsid);
final String dsPath = path + "/" + dsid;
final Object obj = part.getEntity();
InputStream src = null;
Expand Down
Expand Up @@ -51,6 +51,7 @@

import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.api.rdf.HttpGraphSubjects;
import org.fcrepo.kernel.rdf.SerializationUtils;
import org.springframework.context.annotation.Scope;

import com.codahale.metrics.annotation.Timed;
Expand Down Expand Up @@ -119,7 +120,7 @@ public Dataset getNextPid(@PathParam("path")
model.add(pidsResult, HAS_MEMBER_OF_RESULT, s);
}

return create(model).toDataset();
return SerializationUtils.setDatasetSubject(create(model).toDataset(), path);

}
}
Expand Up @@ -21,12 +21,14 @@
import static java.lang.Integer.parseInt;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.jena.riot.WebContent.contentTypeToLang;
import static org.junit.Assert.assertEquals;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import org.apache.http.HttpEntity;
Expand Down Expand Up @@ -139,7 +141,16 @@ protected Model extract(final String serialization,
logger.debug("Reading {} RDF:\n{}", lang, serialization);
return createDefaultModel().read(new StringReader(serialization), null,lang);
}


public String getTestObjectPath(String parent) throws ClientProtocolException, IOException {
final HttpPost createObjMethod =
postObjMethod(parent);
HttpResponse response = execute(createObjMethod);
assertEquals(201, response.getStatusLine().getStatusCode());
String objPath = response.getFirstHeader(HttpHeaders.LOCATION).getValue();
return objPath.substring(serverAddress.length());
}

protected static MediaType getMediaType(HttpEntity entity) {
return MediaType.valueOf(entity.getContentType().getValue());
}
Expand Down
Expand Up @@ -20,14 +20,19 @@
import static com.hp.hpl.jena.graph.NodeFactory.createURI;
import static java.util.regex.Pattern.DOTALL;
import static java.util.regex.Pattern.compile;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.OK;
import static junit.framework.TestCase.assertFalse;
import static org.fcrepo.http.commons.test.util.TestHelpers.parseTriples;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import javax.ws.rs.core.HttpHeaders;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
Expand All @@ -44,28 +49,26 @@ public class FedoraDatastreamsIT extends AbstractResourceIT {

@Test
public void testMultipleDatastreams() throws Exception {
final HttpPost createObjMethod =
postObjMethod("FedoraDatastreamsTest7");
assertEquals(201, getStatus(createObjMethod));

String objPath = getTestObjectPath("FedoraDatastreamsTest7");
final HttpPost createDS1Method =
postDSMethod("FedoraDatastreamsTest7", "ds1",
postDSMethod(objPath, "ds1",
"marbles for everyone");
assertEquals(201, getStatus(createDS1Method));
assertEquals(CREATED.getStatusCode(), getStatus(createDS1Method));
final HttpPost createDS2Method =
postDSMethod("FedoraDatastreamsTest7", "ds2",
postDSMethod(objPath, "ds2",
"marbles for no one");
assertEquals(201, getStatus(createDS2Method));
assertEquals(CREATED.getStatusCode(), getStatus(createDS2Method));

final HttpGet getDSesMethod =
new HttpGet(serverAddress + "FedoraDatastreamsTest7");
new HttpGet(serverAddress + objPath);
getDSesMethod.addHeader(HttpHeaders.ACCEPT, RDFMediaType.N3_TEXT);
final HttpResponse response = client.execute(getDSesMethod);
HttpResponse response = client.execute(getDSesMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
final GraphStore result =
parseTriples(response.getEntity().getContent());
logger.debug("Received triples: \n{}", result.toString());
final String subjectURI = serverAddress + "FedoraDatastreamsTest7";
final String subjectURI = serverAddress + objPath;

assertTrue("Didn't find the first datastream! ", result.contains(ANY,
createURI(subjectURI), ANY, createURI(subjectURI + "/ds1")));
Expand All @@ -75,18 +78,17 @@ public void testMultipleDatastreams() throws Exception {

@Test
public void testModifyMultipleDatastreams() throws Exception {
final HttpPost objMethod = postObjMethod("FedoraDatastreamsTest8");
String objPath = getTestObjectPath("FedoraDatastreamsTest8");

assertEquals(201, getStatus(objMethod));

final HttpPost createDSVOIDMethod =
postDSMethod("FedoraDatastreamsTest8", "ds_void",
postDSMethod(objPath, "ds_void",
"marbles for everyone");
assertEquals(201, getStatus(createDSVOIDMethod));
assertEquals(CREATED.getStatusCode(), getStatus(createDSVOIDMethod));

final HttpPost post =
new HttpPost(serverAddress
+ "FedoraDatastreamsTest8/fcr:datastreams?delete=ds_void");
new HttpPost(serverAddress + objPath
+ "/fcr:datastreams?delete=ds_void");

final MultipartEntity multiPartEntity = new MultipartEntity();
multiPartEntity.addPart("ds1", new StringBody("asdfg"));
Expand All @@ -96,15 +98,15 @@ public void testModifyMultipleDatastreams() throws Exception {

final HttpResponse postResponse = client.execute(post);

assertEquals(201, postResponse.getStatusLine().getStatusCode());
assertEquals(CREATED.getStatusCode(), postResponse.getStatusLine().getStatusCode());

final HttpGet getDSesMethod =
new HttpGet(serverAddress + "FedoraDatastreamsTest8");
new HttpGet(serverAddress + objPath);
getDSesMethod.addHeader(HttpHeaders.ACCEPT, RDFMediaType.N3_TEXT);
final HttpResponse response = client.execute(getDSesMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(OK.getStatusCode(), response.getStatusLine().getStatusCode());

final String subjectURI = serverAddress + "FedoraDatastreamsTest8";
final String subjectURI = serverAddress + objPath;
final GraphStore result =
parseTriples(response.getEntity().getContent());
assertTrue("Didn't find the first datastream! ", result.contains(ANY,
Expand All @@ -119,11 +121,10 @@ public void testModifyMultipleDatastreams() throws Exception {
@Test
public void testRetrieveMultipartDatastreams() throws Exception {

final HttpPost objMethod = postObjMethod("FedoraDatastreamsTest9");
assertEquals(201, getStatus(objMethod));
String objPath = getTestObjectPath("FedoraDatastreamsTest9");
String datastreamsUri = serverAddress + objPath + "/fcr:datastreams";
final HttpPost post =
new HttpPost(serverAddress
+ "FedoraDatastreamsTest9/fcr:datastreams/");
new HttpPost(datastreamsUri.concat("/"));

final MultipartEntity multiPartEntity = new MultipartEntity();
multiPartEntity.addPart("ds1", new StringBody("asdfg"));
Expand All @@ -132,15 +133,14 @@ public void testRetrieveMultipartDatastreams() throws Exception {
post.setEntity(multiPartEntity);

final HttpResponse postResponse = client.execute(post);
assertEquals(201, postResponse.getStatusLine().getStatusCode());
assertEquals(CREATED.getStatusCode(), postResponse.getStatusLine().getStatusCode());

// TODO: we should actually evaluate the multipart response for the
// things we're expecting
final HttpGet getDSesMethod =
new HttpGet(serverAddress
+ "FedoraDatastreamsTest9/fcr:datastreams");
new HttpGet(datastreamsUri);
final HttpResponse response = client.execute(getDSesMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(OK.getStatusCode(), response.getStatusLine().getStatusCode());
final String content = EntityUtils.toString(response.getEntity());

assertTrue("Didn't find the first datastream!",
Expand All @@ -151,13 +151,12 @@ public void testRetrieveMultipartDatastreams() throws Exception {
}

@Test
public void testRetrieveFIlteredMultipartDatastreams() throws Exception {
public void testRetrieveFilteredMultipartDatastreams() throws Exception {

final HttpPost objMethod = postObjMethod("FedoraDatastreamsTest10");
assertEquals(201, getStatus(objMethod));
String objPath = getTestObjectPath("FedoraDatastreamsTest10");
String datastreamsUri = serverAddress + objPath + "/fcr:datastreams";
final HttpPost post =
new HttpPost(serverAddress
+ "FedoraDatastreamsTest10/fcr:datastreams");
new HttpPost(datastreamsUri.concat("/"));

final MultipartEntity multiPartEntity = new MultipartEntity();
multiPartEntity.addPart("ds1", new StringBody("asdfg"));
Expand All @@ -166,15 +165,14 @@ public void testRetrieveFIlteredMultipartDatastreams() throws Exception {
post.setEntity(multiPartEntity);

final HttpResponse postResponse = client.execute(post);
assertEquals(201, postResponse.getStatusLine().getStatusCode());
assertEquals(CREATED.getStatusCode(), postResponse.getStatusLine().getStatusCode());

// TODO: we should actually evaluate the multipart response for the
// things we're expecting
final HttpGet getDSesMethod =
new HttpGet(serverAddress
+ "FedoraDatastreamsTest10/fcr:datastreams?dsid=ds1");
new HttpGet(datastreamsUri.concat("?dsid=ds1"));
final HttpResponse response = client.execute(getDSesMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(OK.getStatusCode(), response.getStatusLine().getStatusCode());
final String content = EntityUtils.toString(response.getEntity());

assertTrue("Didn't find the first datastream!",
Expand All @@ -186,25 +184,34 @@ public void testRetrieveFIlteredMultipartDatastreams() throws Exception {

@Test
public void testBatchDeleteDatastream() throws Exception {
execute(postObjMethod("FedoraDatastreamsTest12"));
String objPath = getTestObjectPath("FedoraDatastreamsTest11");
final HttpPost method1 =
postDSMethod("FedoraDatastreamsTest12", "ds1", "foo1");
assertEquals(201, getStatus(method1));
postDSMethod(objPath, "ds1", "foo1");
assertEquals(CREATED.getStatusCode(), getStatus(method1));
final HttpPost method2 =
postDSMethod("FedoraDatastreamsTest12", "ds2", "foo2");
assertEquals(201, getStatus(method2));
postDSMethod(objPath, "ds2", "foo2");
assertEquals(CREATED.getStatusCode(), getStatus(method2));

final HttpDelete dmethod =
new HttpDelete(
serverAddress
+ "FedoraDatastreamsTest12/fcr:datastreams?dsid=ds1&dsid=ds2");
serverAddress + objPath
+ "/fcr:datastreams?dsid=ds1&dsid=ds2");
assertEquals(204, getStatus(dmethod));

final HttpGet method_test_get1 =
new HttpGet(serverAddress + "FedoraDatastreamsTest12/ds1");
new HttpGet(serverAddress + objPath + "/ds1");
assertEquals(404, getStatus(method_test_get1));
final HttpGet method_test_get2 =
new HttpGet(serverAddress + "FedoraDatastreamsTest12/ds2");
new HttpGet(serverAddress + objPath + "/ds2");
assertEquals(404, getStatus(method_test_get2));
}

public String getTestObjectPath(String parent) throws ClientProtocolException, IOException {
final HttpPost createObjMethod =
postObjMethod(parent);
HttpResponse response = execute(createObjMethod);
assertEquals(201, response.getStatusLine().getStatusCode());
String objPath = response.getFirstHeader(HttpHeaders.LOCATION).getValue();
return objPath.substring(serverAddress.length());
}
}

0 comments on commit 6e883c8

Please sign in to comment.