Skip to content
Browse files

Servlet tests do not require plain text responses anymore.

  • Loading branch information...
1 parent fa35063 commit 1e7dd99cfcc62df4749010b5b20d17338a695e4d @nielsAD nielsAD committed May 25, 2012
View
44 program/WEB-INF/src/synthbio/servlets/test/TestCircuitServlet.java
@@ -28,7 +28,6 @@
import synthbio.Util;
-import com.gargoylesoftware.htmlunit.TextPage;
import com.gargoylesoftware.htmlunit.WebClient;
/**
@@ -42,20 +41,20 @@
*/
public static final String url="http://localhost:8080/Circuit";
- public TextPage getTestPage(String url) throws Exception{
+ public String getTestPage(String url) throws Exception{
final WebClient webClient = new WebClient();
- return webClient.getPage(url);
+ return webClient.getPage(url).getWebResponse().getContentAsString().trim();
}
/**
* Check if an error message is returned if no action is supplied.
*/
@Test
public void testNoAction() throws Exception{
- TextPage page=this.getTestPage(this.url);
+ String page=this.getTestPage(this.url);
String expected="Parameter 'action' not set.";
- assertThat(page.getContent(), containsString(expected));
+ assertThat(page, containsString(expected));
}
/**
@@ -67,9 +66,9 @@ public void testNoAction() throws Exception{
*/
@Test
public void testList() throws Exception{
- TextPage page=this.getTestPage(this.url+"?action=list");
+ String page=this.getTestPage(this.url+"?action=list");
- JSONObject response=new JSONObject(page.getContent());
+ JSONObject response=new JSONObject(page);
//check success and empty message string.
assertTrue(response.getBoolean("success"));
@@ -89,17 +88,16 @@ public void testList() throws Exception{
}
//check that the file list contains 'example.syn'
- assertThat(page.getContent(), containsString("example.syn"));
+ assertThat(page, containsString("example.syn"));
}
/**
* Test the loadFile action
*/
@Test
public void testLoad() throws Exception{
- TextPage page=this.getTestPage(this.url+"?action=load&filename=example.syn");
-
- JSONObject response=new JSONObject(page.getContent());
+ String page=this.getTestPage(this.url+"?action=load&filename=example.syn");
+ JSONObject response=new JSONObject(page);
//check success and empty message string.
assertTrue(response.getBoolean("success"));
@@ -125,9 +123,9 @@ public void testSave() throws Exception{
JSONObject circuit=Util.fileToJSONObject("data/synstore/example.syn");
- TextPage page=this.getTestPage(this.url+"?action=save&filename=test.syn&circuit="+circuit.toString());
+ String page=this.getTestPage(this.url+"?action=save&filename=test.syn&circuit="+circuit.toString());
- JSONObject response=new JSONObject(page.getContent());
+ JSONObject response=new JSONObject(page);
assertTrue(response.getBoolean("success"));
assertEquals("Saved succesfully", response.getString("message"));
@@ -160,9 +158,9 @@ public void testSave() throws Exception{
@Test
public void testSave_notDotSyn() throws Exception {
String content="abracadabra";
- TextPage page=this.getTestPage(this.url+"?action=save&filename=test.foo&circuit="+content);
+ String page=this.getTestPage(this.url+"?action=save&filename=test.foo&circuit="+content);
- JSONObject response=new JSONObject(page.getContent());
+ JSONObject response=new JSONObject(page);
assertFalse(response.getBoolean("success"));
assertEquals("Filename should end with .syn.", response.getString("message"));
@@ -174,9 +172,9 @@ public void testSave_notDotSyn() throws Exception {
@Test
public void testSave_noFilename() throws Exception {
String content="abracadabra";
- TextPage page=this.getTestPage(this.url+"?action=save&circuit="+content);
+ String page=this.getTestPage(this.url+"?action=save&circuit="+content);
- JSONObject response=new JSONObject(page.getContent());
+ JSONObject response=new JSONObject(page);
assertFalse(response.getBoolean("success"));
assertEquals("Parameter 'filename' not set.", response.getString("message"));
@@ -187,9 +185,9 @@ public void testSave_noFilename() throws Exception {
*/
@Test
public void testSave_noCircuit() throws Exception {
- TextPage page=this.getTestPage(this.url+"?action=save&filename=test.syn");
+ String page=this.getTestPage(this.url+"?action=save&filename=test.syn");
- JSONObject response=new JSONObject(page.getContent());
+ JSONObject response=new JSONObject(page);
assertFalse(response.getBoolean("success"));
assertEquals("Parameter 'circuit' not set.", response.getString("message"));
@@ -203,9 +201,9 @@ public void testSave_noCircuit() throws Exception {
public void testValidate_withValid() throws Exception {
JSONObject circuit=Util.fileToJSONObject("data/synstore/example-with-inputs.syn");
- TextPage page=this.getTestPage(this.url+"?action=validate&circuit="+circuit.toString());
+ String page=this.getTestPage(this.url+"?action=validate&circuit="+circuit.toString());
- JSONObject response=new JSONObject(page.getContent());
+ JSONObject response=new JSONObject(page);
assertTrue(response.getBoolean("success"));
}
@@ -219,9 +217,9 @@ public void testValidate_withValid() throws Exception {
public void testValidate_withoutInputs() throws Exception {
JSONObject circuit=Util.fileToJSONObject("data/test/models/incompleteAndCircuit.json");
- TextPage page=this.getTestPage(this.url+"?action=validate&circuit="+circuit.toString());
+ String page=this.getTestPage(this.url+"?action=validate&circuit="+circuit.toString());
- JSONObject response=new JSONObject(page.getContent());
+ JSONObject response=new JSONObject(page);
assertFalse(response.getBoolean("success"));
assertThat(response.getString("message"), equalTo("Error in Circuit: At least one AND gate has only one input."));
View
6 program/WEB-INF/src/synthbio/servlets/test/TestListProteins.java
@@ -21,7 +21,7 @@
import synthbio.Util;
-import com.gargoylesoftware.htmlunit.TextPage;
+import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
/**
@@ -43,13 +43,13 @@
@Test
public void testResponse() throws Exception{
final WebClient webClient = new WebClient();
- final TextPage page = webClient.getPage(url);
+ final Page page = webClient.getPage(url);
String expected=Util.fileToString("data/test/servlets/listProteins-expected.json").trim();
assertEquals(
expected,
- page.getContent().trim()
+ page.getWebResponse().getContentAsString().trim()
);
webClient.closeAllWindows();

0 comments on commit 1e7dd99

Please sign in to comment.
Something went wrong with that request. Please try again.