Skip to content

Commit

Permalink
Added test for mutate datastream content
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 6, 2013
1 parent 7ed1c9a commit 460a650
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
49 changes: 35 additions & 14 deletions src/test/java/org/fcrepo/modeshape/FedoraDatastreamsTest.java
@@ -1,6 +1,8 @@
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;
Expand All @@ -10,15 +12,21 @@
import org.apache.commons.httpclient.methods.StringRequestEntity;
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;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/testContext.xml")
public class FedoraDatastreamsTest {

private static final String faulkner1 = "The past is never dead. It's not even past.";
int SERVER_PORT = 9999;

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

@Test
public void testGetDatastreams() throws Exception {
HttpClient client = new HttpClient();
Expand Down Expand Up @@ -53,19 +61,32 @@ public void testMutateDatastream() throws Exception {

HttpClient client = new HttpClient();

PostMethod pmethod = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf2");
client.executeMethod(pmethod);

PostMethod method = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf2/datastreams/vcxz");
int status = client.executeMethod(method);
assertEquals(201, status);

PutMethod method_2 = new PutMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf2/datastreams/vcxz");
status = client.executeMethod(method_2);
assertEquals(201, status);
PostMethod createObjectMethod = new PostMethod("http://localhost:"
+ SERVER_PORT + "/objects/asdf2");
Integer status = client.executeMethod(createObjectMethod);
assertEquals("Couldn't create an object!", (Integer) 201, status);

PostMethod createDataStreamMethod = new PostMethod("http://localhost:"
+ SERVER_PORT + "/objects/asdf2/datastreams/vcxz");
status = client.executeMethod(createDataStreamMethod);
assertEquals("Couldn't create a datastream!", (Integer) 201, status);

PutMethod mutateDataStreamMethod = new PutMethod("http://localhost:"
+ SERVER_PORT + "/objects/asdf2/datastreams/vcxz");
mutateDataStreamMethod.setRequestEntity(new StringRequestEntity(
faulkner1, "text/plain", "UTF-8"));
status = client.executeMethod(mutateDataStreamMethod);
assertEquals("Couldn't mutate a datastream!", (Integer) 201, status);

GetMethod retrieveMutatedDataStreamMethod = new GetMethod(
"http://localhost:" + SERVER_PORT
+ "/objects/asdf2/datastreams/vcxz/content");
client.executeMethod(retrieveMutatedDataStreamMethod);
String response = retrieveMutatedDataStreamMethod
.getResponseBodyAsString();
logger.debug("Retrieved mutated datastream content: " + response);
assertTrue("Datastream didn't accept mutation!", compile(faulkner1)
.matcher(response).find());
}

@Test
Expand Down Expand Up @@ -141,7 +162,7 @@ public void testGetDatastreamContent() throws Exception {
+ SERVER_PORT
+ "/objects/testfoo/datastreams/testfoozle/content");
assertEquals(200, client.executeMethod(method_test_get));
assertEquals("marbles for everyone",
assertEquals("Got the wrong content back!", "marbles for everyone",
method_test_get.getResponseBodyAsString());

}
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/fcrepo/modeshape/FedoraIdentifiersTest.java
@@ -1,10 +1,11 @@
package org.fcrepo.modeshape;

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

import java.io.IOException;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletResponse;

Expand Down Expand Up @@ -49,7 +50,7 @@ public void testGetNextHasAPid() throws HttpException, IOException {
String response = method.getResponseBodyAsString(Integer.MAX_VALUE);
logger.debug("Only to find:\n" + response);
assertTrue("Didn't find a single dang PID!",
Pattern.compile("<pid>.*?</pid>").matcher(response).find());
compile("<pid>.*?</pid>", DOTALL).matcher(response).find());
}

@Test
Expand All @@ -64,7 +65,7 @@ public void testGetNextHasTwoPids() throws HttpException, IOException {
logger.debug("Only to find:\n" + response);
assertTrue(
"Didn't find a two dang PIDs!",
Pattern.compile("<pid>.*?</pid>.*?<pid>.*?</pid>",
Pattern.DOTALL).matcher(response).find());
compile("<pid>.*?</pid>.*?<pid>.*?</pid>", DOTALL).matcher(
response).find());
}
}
7 changes: 2 additions & 5 deletions src/test/java/org/fcrepo/modeshape/FedoraRepositoryTest.java
@@ -1,13 +1,10 @@
package org.fcrepo.modeshape;

import static java.util.regex.Pattern.compile;
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.regex.Pattern;

import javax.ws.rs.core.MediaType;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.junit.Test;
Expand Down Expand Up @@ -55,7 +52,7 @@ public void testDescribe() throws Exception {
final String description = method.getResponseBodyAsString();
logger.debug("Found a repository description:\n" + description);
assertTrue("Failed to find a proper repo versiom",
Pattern.compile("<repositoryVersion>.*?</repositoryVersion>")
compile("<repositoryVersion>.*?</repositoryVersion>")
.matcher(description).find());
}
}

0 comments on commit 460a650

Please sign in to comment.