Skip to content

Commit

Permalink
Factoring HTTP client for tests from variable into field for efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 6, 2013
1 parent 460a650 commit 39130f5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
17 changes: 1 addition & 16 deletions src/test/java/org/fcrepo/modeshape/FedoraDatastreamsTest.java
Expand Up @@ -26,11 +26,10 @@ public class FedoraDatastreamsTest {

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

@Test
public void testGetDatastreams() throws Exception {
HttpClient client = new HttpClient();

PostMethod pmethod = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf");
client.executeMethod(pmethod);
Expand All @@ -43,9 +42,6 @@ public void testGetDatastreams() throws Exception {

@Test
public void testAddDatastream() throws Exception {

HttpClient client = new HttpClient();

PostMethod pmethod = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf");
client.executeMethod(pmethod);
Expand All @@ -58,9 +54,6 @@ public void testAddDatastream() throws Exception {

@Test
public void testMutateDatastream() throws Exception {

HttpClient client = new HttpClient();

PostMethod createObjectMethod = new PostMethod("http://localhost:"
+ SERVER_PORT + "/objects/asdf2");
Integer status = client.executeMethod(createObjectMethod);
Expand Down Expand Up @@ -91,9 +84,6 @@ public void testMutateDatastream() throws Exception {

@Test
public void testGetDatastream() throws Exception {

HttpClient client = new HttpClient();

PostMethod pmethod = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf");
client.executeMethod(pmethod);
Expand All @@ -116,9 +106,6 @@ public void testGetDatastream() throws Exception {

@Test
public void testDeleteDatastream() throws Exception {

HttpClient client = new HttpClient();

PostMethod pmethod = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf");
client.executeMethod(pmethod);
Expand Down Expand Up @@ -146,8 +133,6 @@ public void testDeleteDatastream() throws Exception {

@Test
public void testGetDatastreamContent() throws Exception {
final HttpClient client = new HttpClient();

final PostMethod pmethod = new PostMethod("http://localhost:"
+ SERVER_PORT + "/objects/testfoo");
client.executeMethod(pmethod);
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/fcrepo/modeshape/FedoraIdentifiersTest.java
Expand Up @@ -28,9 +28,10 @@ public class FedoraIdentifiersTest {

int SERVER_PORT = 9999;

final private HttpClient client = new HttpClient();

@Test
public void testGetNextPidResponds() throws Exception {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://localhost:" + SERVER_PORT
+ "/nextPID");
method.addRequestHeader("Accepts", "text/xml");
Expand All @@ -41,7 +42,6 @@ public void testGetNextPidResponds() throws Exception {

@Test
public void testGetNextHasAPid() throws HttpException, IOException {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://localhost:" + SERVER_PORT
+ "/nextPID?numPids=1");
method.addRequestHeader("Accepts", "text/xml");
Expand All @@ -55,7 +55,6 @@ public void testGetNextHasAPid() throws HttpException, IOException {

@Test
public void testGetNextHasTwoPids() throws HttpException, IOException {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://localhost:" + SERVER_PORT
+ "/nextPID?numPids=2");
method.addRequestHeader("Accepts", "text/xml");
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/org/fcrepo/modeshape/FedoraObjectsTest.java
Expand Up @@ -16,10 +16,11 @@
public class FedoraObjectsTest {

int SERVER_PORT = 9999;


final private HttpClient client = new HttpClient();

@Test
public void testIngest() throws Exception {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf");
int status = client.executeMethod(method);
Expand All @@ -28,7 +29,6 @@ public void testIngest() throws Exception {

@Test
public void testGetObjectInXML() throws Exception {
HttpClient client = new HttpClient();
PostMethod pmethod = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/fdsa");
client.executeMethod(pmethod);
Expand All @@ -41,7 +41,6 @@ public void testGetObjectInXML() throws Exception {

@Test
public void testDeleteObject() throws Exception {
HttpClient client = new HttpClient();
PostMethod pmethod = new PostMethod("http://localhost:" + SERVER_PORT
+ "/objects/asdf");
client.executeMethod(pmethod);
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/fcrepo/modeshape/FedoraRepositoryTest.java
Expand Up @@ -23,9 +23,10 @@ public class FedoraRepositoryTest {
final private Logger logger = LoggerFactory
.getLogger(FedoraRepositoryTest.class);

final private HttpClient client = new HttpClient();

@Test
public void testDescribeModeshape() throws Exception {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://localhost:" + SERVER_PORT
+ "/describe/modeshape");
int status = client.executeMethod(method);
Expand All @@ -34,7 +35,6 @@ public void testDescribeModeshape() throws Exception {

@Test
public void testGetObjects() throws Exception {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://localhost:" + SERVER_PORT
+ "/objects");
int status = client.executeMethod(method);
Expand All @@ -43,16 +43,16 @@ public void testGetObjects() throws Exception {

@Test
public void testDescribe() throws Exception {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://localhost:" + SERVER_PORT
+ "/describe");
method.addRequestHeader("Accept", TEXT_XML);
int status = client.executeMethod(method);
assertEquals(200, status);
final String description = method.getResponseBodyAsString();
logger.debug("Found a repository description:\n" + description);
assertTrue("Failed to find a proper repo versiom",
compile("<repositoryVersion>.*?</repositoryVersion>")
.matcher(description).find());
assertTrue(
"Failed to find a proper repo versiom",
compile("<repositoryVersion>.*?</repositoryVersion>").matcher(
description).find());
}
}

0 comments on commit 39130f5

Please sign in to comment.