diff --git a/.classpath b/.classpath
index be8f69d..a19d0e2 100644
--- a/.classpath
+++ b/.classpath
@@ -1,16 +1,19 @@
+
+
-
+
+
diff --git a/.gitignore b/.gitignore
index 4c09de1..12c5c19 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
/user.property
/content/WEB-INF/classes
/plantuml.war
+/dist
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index 985afb9..d13cb29 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -3,6 +3,7 @@
+
diff --git a/build.xml b/build.xml
index 0043a49..3e8773f 100644
--- a/build.xml
+++ b/build.xml
@@ -3,21 +3,36 @@
+
+
+
+
+
+
+
-
+
+
+
+
+
+
-
+
+
+
@@ -38,4 +53,18 @@
+
+
+ WARN - Test execution requires an running PlantUMLServer.
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/lib/httpunit.jar b/test/lib/httpunit.jar
new file mode 100644
index 0000000..8656e8b
Binary files /dev/null and b/test/lib/httpunit.jar differ
diff --git a/test/lib/js-1.6R5.jar b/test/lib/js-1.6R5.jar
new file mode 100644
index 0000000..2b92650
Binary files /dev/null and b/test/lib/js-1.6R5.jar differ
diff --git a/test/lib/jtidy-4aug2000r7-dev.jar b/test/lib/jtidy-4aug2000r7-dev.jar
new file mode 100644
index 0000000..0eebfa6
Binary files /dev/null and b/test/lib/jtidy-4aug2000r7-dev.jar differ
diff --git a/test/lib/junit-3.8.1.jar b/test/lib/junit-3.8.1.jar
new file mode 100644
index 0000000..674d71e
Binary files /dev/null and b/test/lib/junit-3.8.1.jar differ
diff --git a/test/src/net/sourceforge/plantuml/servlet/AllTests.java b/test/src/net/sourceforge/plantuml/servlet/AllTests.java
new file mode 100644
index 0000000..ad6f081
--- /dev/null
+++ b/test/src/net/sourceforge/plantuml/servlet/AllTests.java
@@ -0,0 +1,17 @@
+package net.sourceforge.plantuml.servlet;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests extends TestSuite {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ //$JUnit-BEGIN$
+ suite.addTestSuite(TestForm.class);
+ suite.addTestSuite(TestImage.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/test/src/net/sourceforge/plantuml/servlet/TestForm.java b/test/src/net/sourceforge/plantuml/servlet/TestForm.java
new file mode 100644
index 0000000..5953eb6
--- /dev/null
+++ b/test/src/net/sourceforge/plantuml/servlet/TestForm.java
@@ -0,0 +1,92 @@
+package net.sourceforge.plantuml.servlet;
+
+import junit.framework.TestCase;
+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( TestUtils.getServerUrl());
+ WebResponse response = TestUtils.tryGetResponse(conversation, request );
+ // Analyze response
+ WebForm forms[] = response.getForms();
+ assertEquals( 2, forms.length );
+ assertEquals( "url", forms[1].getParameterNames()[0] );
+ assertTrue( forms[1].getParameterValue("url").endsWith("/img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"));
+ // Ensure the generated image is present
+ assertEquals( 1, response.getImages().length);
+
+ }
+
+ /**
+ * Verifies that the version image is generated
+ */
+ public void testVersion() throws Exception {
+ WebConversation conversation = new WebConversation();
+ // Fill the form and submit it
+ WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl());
+ WebResponse response = TestUtils.tryGetResponse(conversation, request );
+ WebForm formUMLText = response.getForms()[0];
+ formUMLText.setParameter("text", "version");
+ response = formUMLText.submit();
+ // Analyze response
+ WebForm forms[] = response.getForms();
+ assertEquals( 2, forms.length );
+ // Ensure the Text field is correct
+ assertEquals( "version", forms[0].getParameterValue("text"));
+ // Ensure the URL field is correct
+ assertTrue( forms[1].getParameterValue("url").endsWith("/img/AqijAixCpmC0"));
+ // Ensure the 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( TestUtils.getServerUrl());
+ WebResponse response = TestUtils.tryGetResponse(conversation, request );
+ WebForm formUMLText = response.getForms()[0];
+ formUMLText.setParameter("text", "");
+ response = formUMLText.submit();
+ // 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);
+ }
+
+ /**
+ * Verifies that when the encoded URL is empty, the default image is generated
+ */
+ public void testEmptyUrl() throws Exception {
+ WebConversation conversation = new WebConversation();
+ // Fill the form and submit it
+ WebRequest request = new GetMethodWebRequest( "http://localhost/plantuml/" );
+ WebResponse response = TestUtils.tryGetResponse(conversation, request );
+ WebForm formUrl = response.getForms()[1];
+ formUrl.setParameter("url", "");
+ response = formUrl.submit();
+ // Analyze response
+ WebForm forms[] = response.getForms();
+ assertEquals( 2, forms.length );
+ // Ensure the Text field is empty
+ assertTrue( forms[0].getParameterValue("text").startsWith("Bob"));
+ // Ensure the URL field is correct
+ assertTrue( forms[1].getParameterValue("url").endsWith("/img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"));
+ // Ensure the image is present
+ assertEquals( 1, response.getImages().length);
+ }
+
+}
diff --git a/test/src/net/sourceforge/plantuml/servlet/TestImage.java b/test/src/net/sourceforge/plantuml/servlet/TestImage.java
new file mode 100644
index 0000000..746df00
--- /dev/null
+++ b/test/src/net/sourceforge/plantuml/servlet/TestImage.java
@@ -0,0 +1,35 @@
+package net.sourceforge.plantuml.servlet;
+
+import junit.framework.TestCase;
+import com.meterware.httpunit.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+public class TestImage extends TestCase {
+ /**
+ * Verifies the generation of the version image from an encoded URL
+ */
+ public void testVersionImage() throws Exception {
+ WebConversation conversation = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"img/AqijAixCpmC0");
+ WebResponse response = conversation.getResource( request);
+ // Analyze response
+ // Verifies the Content-Type header
+ assertEquals( "image/png", response.getContentType());
+ // Get the image and verify its size
+ InputStream responseStream = response.getInputStream();
+ ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
+ byte[] buf = new byte[1024];
+ int n = 0;
+ while( ( n = responseStream.read( buf)) != -1) {
+ imageStream.write( buf, 0, n);
+ }
+ imageStream.close();
+ responseStream.close();
+ byte[] inMemoryImage = imageStream.toByteArray();
+ int diagramLen = inMemoryImage.length;
+ assertTrue( diagramLen > 10000);
+ assertTrue( diagramLen < 20000);
+ }
+}
diff --git a/test/src/net/sourceforge/plantuml/servlet/TestUtils.java b/test/src/net/sourceforge/plantuml/servlet/TestUtils.java
new file mode 100644
index 0000000..63fb937
--- /dev/null
+++ b/test/src/net/sourceforge/plantuml/servlet/TestUtils.java
@@ -0,0 +1,40 @@
+package net.sourceforge.plantuml.servlet;
+
+import com.meterware.httpunit.*;
+
+/**
+ * Utility class for HttpUnit conversations
+ */
+public class TestUtils {
+
+ /**
+ * Return the URL of the PlantUMLServlet, deployed on the testing web server
+ * in the following form http://server/contextroot/
+ * Note the trailing slash (/)
+ * @return the URL
+ */
+ public static String getServerUrl() {
+ return "http://localhost/plantuml/";
+ }
+
+ /**
+ * 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 static 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;
+ }
+
+}
+