Skip to content

Commit

Permalink
Added test to check that objects are saved with the PIDs with which t…
Browse files Browse the repository at this point in the history
…hey are offered
  • Loading branch information
ajs6f committed Feb 6, 2013
1 parent 39130f5 commit 664c1e3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/fcrepo/modeshape/FedoraObjects.java
Expand Up @@ -97,6 +97,7 @@ public Response getObject(@PathParam("pid") final String pid)
final Node obj = session.getNode("/" + pid);
final ObjectProfile objectProfile = new ObjectProfile();

objectProfile.pid = pid;
objectProfile.objLabel = obj.getName();
objectProfile.objOwnerId = obj.getProperty("fedora:ownerId")
.getString();
Expand Down
Expand Up @@ -3,13 +3,17 @@
import java.net.URI;
import java.util.Collection;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "objectProfile", namespace = "http://www.fedora.info/definitions/1/0/access/")
public class ObjectProfile {

@XmlAttribute
public String pid;

@XmlElement
public String objLabel;

Expand Down
38 changes: 27 additions & 11 deletions src/test/java/org/fcrepo/modeshape/FedoraObjectsTest.java
@@ -1,13 +1,17 @@
package org.fcrepo.modeshape;

import static java.util.regex.Pattern.compile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

Expand All @@ -17,6 +21,9 @@ public class FedoraObjectsTest {

int SERVER_PORT = 9999;

final private Logger logger = LoggerFactory
.getLogger(FedoraObjectsTest.class);

final private HttpClient client = new HttpClient();

@Test
Expand All @@ -29,26 +36,35 @@ public void testIngest() throws Exception {

@Test
public void testGetObjectInXML() throws Exception {
PostMethod pmethod = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/fdsa");
client.executeMethod(pmethod);
PostMethod createObjMethod = new PostMethod("http://localhost:"
+ SERVER_PORT + "/objects/fdsa");
client.executeMethod(createObjMethod);

GetMethod method = new GetMethod("http://localhost:" + SERVER_PORT
+ "/objects/fdsa");
int status = client.executeMethod(method);
GetMethod getObjMethod = new GetMethod("http://localhost:"
+ SERVER_PORT + "/objects/fdsa");
int status = client.executeMethod(getObjMethod);
assertEquals(200, status);
String response = getObjMethod.getResponseBodyAsString();
logger.debug("Retrieved object profile:\n" + response);
assertTrue("Object had wrong PID!",
compile("pid=\"fdsa\"").matcher(response).find());
}

@Test
public void testDeleteObject() throws Exception {
PostMethod pmethod = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf");
client.executeMethod(pmethod);
PostMethod createObjmethod = new PostMethod("http://localhost:"
+ SERVER_PORT + "/objects/asdf");
client.executeMethod(createObjmethod);

DeleteMethod method = new DeleteMethod("http://localhost:"
DeleteMethod delMethod = new DeleteMethod("http://localhost:"
+ SERVER_PORT + "/objects/asdf");
int status = client.executeMethod(method);
int status = client.executeMethod(delMethod);
assertEquals(204, status);

GetMethod getMethod = new GetMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf");
status = client.executeMethod(getMethod);
assertEquals("Object wasn't really deleted!", 404, status);
}

}

0 comments on commit 664c1e3

Please sign in to comment.