1
0
mirror of https://github.com/octoleo/plantuml-server.git synced 2024-12-22 08:48:54 +00:00

[TASK] Refactoring of the TestUtils class

tryGetResponse method deleted
Compressed diagram strings added as constant strings
This commit is contained in:
Maxime Sinclair 2013-07-17 14:30:44 +02:00
parent 97f00051f0
commit 779351844c
5 changed files with 25 additions and 31 deletions

View File

@ -12,7 +12,7 @@ public class TestAsciiArt extends WebappTestCase {
*/ */
public void testSimpleSequenceDiagram() throws Exception { public void testSimpleSequenceDiagram() throws Exception {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(getServerUrl() + "txt/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); WebRequest request = new GetMethodWebRequest(getServerUrl() + "txt/" + TestUtils.SEQBOB);
WebResponse response = conversation.getResource(request); WebResponse response = conversation.getResource(request);
// Analyze response // Analyze response
// Verifies the Content-Type header // Verifies the Content-Type header

View File

@ -14,12 +14,12 @@ public class TestForm extends WebappTestCase {
public void testWelcomePage() throws Exception { public void testWelcomePage() throws Exception {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(getServerUrl()); WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request); WebResponse response = conversation.getResponse(request);
// Analyze response // Analyze response
WebForm forms[] = response.getForms(); WebForm forms[] = response.getForms();
assertEquals(2, forms.length); assertEquals(2, forms.length);
assertEquals("url", forms[1].getParameterNames()[0]); 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 // Ensure the generated image is present
assertEquals(1, response.getImages().length); assertEquals(1, response.getImages().length);
@ -32,7 +32,7 @@ public class TestForm extends WebappTestCase {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
// Fill the form and submit it // Fill the form and submit it
WebRequest request = new GetMethodWebRequest(getServerUrl()); WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request); WebResponse response = conversation.getResponse(request);
WebForm formUMLText = response.getForms()[0]; WebForm formUMLText = response.getForms()[0];
formUMLText.setParameter("text", "version"); formUMLText.setParameter("text", "version");
response = formUMLText.submit(); response = formUMLText.submit();
@ -42,7 +42,7 @@ public class TestForm extends WebappTestCase {
// Ensure the Text field is correct // Ensure the Text field is correct
assertEquals("version", forms[0].getParameterValue("text")); assertEquals("version", forms[0].getParameterValue("text"));
// Ensure the URL field is correct // 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 // Ensure the image is present
assertEquals(1, response.getImages().length); assertEquals(1, response.getImages().length);
} }
@ -54,7 +54,7 @@ public class TestForm extends WebappTestCase {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
// Fill the form and submit it // Fill the form and submit it
WebRequest request = new GetMethodWebRequest(getServerUrl()); WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request); WebResponse response = conversation.getResponse(request);
WebForm formUMLText = response.getForms()[0]; WebForm formUMLText = response.getForms()[0];
formUMLText.setParameter("text", ""); formUMLText.setParameter("text", "");
response = formUMLText.submit(); response = formUMLText.submit();
@ -76,7 +76,7 @@ public class TestForm extends WebappTestCase {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
// Fill the form and submit it // Fill the form and submit it
WebRequest request = new GetMethodWebRequest(getServerUrl()); WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request); WebResponse response = conversation.getResponse(request);
WebForm formUrl = response.getForms()[1]; WebForm formUrl = response.getForms()[1];
formUrl.setParameter("url", ""); formUrl.setParameter("url", "");
response = formUrl.submit(); response = formUrl.submit();
@ -98,7 +98,7 @@ public class TestForm extends WebappTestCase {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
// Fill the form and submit it // Fill the form and submit it
WebRequest request = new GetMethodWebRequest(getServerUrl()); WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request); WebResponse response = conversation.getResponse(request);
WebForm formDitaaText = response.getForms()[0]; WebForm formDitaaText = response.getForms()[0];
formDitaaText.setParameter("text", "@startditaa \n*--> \n@endditaa"); formDitaaText.setParameter("text", "@startditaa \n*--> \n@endditaa");
response = formDitaaText.submit(); response = formDitaaText.submit();

View File

@ -17,7 +17,7 @@ public class TestImage extends WebappTestCase {
*/ */
public void testVersionImage() throws Exception { public void testVersionImage() throws Exception {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/AqijAixCpmC0"); WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/" + TestUtils.VERSION);
WebResponse response = conversation.getResource(request); WebResponse response = conversation.getResource(request);
// Analyze response // Analyze response
// Verifies the Content-Type header // Verifies the Content-Type header
@ -44,7 +44,7 @@ public class TestImage extends WebappTestCase {
public void testDiagramHttpHeader() throws Exception { public void testDiagramHttpHeader() throws Exception {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
// Bob -> Alice : hello // Bob -> Alice : hello
WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/" + TestUtils.SEQBOB);
WebResponse response = conversation.getResource(request); WebResponse response = conversation.getResource(request);
// Analyze response // Analyze response
// Verifies the Content-Type header // Verifies the Content-Type header

View File

@ -13,7 +13,7 @@ public class TestSVG extends WebappTestCase {
*/ */
public void testSimpleSequenceDiagram() throws Exception { public void testSimpleSequenceDiagram() throws Exception {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/" + TestUtils.SEQBOB);
WebResponse response = conversation.getResource(request); WebResponse response = conversation.getResource(request);
// Analyze response // Analyze response
// Verifies the Content-Type header // Verifies the Content-Type header
@ -30,7 +30,7 @@ public class TestSVG extends WebappTestCase {
*/ */
public void testSequenceDiagramContent() throws Exception { public void testSequenceDiagramContent() throws Exception {
WebConversation conversation = new WebConversation(); WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/" + TestUtils.SEQBOB);
WebResponse response = conversation.getResource(request); WebResponse response = conversation.getResource(request);
// Analyze response // Analyze response
// Get the data contained in the XML // Get the data contained in the XML

View File

@ -1,29 +1,23 @@
package net.sourceforge.plantuml.servlet; package net.sourceforge.plantuml.servlet;
import com.meterware.httpunit.*;
/** /**
* Utility class for HttpUnit conversations * Utility class for the unit tests
*/ */
public class TestUtils { public class TestUtils {
/** /*
* Try getting a response for the given Conversation and Request show an error message if a 404 error appears * Theses strings are the compressed form of a PlantUML diagram.
*
* @param conversation The conversation to use
* @param request
* @return The response
* @throws nfe If getting the response fails
*/ */
public static WebResponse tryGetResponse(WebConversation conversation, WebRequest request) throws Exception {
WebResponse response = null; /*
try { * version
response = conversation.getResponse(request); */
} catch (HttpNotFoundException nfe) { public static final String VERSION = "AqijAixCpmC0";
System.err.println("The URL '" + request.getURL() + "' is no more active");
throw nfe; /*
} * Bob -> Alice : hello
return response; */
} public static final String SEQBOB = "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000";
} }