From 779351844c50fcd36c4e1b1d092286c945e34100 Mon Sep 17 00:00:00 2001 From: Maxime Sinclair Date: Wed, 17 Jul 2013 14:30:44 +0200 Subject: [PATCH] [TASK] Refactoring of the TestUtils class tryGetResponse method deleted Compressed diagram strings added as constant strings --- .../plantuml/servlet/TestAsciiArt.java | 2 +- .../plantuml/servlet/TestForm.java | 14 ++++---- .../plantuml/servlet/TestImage.java | 4 +-- .../sourceforge/plantuml/servlet/TestSVG.java | 4 +-- .../plantuml/servlet/TestUtils.java | 32 ++++++++----------- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java index 49c84ac..4143ca6 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java @@ -12,7 +12,7 @@ public class TestAsciiArt extends WebappTestCase { */ public void testSimpleSequenceDiagram() throws Exception { WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest(getServerUrl() + "txt/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "txt/" + TestUtils.SEQBOB); WebResponse response = conversation.getResource(request); // Analyze response // Verifies the Content-Type header diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java b/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java index f1f6852..2cb32ed 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java @@ -14,12 +14,12 @@ public class TestForm extends WebappTestCase { public void testWelcomePage() throws Exception { WebConversation conversation = new WebConversation(); WebRequest request = new GetMethodWebRequest(getServerUrl()); - WebResponse response = TestUtils.tryGetResponse(conversation, request); + WebResponse response = conversation.getResponse(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")); + assertTrue(forms[1].getParameterValue("url").endsWith("/img/" + TestUtils.SEQBOB)); // Ensure the generated image is present assertEquals(1, response.getImages().length); @@ -32,7 +32,7 @@ public class TestForm extends WebappTestCase { WebConversation conversation = new WebConversation(); // Fill the form and submit it WebRequest request = new GetMethodWebRequest(getServerUrl()); - WebResponse response = TestUtils.tryGetResponse(conversation, request); + WebResponse response = conversation.getResponse(request); WebForm formUMLText = response.getForms()[0]; formUMLText.setParameter("text", "version"); response = formUMLText.submit(); @@ -42,7 +42,7 @@ public class TestForm extends WebappTestCase { // 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")); + assertTrue(forms[1].getParameterValue("url").endsWith("/img/" + TestUtils.VERSION)); // Ensure the image is present assertEquals(1, response.getImages().length); } @@ -54,7 +54,7 @@ public class TestForm extends WebappTestCase { WebConversation conversation = new WebConversation(); // Fill the form and submit it WebRequest request = new GetMethodWebRequest(getServerUrl()); - WebResponse response = TestUtils.tryGetResponse(conversation, request); + WebResponse response = conversation.getResponse(request); WebForm formUMLText = response.getForms()[0]; formUMLText.setParameter("text", ""); response = formUMLText.submit(); @@ -76,7 +76,7 @@ public class TestForm extends WebappTestCase { WebConversation conversation = new WebConversation(); // Fill the form and submit it WebRequest request = new GetMethodWebRequest(getServerUrl()); - WebResponse response = TestUtils.tryGetResponse(conversation, request); + WebResponse response = conversation.getResponse(request); WebForm formUrl = response.getForms()[1]; formUrl.setParameter("url", ""); response = formUrl.submit(); @@ -98,7 +98,7 @@ public class TestForm extends WebappTestCase { WebConversation conversation = new WebConversation(); // Fill the form and submit it WebRequest request = new GetMethodWebRequest(getServerUrl()); - WebResponse response = TestUtils.tryGetResponse(conversation, request); + WebResponse response = conversation.getResponse(request); WebForm formDitaaText = response.getForms()[0]; formDitaaText.setParameter("text", "@startditaa \n*--> \n@endditaa"); response = formDitaaText.submit(); diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java b/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java index 6d746d6..b0f6cd5 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java @@ -17,7 +17,7 @@ public class TestImage extends WebappTestCase { */ public void testVersionImage() throws Exception { WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/AqijAixCpmC0"); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/" + TestUtils.VERSION); WebResponse response = conversation.getResource(request); // Analyze response // Verifies the Content-Type header @@ -44,7 +44,7 @@ public class TestImage extends WebappTestCase { public void testDiagramHttpHeader() throws Exception { WebConversation conversation = new WebConversation(); // Bob -> Alice : hello - WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/" + TestUtils.SEQBOB); WebResponse response = conversation.getResource(request); // Analyze response // Verifies the Content-Type header diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java b/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java index f6bbebe..526baab 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java @@ -13,7 +13,7 @@ public class TestSVG extends WebappTestCase { */ public void testSimpleSequenceDiagram() throws Exception { WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/" + TestUtils.SEQBOB); WebResponse response = conversation.getResource(request); // Analyze response // Verifies the Content-Type header @@ -30,7 +30,7 @@ public class TestSVG extends WebappTestCase { */ public void testSequenceDiagramContent() throws Exception { WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/" + TestUtils.SEQBOB); WebResponse response = conversation.getResource(request); // Analyze response // Get the data contained in the XML diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestUtils.java b/src/test/java/net/sourceforge/plantuml/servlet/TestUtils.java index 5a2056d..5c52809 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestUtils.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestUtils.java @@ -1,29 +1,23 @@ package net.sourceforge.plantuml.servlet; -import com.meterware.httpunit.*; /** - * Utility class for HttpUnit conversations + * Utility class for the unit tests */ public class TestUtils { - /** - * 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 nfe If getting the response fails + /* + * Theses strings are the compressed form of a PlantUML diagram. */ - 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 no more active"); - throw nfe; - } - return response; - } + + /* + * version + */ + public static final String VERSION = "AqijAixCpmC0"; + + /* + * Bob -> Alice : hello + */ + public static final String SEQBOB = "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"; }