mirror of
https://github.com/octoleo/plantuml-server.git
synced 2024-12-22 08:48:54 +00:00
First unit test case using HttpUnit
This commit is contained in:
parent
4f0aab14f7
commit
7ffbc44e08
@ -1,7 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="test/src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="lib" path="test/lib/junit-3.8.1.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="jst.web"/>
|
||||
@ -12,5 +14,6 @@
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="test/lib/httpunit.jar"/>
|
||||
<classpathentry kind="output" path="content/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
@ -3,6 +3,7 @@
|
||||
<wb-module deploy-name="plantumlservlet">
|
||||
<wb-resource deploy-path="/" source-path="/content"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/test/src"/>
|
||||
<property name="java-output-path" value="/plantumlservlet/WEB-INF/classes"/>
|
||||
<property name="context-root" value="plantuml"/>
|
||||
</wb-module>
|
||||
|
BIN
test/lib/httpunit.jar
Normal file
BIN
test/lib/httpunit.jar
Normal file
Binary file not shown.
BIN
test/lib/js-1.6R5.jar
Normal file
BIN
test/lib/js-1.6R5.jar
Normal file
Binary file not shown.
BIN
test/lib/jtidy-4aug2000r7-dev.jar
Normal file
BIN
test/lib/jtidy-4aug2000r7-dev.jar
Normal file
Binary file not shown.
BIN
test/lib/junit-3.8.1.jar
Normal file
BIN
test/lib/junit-3.8.1.jar
Normal file
Binary file not shown.
70
test/src/net/sourceforge/plantuml/servlet/TestForm.java
Normal file
70
test/src/net/sourceforge/plantuml/servlet/TestForm.java
Normal file
@ -0,0 +1,70 @@
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
|
||||
import junit.framework.*;
|
||||
import com.meterware.httpunit.*;
|
||||
|
||||
public class TestForm extends TestCase {
|
||||
|
||||
/**
|
||||
* Verifies that the welcome page has exactly two form
|
||||
* with the Bob --> Alice sample
|
||||
*/
|
||||
public void testWelcomePage() throws Exception {
|
||||
WebConversation conversation = new WebConversation();
|
||||
WebRequest request = new GetMethodWebRequest( "http://localhost/plantuml/" );
|
||||
WebResponse response = tryGetResponse(conversation, request );
|
||||
|
||||
WebForm forms[] = response.getForms();
|
||||
assertEquals( 2, forms.length );
|
||||
assertEquals( "url", forms[1].getParameterNames()[0] );
|
||||
FormControl urlInput = forms[1].getParameter("url").getControl();
|
||||
assertEquals( "http://localhost:80/plantuml/img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000",
|
||||
forms[1].getParameterValue("url"));
|
||||
assertEquals( "INPUT", urlInput.getTagName());
|
||||
// Ensure the generated image is present
|
||||
assertEquals( 1, response.getImages().length);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that when the UML text is empty, no image is generated
|
||||
*/
|
||||
public void testEmptyText() throws Exception {
|
||||
WebConversation conversation = new WebConversation();
|
||||
// Fill the form and submit it
|
||||
WebRequest request = new GetMethodWebRequest( "http://localhost/plantuml/form" );
|
||||
WebResponse response = tryGetResponse(conversation, request );
|
||||
WebForm formUMLText = response.getForms()[0];
|
||||
formUMLText.setParameter("text", "");
|
||||
response = tryGetResponse( conversation, formUMLText.getRequest());
|
||||
// Analyze response
|
||||
WebForm forms[] = response.getForms();
|
||||
assertEquals( 2, forms.length );
|
||||
// Ensure the Text field is empty
|
||||
assertNull( forms[0].getParameterValue("text"));
|
||||
// Ensure the URL field is empty
|
||||
assertTrue( forms[1].getParameterValue("url").isEmpty());
|
||||
// Ensure there is no image
|
||||
assertEquals( 0, response.getImages().length);
|
||||
}
|
||||
|
||||
/**
|
||||
* try getting a response for the given Conversation and Request
|
||||
* show an error message if a 404 error appears
|
||||
* @param conversation - the conversation to use
|
||||
* @param request
|
||||
* @return the response
|
||||
* @throws an Exception if getting the response fails
|
||||
*/
|
||||
public WebResponse tryGetResponse(WebConversation conversation, WebRequest request) throws Exception {
|
||||
WebResponse response=null;
|
||||
try {
|
||||
response = conversation.getResponse( request );
|
||||
} catch (HttpNotFoundException nfe) {
|
||||
System.err.println("The URL '"+request.getURL()+"' is not active any more");
|
||||
throw nfe;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user