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:
parent
97f00051f0
commit
779351844c
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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";
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user