diff --git a/.classpath b/.classpath deleted file mode 100644 index a19d0e2..0000000 --- a/.classpath +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore index 12c5c19..cb9c43c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ -/user.property -/content/WEB-INF/classes -/plantuml.war -/dist - +target +.* diff --git a/.project b/.project deleted file mode 100644 index 08a89c0..0000000 --- a/.project +++ /dev/null @@ -1,31 +0,0 @@ - - - plantumlservlet - - - Servers - - - - org.eclipse.wst.common.project.facet.core.builder - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.wst.validation.validationbuilder - - - - - - org.eclipse.jem.workbench.JavaEMFNature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jdt.core.javanature - org.eclipse.wst.common.project.facet.core.nature - - diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope deleted file mode 100644 index 620a2ac..0000000 --- a/.settings/.jsdtscope +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 169c298..0000000 --- a/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Feb 17 12:10:42 CET 2011 -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 694df1b..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Thu Feb 17 12:07:22 CET 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/.settings/org.eclipse.ltk.core.refactoring.prefs b/.settings/org.eclipse.ltk.core.refactoring.prefs deleted file mode 100644 index 4008ac3..0000000 --- a/.settings/org.eclipse.ltk.core.refactoring.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Feb 17 12:12:34 CET 2011 -eclipse.preferences.version=1 -org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component deleted file mode 100644 index d13cb29..0000000 --- a/.settings/org.eclipse.wst.common.component +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml deleted file mode 100644 index 2bab022..0000000 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container deleted file mode 100644 index 3bd5d0a..0000000 --- a/.settings/org.eclipse.wst.jsdt.ui.superType.container +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name deleted file mode 100644 index 05bd71b..0000000 --- a/.settings/org.eclipse.wst.jsdt.ui.superType.name +++ /dev/null @@ -1 +0,0 @@ -Window \ No newline at end of file diff --git a/.settings/org.eclipse.wst.ws.service.policy.prefs b/.settings/org.eclipse.wst.ws.service.policy.prefs deleted file mode 100644 index 1bbb2f0..0000000 --- a/.settings/org.eclipse.wst.ws.service.policy.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Feb 17 12:12:34 CET 2011 -eclipse.preferences.version=1 -org.eclipse.wst.ws.service.policy.projectEnabled=false diff --git a/README b/README deleted file mode 100644 index 9db8788..0000000 --- a/README +++ /dev/null @@ -1,21 +0,0 @@ -* PlantUMLServlet description -***************************** -PlantUMLServlet is a PlantUML extension to generate images on-the-fly. -To know more about PlantUML, please visit http://plantuml.sourceforge.net/ - -* How to build the project -************************** -To build the project you need to install the following components : -- java jdk 1.6.0 or above -- apache tomcat 6.0 or above -- apache ant 1.7 or above - -If the tomcat home directory is not /tomcat, you have to create at -the root of the project a text file named user.property and -containing the following line: -tomcat-home= - -For example, on a Windows environment, your user.property file can be: -tomcat-home=C:/tools/Tomcat6.0 - -To build the war, just run "ant" at the root directory of the project. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3b7b71c --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +PlantUMLServlet description +=========================== + +PlantUMLServlet is a PlantUML extension to generate images on-the-fly. + +To know more about PlantUML, please visit http://plantuml.sourceforge.net/. + +How to build the project +======================== + +To build the project you need to install the following components: + + * java jdk 1.6.0 or above + * apache maven 3.0.2 or above + +To build the war, just run "mvn package" at the root directory of the project to produce +plantuml.war in the target/ directory. + +How to testrun the project +========================== + +To run the application deployed on an embedded jetty server run "mvn jetty:run-war" +and go to http://localhost:8080/plantuml with your favorite web browser (after it finishes +to start up). diff --git a/build.xml b/build.xml deleted file mode 100644 index 957bf05..0000000 --- a/build.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WARN - Test execution requires an running PlantUMLServer. - - - - - - - - - - - - diff --git a/content/WEB-INF/lib/HTTPClient.jar b/content/WEB-INF/lib/HTTPClient.jar deleted file mode 100644 index 5e79f0b..0000000 Binary files a/content/WEB-INF/lib/HTTPClient.jar and /dev/null differ diff --git a/content/WEB-INF/lib/plantuml.jar b/content/WEB-INF/lib/plantuml.jar deleted file mode 100644 index 03efcb1..0000000 Binary files a/content/WEB-INF/lib/plantuml.jar and /dev/null differ diff --git a/content/WEB-INF/web.xml b/content/WEB-INF/web.xml deleted file mode 100644 index 6de59ce..0000000 --- a/content/WEB-INF/web.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - plantuml - - plantumlservlet - net.sourceforge.plantuml.servlet.PlantUmlServlet - - - welcome - net.sourceforge.plantuml.servlet.Welcome - - - imgservlet - net.sourceforge.plantuml.servlet.ImgServlet - - - svgservlet - net.sourceforge.plantuml.servlet.SvgServlet - - - asciiservlet - net.sourceforge.plantuml.servlet.AsciiServlet - - - - welcome - /welcome - - - plantumlservlet - /uml/* - - - plantumlservlet - /form - - - imgservlet - /img/* - - - svgservlet - /svg/* - - - asciiservlet - /txt/* - - - plantumlservlet - /start/* - - - plantumlservlet - /proxy/* - - - welcome - - - java.lang.Throwable - /error.jsp - - - 500 - /error.jsp - - diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6ed5b4e --- /dev/null +++ b/pom.xml @@ -0,0 +1,90 @@ + + 4.0.0 + org.sourceforge.plantuml + plantumlservlet + 1-SNAPSHOT + PlantUML Servlet + war + + plantuml + + + maven-eclipse-plugin + + 1.5 + plantuml + + + + maven-compiler-plugin + + 1.6 + 1.6 + + + + org.mortbay.jetty + jetty-maven-plugin + ${jetty.version} + + 5 + + /plantuml + + + + + + + 8.0.4.v20111024 + + + + net.sourceforge.plantuml + plantuml + 7481 + + + HTTPClient + HTTPClient + 0.3-3 + + + javax.servlet + servlet-api + 2.4 + provided + + + junit + junit + 3.8.2 + test + + + httpunit + httpunit + 1.7 + test + + + rhino + js + 1.7R2 + test + + + org.eclipse.jetty.aggregate + jetty-all + ${jetty.version} + test + + + org.mortbay.jetty + jsp-2.1-glassfish + 2.1.v20100127 + test + + + diff --git a/src/net/sourceforge/plantuml/servlet/AsciiServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/AsciiServlet.java similarity index 100% rename from src/net/sourceforge/plantuml/servlet/AsciiServlet.java rename to src/main/java/net/sourceforge/plantuml/servlet/AsciiServlet.java diff --git a/src/net/sourceforge/plantuml/servlet/DiagramResponse.java b/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java similarity index 100% rename from src/net/sourceforge/plantuml/servlet/DiagramResponse.java rename to src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java diff --git a/src/net/sourceforge/plantuml/servlet/ImgServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/ImgServlet.java similarity index 100% rename from src/net/sourceforge/plantuml/servlet/ImgServlet.java rename to src/main/java/net/sourceforge/plantuml/servlet/ImgServlet.java diff --git a/src/net/sourceforge/plantuml/servlet/PlantUmlServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java similarity index 84% rename from src/net/sourceforge/plantuml/servlet/PlantUmlServlet.java rename to src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java index 72f693a..41acc22 100644 --- a/src/net/sourceforge/plantuml/servlet/PlantUmlServlet.java +++ b/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java @@ -3,7 +3,7 @@ * ======================================================================== * * Project Info: http://plantuml.sourceforge.net - * + * * This file is part of PlantUML. * * PlantUML is free software; you can redistribute it and/or modify it @@ -48,22 +48,23 @@ import HTTPClient.HTTPResponse; import HTTPClient.ModuleException; import HTTPClient.ParseException; -/* +/* * Original idea from Achim Abeling for Confluence macro * See http://www.banapple.de/display/BANAPPLE/plantuml+user+macro - * + * * Modified by Arnaud Roques + * Modified by Pablo Lalloni * Packaged by Maxime Sinclair - * + * */ @SuppressWarnings("serial") public class PlantUmlServlet extends HttpServlet { private static final Pattern startumlPattern = Pattern.compile("/\\w+/start/(.*)"); - private static final Pattern proxyPattern = Pattern.compile("/\\w+/proxy/((\\d+)/)?(http://.*)"); + private static final Pattern proxyPattern = Pattern.compile("/\\w+/proxy/((\\d+)/)?((\\w+)/)?(http://.*)"); private static final Pattern oldStartumlPattern = Pattern.compile("/\\w+/uml/startuml/(.*)"); private static final Pattern oldImagePattern = Pattern.compile("/\\w+/uml/image/(.*)"); - private static final Pattern oldProxyPattern = Pattern.compile("/\\w+/uml/proxy/((\\d+)/)?(http://.*)"); + private static final Pattern oldProxyPattern = Pattern.compile("/\\w+/uml/proxy/((\\d+)/)?((\\w+)/)?(http://.*)"); @Override public void doGet(HttpServletRequest request, HttpServletResponse response) @@ -80,8 +81,9 @@ public class PlantUmlServlet extends HttpServlet { handleImage(response, source, uri); } else if (proxyMatcher.matches()) { String num = proxyMatcher.group(2); - String source = proxyMatcher.group(3); - handleImageProxy(response, num, source, uri); + String format = proxyMatcher.group(4); + String source = proxyMatcher.group(5); + handleImageProxy(response, num, source, format, uri); } else if (oldStartumlMatcher.matches()) { String source = oldStartumlMatcher.group(1); handleImage(response, source, uri); @@ -90,8 +92,9 @@ public class PlantUmlServlet extends HttpServlet { handleImageDecompress(response, source, uri); } else if (oldProxyMatcher.matches()) { String num = oldProxyMatcher.group(2); - String source = oldProxyMatcher.group(3); - handleImageProxy(response, num, source, uri); + String format = oldProxyMatcher.group(4); + String source = oldProxyMatcher.group(5); + handleImageProxy(response, num, source, format, uri); } else { doPost(request, response); } @@ -109,7 +112,7 @@ public class PlantUmlServlet extends HttpServlet { Transcoder transcoder = getTranscoder(); // the URL form has been submitted - if ((url != null) && (!url.trim().isEmpty())) { + if (url != null && !url.trim().isEmpty()) { // TODO Verify the url is correct Pattern p = Pattern.compile(".*/(.*)"); Matcher m = p.matcher(url); @@ -119,13 +122,13 @@ public class PlantUmlServlet extends HttpServlet { } } // the Text form has been submitted - if ((text != null) && (!text.trim().isEmpty())) { + if (text != null && !text.trim().isEmpty()) { encoded = transcoder.encode(text); } request.setAttribute("net.sourceforge.plantuml.servlet.decoded", text); request.setAttribute("net.sourceforge.plantuml.servlet.encoded", encoded); - + // forward to index.jsp RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp"); dispatcher.forward(request, response); @@ -158,11 +161,15 @@ public class PlantUmlServlet extends HttpServlet { } private void handleImageProxy(HttpServletResponse response, String num, - String source, String uri) throws IOException { + String source, String format, String uri) throws IOException { SourceStringReader reader = new SourceStringReader( getContent(source)); int n = num == null ? 0 : Integer.parseInt(num); - // Write the first image to "os" - reader.generateImage(response.getOutputStream(), n); + // Write the requested image to "os" + if (format != null) { + reader.generateImage(response.getOutputStream(), n, new FileFormatOption(FileFormat.valueOf(format))); + } else { + reader.generateImage(response.getOutputStream(), n); + } } private void sendImage(HttpServletResponse response, String text, String uri) @@ -195,7 +202,7 @@ public class PlantUmlServlet extends HttpServlet { reader.generateImage(response.getOutputStream(), new FileFormatOption(FileFormat.PNG)); response.flushBuffer(); } - + private String getContent(String adress) throws IOException { // HTTPConnection.setProxyServer("proxy", 8080); CookieModule.setCookiePolicyHandler(null); diff --git a/src/net/sourceforge/plantuml/servlet/SvgServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/SvgServlet.java similarity index 100% rename from src/net/sourceforge/plantuml/servlet/SvgServlet.java rename to src/main/java/net/sourceforge/plantuml/servlet/SvgServlet.java diff --git a/src/net/sourceforge/plantuml/servlet/UmlDiagramService.java b/src/main/java/net/sourceforge/plantuml/servlet/UmlDiagramService.java similarity index 100% rename from src/net/sourceforge/plantuml/servlet/UmlDiagramService.java rename to src/main/java/net/sourceforge/plantuml/servlet/UmlDiagramService.java diff --git a/src/net/sourceforge/plantuml/servlet/Welcome.java b/src/main/java/net/sourceforge/plantuml/servlet/Welcome.java similarity index 100% rename from src/net/sourceforge/plantuml/servlet/Welcome.java rename to src/main/java/net/sourceforge/plantuml/servlet/Welcome.java diff --git a/src/net/sourceforge/plantuml/servlet/package.html b/src/main/java/net/sourceforge/plantuml/servlet/package.html similarity index 100% rename from src/net/sourceforge/plantuml/servlet/package.html rename to src/main/java/net/sourceforge/plantuml/servlet/package.html diff --git a/content/META-INF/MANIFEST.MF b/src/main/webapp/META-INF/MANIFEST.MF similarity index 100% rename from content/META-INF/MANIFEST.MF rename to src/main/webapp/META-INF/MANIFEST.MF diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..240841c --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,74 @@ + + + plantuml + + org.eclipse.jetty.servlet.Default.welcomeServlets + exact + + + plantumlservlet + net.sourceforge.plantuml.servlet.PlantUmlServlet + + + welcome + net.sourceforge.plantuml.servlet.Welcome + + + imgservlet + net.sourceforge.plantuml.servlet.ImgServlet + + + svgservlet + net.sourceforge.plantuml.servlet.SvgServlet + + + asciiservlet + net.sourceforge.plantuml.servlet.AsciiServlet + + + + welcome + /welcome + + + plantumlservlet + /uml/* + + + plantumlservlet + /form + + + imgservlet + /img/* + + + svgservlet + /svg/* + + + asciiservlet + /txt/* + + + plantumlservlet + /start/* + + + plantumlservlet + /proxy/* + + + java.lang.Throwable + /error.jsp + + + 500 + /error.jsp + + + welcome + + diff --git a/content/error.jsp b/src/main/webapp/error.jsp similarity index 100% rename from content/error.jsp rename to src/main/webapp/error.jsp diff --git a/content/favicon.ico b/src/main/webapp/favicon.ico similarity index 100% rename from content/favicon.ico rename to src/main/webapp/favicon.ico diff --git a/content/footer.jspf b/src/main/webapp/footer.jspf similarity index 100% rename from content/footer.jspf rename to src/main/webapp/footer.jspf diff --git a/content/index.jsp b/src/main/webapp/index.jsp similarity index 100% rename from content/index.jsp rename to src/main/webapp/index.jsp diff --git a/content/plantuml.css b/src/main/webapp/plantuml.css similarity index 100% rename from content/plantuml.css rename to src/main/webapp/plantuml.css diff --git a/test/src/net/sourceforge/plantuml/servlet/AllTests.java b/src/test/java/net/sourceforge/plantuml/servlet/AllTests.java similarity index 100% rename from test/src/net/sourceforge/plantuml/servlet/AllTests.java rename to src/test/java/net/sourceforge/plantuml/servlet/AllTests.java diff --git a/src/test/java/net/sourceforge/plantuml/servlet/ServerUtils.java b/src/test/java/net/sourceforge/plantuml/servlet/ServerUtils.java new file mode 100644 index 0000000..8fae235 --- /dev/null +++ b/src/test/java/net/sourceforge/plantuml/servlet/ServerUtils.java @@ -0,0 +1,38 @@ +package net.sourceforge.plantuml.servlet; + +import java.net.InetSocketAddress; + +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.webapp.WebAppContext; + +public class ServerUtils { + + Server server; + + public ServerUtils(boolean start) throws Exception { + server = new Server(new InetSocketAddress("127.0.0.1", 0)); + server.addBean(new WebAppContext(server, "src/main/webapp", "/plantuml")); + if (start) { + startServer(); + } + } + + public ServerUtils() throws Exception { + this(false); + } + + public void startServer() throws Exception { + server.start(); + } + + public void stopServer() throws Exception { + server.stop(); + } + + public String getServerUrl() { + Connector connector = server.getConnectors()[0]; + return String.format("http://%s:%d/plantuml/", connector.getHost(), connector.getLocalPort()); + } + +} diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java new file mode 100644 index 0000000..2657e1a --- /dev/null +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java @@ -0,0 +1,28 @@ +package net.sourceforge.plantuml.servlet; + + +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +public class TestAsciiArt extends WebappTestCase { + + /** + * Verifies the generation of the ascii art for the Bob -> Alice sample + */ + public void testSimpleSequenceDiagram() throws Exception { + WebConversation conversation = new WebConversation(); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "txt/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); + WebResponse response = conversation.getResource(request); + // Analyze response + // Verifies the Content-Type header + assertEquals("Response content type is not TEXT PLAIN", "text/plain", response.getContentType()); + // Get the content and verify its size + String diagram = response.getText(); + int diagramLen = diagram.length(); + assertTrue(diagramLen > 200); + assertTrue(diagramLen < 250); + } + +} diff --git a/test/src/net/sourceforge/plantuml/servlet/TestForm.java b/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java similarity index 86% rename from test/src/net/sourceforge/plantuml/servlet/TestForm.java rename to src/test/java/net/sourceforge/plantuml/servlet/TestForm.java index 8c5e69b..4851065 100644 --- a/test/src/net/sourceforge/plantuml/servlet/TestForm.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java @@ -1,19 +1,22 @@ package net.sourceforge.plantuml.servlet; -import junit.framework.TestCase; -import com.meterware.httpunit.*; +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebForm; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +public class TestForm extends WebappTestCase { -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()); + WebRequest request = new GetMethodWebRequest(getServerUrl()); WebResponse response = TestUtils.tryGetResponse(conversation, request ); - // Analyze response + // Analyze response WebForm forms[] = response.getForms(); assertEquals( 2, forms.length ); assertEquals( "url", forms[1].getParameterNames()[0] ); @@ -29,7 +32,7 @@ public class TestForm extends TestCase { public void testVersion() throws Exception { WebConversation conversation = new WebConversation(); // Fill the form and submit it - WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()); + WebRequest request = new GetMethodWebRequest(getServerUrl()); WebResponse response = TestUtils.tryGetResponse(conversation, request ); WebForm formUMLText = response.getForms()[0]; formUMLText.setParameter("text", "version"); @@ -51,7 +54,7 @@ public class TestForm extends TestCase { public void testEmptyText() throws Exception { WebConversation conversation = new WebConversation(); // Fill the form and submit it - WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()); + WebRequest request = new GetMethodWebRequest(getServerUrl()); WebResponse response = TestUtils.tryGetResponse(conversation, request ); WebForm formUMLText = response.getForms()[0]; formUMLText.setParameter("text", ""); @@ -66,14 +69,14 @@ public class TestForm extends TestCase { // Ensure there is no image assertEquals( 0, response.getImages().length); } - + /** * Verifies that when the encoded URL is empty, no image is generated */ public void testEmptyUrl() throws Exception { WebConversation conversation = new WebConversation(); // Fill the form and submit it - WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl() ); + WebRequest request = new GetMethodWebRequest(getServerUrl()); WebResponse response = TestUtils.tryGetResponse(conversation, request ); WebForm formUrl = response.getForms()[1]; formUrl.setParameter("url", ""); @@ -88,14 +91,14 @@ public class TestForm extends TestCase { // Ensure there is no image assertEquals( 0, response.getImages().length); } - + /** * Verifies that a ditaa diagram is generated */ public void testDitaaText() throws Exception { WebConversation conversation = new WebConversation(); // Fill the form and submit it - WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl() ); + WebRequest request = new GetMethodWebRequest(getServerUrl()); WebResponse response = TestUtils.tryGetResponse(conversation, request ); WebForm formDitaaText = response.getForms()[0]; formDitaaText.setParameter("text", "@startditaa \n*--> \n@endditaa"); diff --git a/test/src/net/sourceforge/plantuml/servlet/TestImage.java b/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java similarity index 80% rename from test/src/net/sourceforge/plantuml/servlet/TestImage.java rename to src/test/java/net/sourceforge/plantuml/servlet/TestImage.java index ab4e936..be183ba 100644 --- a/test/src/net/sourceforge/plantuml/servlet/TestImage.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java @@ -1,26 +1,28 @@ package net.sourceforge.plantuml.servlet; -import junit.framework.TestCase; -import com.meterware.httpunit.*; - import java.io.ByteArrayOutputStream; import java.io.InputStream; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; -import java.text.SimpleDateFormat; -public class TestImage extends TestCase { +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +public class TestImage extends WebappTestCase { /** * 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"); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/AqijAixCpmC0"); WebResponse response = conversation.getResource( request); // Analyze response // Verifies the Content-Type header assertEquals( "Response content type is not PNG", "image/png", response.getContentType()); - // Get the image and verify its size + // Get the image and verify its size InputStream responseStream = response.getInputStream(); ByteArrayOutputStream imageStream = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; @@ -33,7 +35,7 @@ public class TestImage extends TestCase { byte[] inMemoryImage = imageStream.toByteArray(); int diagramLen = inMemoryImage.length; assertTrue( diagramLen > 10000); - assertTrue( diagramLen < 20000); + assertTrue( diagramLen < 20000); } /** @@ -41,8 +43,8 @@ public class TestImage extends TestCase { */ public void testDiagramHttpHeader() throws Exception { WebConversation conversation = new WebConversation(); - // Bob -> Alice : hello - WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); + // Bob -> Alice : hello + WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); WebResponse response = conversation.getResource( request); // Analyze response // Verifies the Content-Type header diff --git a/test/src/net/sourceforge/plantuml/servlet/TestProxy.java b/src/test/java/net/sourceforge/plantuml/servlet/TestProxy.java similarity index 72% rename from test/src/net/sourceforge/plantuml/servlet/TestProxy.java rename to src/test/java/net/sourceforge/plantuml/servlet/TestProxy.java index b36d9b1..2542589 100644 --- a/test/src/net/sourceforge/plantuml/servlet/TestProxy.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestProxy.java @@ -1,24 +1,27 @@ package net.sourceforge.plantuml.servlet; -import junit.framework.TestCase; -import com.meterware.httpunit.*; - import java.io.ByteArrayOutputStream; import java.io.InputStream; -public class TestProxy extends TestCase { +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebForm; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +public class TestProxy extends WebappTestCase { /** * Verifies the proxified reception of the default Bob and Alice diagram */ public void testDefaultProxy() throws Exception { WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"proxy/" - +TestUtils.getServerUrl()+"welcome"); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/" + + getServerUrl() + "welcome"); WebResponse response = conversation.getResource( request); // Analyze response // Verifies the Content-Type header //assertEquals( "Response content type is not PNG", "image/png", response.getContentType()); - // Get the image and verify its size (~1533 bytes) + // Get the image and verify its size (~1600 bytes) InputStream responseStream = response.getInputStream(); ByteArrayOutputStream imageStream = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; @@ -31,7 +34,7 @@ public class TestProxy extends TestCase { byte[] inMemoryImage = imageStream.toByteArray(); int diagramLen = inMemoryImage.length; assertTrue( diagramLen > 1500); - assertTrue( diagramLen < 1600); + assertTrue( diagramLen < 1700); } /** @@ -39,8 +42,8 @@ public class TestProxy extends TestCase { */ public void testInvalidUrl() throws Exception { WebConversation conversation = new WebConversation(); - // Try to proxify an invalid address - WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"proxy/invalidURL"); + // Try to proxify an invalid address + WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/invalidURL"); WebResponse response = conversation.getResource( request); // Analyze response, it must be the empty form // Verifies the Content-Type header diff --git a/test/src/net/sourceforge/plantuml/servlet/TestSVG.java b/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java similarity index 64% rename from test/src/net/sourceforge/plantuml/servlet/TestSVG.java rename to src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java index 9f4de86..4a960df 100644 --- a/test/src/net/sourceforge/plantuml/servlet/TestSVG.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java @@ -1,19 +1,17 @@ package net.sourceforge.plantuml.servlet; -import junit.framework.TestCase; -import com.meterware.httpunit.*; +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; -import java.util.Date; -import java.util.Locale; -import java.text.SimpleDateFormat; - -public class TestSVG extends TestCase { +public class TestSVG extends WebappTestCase { /** * Verifies the generation of the SVG for the Bob -> Alice sample */ public void testSimpleSequenceDiagram() throws Exception { WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); WebResponse response = conversation.getResource( request); // Analyze response // Verifies the Content-Type header @@ -22,7 +20,7 @@ public class TestSVG extends TestCase { String diagram = response.getText(); int diagramLen = diagram.length(); assertTrue( diagramLen > 1700); - assertTrue( diagramLen < 1800); + assertTrue( diagramLen < 1800); } } diff --git a/test/src/net/sourceforge/plantuml/servlet/TestUtils.java b/src/test/java/net/sourceforge/plantuml/servlet/TestUtils.java similarity index 100% rename from test/src/net/sourceforge/plantuml/servlet/TestUtils.java rename to src/test/java/net/sourceforge/plantuml/servlet/TestUtils.java diff --git a/src/test/java/net/sourceforge/plantuml/servlet/WebappTestCase.java b/src/test/java/net/sourceforge/plantuml/servlet/WebappTestCase.java new file mode 100644 index 0000000..25c5172 --- /dev/null +++ b/src/test/java/net/sourceforge/plantuml/servlet/WebappTestCase.java @@ -0,0 +1,31 @@ +package net.sourceforge.plantuml.servlet; + +import junit.framework.TestCase; + +public abstract class WebappTestCase extends TestCase { + + private ServerUtils serverUtils; + + public WebappTestCase() { + super(); + } + + public WebappTestCase(String name) { + super(name); + } + + @Override + public void setUp() throws Exception { + serverUtils = new ServerUtils(true); + } + + @Override + public void tearDown() throws Exception { + serverUtils.stopServer(); + } + + protected String getServerUrl() { + return serverUtils.getServerUrl(); + } + +} diff --git a/test/lib/httpunit.jar b/test/lib/httpunit.jar deleted file mode 100644 index 8656e8b..0000000 Binary files a/test/lib/httpunit.jar and /dev/null differ diff --git a/test/lib/js-1.6R5.jar b/test/lib/js-1.6R5.jar deleted file mode 100644 index 2b92650..0000000 Binary files a/test/lib/js-1.6R5.jar and /dev/null differ diff --git a/test/lib/jtidy-4aug2000r7-dev.jar b/test/lib/jtidy-4aug2000r7-dev.jar deleted file mode 100644 index 0eebfa6..0000000 Binary files a/test/lib/jtidy-4aug2000r7-dev.jar and /dev/null differ diff --git a/test/lib/junit-3.8.1.jar b/test/lib/junit-3.8.1.jar deleted file mode 100644 index 674d71e..0000000 Binary files a/test/lib/junit-3.8.1.jar and /dev/null differ diff --git a/test/src/net/sourceforge/plantuml/servlet/TestAsciiArt.java b/test/src/net/sourceforge/plantuml/servlet/TestAsciiArt.java deleted file mode 100644 index d9fbe8f..0000000 --- a/test/src/net/sourceforge/plantuml/servlet/TestAsciiArt.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.sourceforge.plantuml.servlet; - -import junit.framework.TestCase; -import com.meterware.httpunit.*; - -import java.util.Date; -import java.util.Locale; -import java.text.SimpleDateFormat; - -public class TestAsciiArt extends TestCase { - /** - * Verifies the generation of the ascii art for the Bob -> Alice sample - */ - public void testSimpleSequenceDiagram() throws Exception { - WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"txt/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); - WebResponse response = conversation.getResource( request); - // Analyze response - // Verifies the Content-Type header - assertEquals( "Response content type is not TEXT PLAIN", "text/plain", response.getContentType()); - // Get the content and verify its size - String diagram = response.getText(); - int diagramLen = diagram.length(); - assertTrue( diagramLen > 200); - assertTrue( diagramLen < 250); - } - -}