mirror of
https://github.com/octoleo/plantuml-server.git
synced 2024-12-23 01:08:54 +00:00
Merge branch 'refs/heads/master' of https://arnaudroques@github.com/arnaudroques/plantumlservlet.git into HEAD
This commit is contained in:
commit
2b77e0e27f
@ -1,16 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="test/src"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
<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">
|
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="owner.project.facets" value="jst.web"/>
|
<attribute name="owner.project.facets" value="jst.web"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_11">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="owner.project.facets" value="java"/>
|
<attribute name="owner.project.facets" value="java"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="test/lib/httpunit.jar"/>
|
||||||
<classpathentry kind="output" path="content/WEB-INF/classes"/>
|
<classpathentry kind="output" path="content/WEB-INF/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
/user.property
|
/user.property
|
||||||
/content/WEB-INF/classes
|
/content/WEB-INF/classes
|
||||||
/plantuml.war
|
/plantuml.war
|
||||||
|
/dist
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<wb-module deploy-name="plantumlservlet">
|
<wb-module deploy-name="plantumlservlet">
|
||||||
<wb-resource deploy-path="/" source-path="/content"/>
|
<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="/src"/>
|
||||||
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/test/src"/>
|
||||||
<property name="java-output-path" value="/plantumlservlet/WEB-INF/classes"/>
|
<property name="java-output-path" value="/plantumlservlet/WEB-INF/classes"/>
|
||||||
<property name="context-root" value="plantuml"/>
|
<property name="context-root" value="plantuml"/>
|
||||||
</wb-module>
|
</wb-module>
|
||||||
|
33
build.xml
33
build.xml
@ -3,21 +3,36 @@
|
|||||||
<target name="main" depends="clean,compile,war">
|
<target name="main" depends="clean,compile,war">
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<taskdef name="junit"
|
||||||
|
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="test/lib/junit-3.8.1.jar" />
|
||||||
|
</classpath>
|
||||||
|
</taskdef>
|
||||||
|
|
||||||
|
|
||||||
<target name="init">
|
<target name="init">
|
||||||
<!-- overwrite with your own values in a user.property file -->
|
<!-- overwrite with your own values in a user.property file -->
|
||||||
<property file="user.property" />
|
<property file="user.property" />
|
||||||
<property name="target" value="." description="Target directory of the build"/>
|
<property name="target" value="dist" description="Target directory of the build"/>
|
||||||
<property name="tomcat-home" value="/tomcat" description="Home directory of Tomcat"/>
|
<property name="tomcat-home" value="/tomcat" description="Home directory of Tomcat"/>
|
||||||
<property name="debug" value="false" />
|
<property name="debug" value="false" />
|
||||||
|
<mkdir dir="${target}" />
|
||||||
<path id="project-classpath">
|
<path id="project-classpath">
|
||||||
<fileset dir="content/WEB-INF/lib" includes="*.jar" />
|
<fileset dir="content/WEB-INF/lib" includes="*.jar" />
|
||||||
<fileset dir="${tomcat-home}/lib" includes="*.jar" />
|
<fileset dir="${tomcat-home}/lib" includes="*.jar" />
|
||||||
</path>
|
</path>
|
||||||
|
<path id="test-classpath">
|
||||||
|
<fileset dir="test/lib" includes="*.jar" />
|
||||||
|
<pathelement location="${target}"/>
|
||||||
|
</path>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="clean" depends="init">
|
<target name="clean" depends="init">
|
||||||
<delete file="${target}/plantuml.war" />
|
<delete file="${target}/plantuml.war" />
|
||||||
<mkdir dir="${target}" />
|
<delete>
|
||||||
|
<fileset dir="${target}" includes="**/*.class"/>
|
||||||
|
</delete>
|
||||||
<delete dir="content/WEB-INF/classes" />
|
<delete dir="content/WEB-INF/classes" />
|
||||||
<mkdir dir="content/WEB-INF/classes" />
|
<mkdir dir="content/WEB-INF/classes" />
|
||||||
</target>
|
</target>
|
||||||
@ -38,4 +53,18 @@
|
|||||||
<copy file="${target}/plantuml.war" todir="${tomcat-home}/webapps" overwrite="true" />
|
<copy file="${target}/plantuml.war" todir="${tomcat-home}/webapps" overwrite="true" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name="test" depends="init">
|
||||||
|
<echo>
|
||||||
|
WARN - Test execution requires an running PlantUMLServer.
|
||||||
|
</echo>
|
||||||
|
<javac srcdir="test/src" destdir="${target}" debug="${debug}" classpathref="test-classpath" />
|
||||||
|
<junit showoutput="true" >
|
||||||
|
<classpath>
|
||||||
|
<path refid="test-classpath"/>
|
||||||
|
</classpath>
|
||||||
|
<formatter type="plain" usefile="false" />
|
||||||
|
<test name="net.sourceforge.plantuml.servlet.AllTests"/>
|
||||||
|
</junit>
|
||||||
|
</target>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
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.
17
test/src/net/sourceforge/plantuml/servlet/AllTests.java
Normal file
17
test/src/net/sourceforge/plantuml/servlet/AllTests.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
92
test/src/net/sourceforge/plantuml/servlet/TestForm.java
Normal file
92
test/src/net/sourceforge/plantuml/servlet/TestForm.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
35
test/src/net/sourceforge/plantuml/servlet/TestImage.java
Normal file
35
test/src/net/sourceforge/plantuml/servlet/TestImage.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
40
test/src/net/sourceforge/plantuml/servlet/TestUtils.java
Normal file
40
test/src/net/sourceforge/plantuml/servlet/TestUtils.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user