1
0
mirror of https://github.com/octoleo/plantuml-server.git synced 2025-02-07 13:08:25 +00:00

Better support of ditaa diagrams.

This commit is contained in:
Maxime Sinclair 2011-08-30 16:39:12 +02:00
parent c40a3e5504
commit b75cf0b7cf
2 changed files with 39 additions and 10 deletions

View File

@ -47,21 +47,28 @@ public abstract class UmlDiagramService extends HttpServlet {
throws IOException, ServletException {
// build the UML source from the compressed request parameter
String text = URLDecoder.decode( getSource( request.getRequestURI()), "UTF-8");
String text = URLDecoder.decode( getSource(request.getRequestURI()), "UTF-8");
Transcoder transcoder = getTranscoder();
text = transcoder.decode(text);
StringBuilder plantUmlSource = new StringBuilder();
plantUmlSource.append("@startuml\n");
plantUmlSource.append( text);
if (text.endsWith("\n") == false) {
plantUmlSource.append("\n");
// encapsulate the UML syntax if necessary
String uml;
if (text.startsWith("@start")) {
uml = text;
} else {
StringBuilder plantUmlSource = new StringBuilder();
plantUmlSource.append( "@startuml\n");
plantUmlSource.append( text);
if (text.endsWith( "\n") == false) {
plantUmlSource.append( "\n");
}
plantUmlSource.append( "@enduml");
uml = plantUmlSource.toString();
}
plantUmlSource.append("@enduml");
final String uml = plantUmlSource.toString();
// generate the response
DiagramResponse dr = new DiagramResponse( response, getOutputFormat());
dr.sendDiagram( uml);
dr.sendDiagram(uml);
dr = null;
}

View File

@ -68,7 +68,7 @@ public class TestForm extends TestCase {
}
/**
* Verifies that when the encoded URL is empty, the default image is generated
* Verifies that when the encoded URL is empty, no image is generated
*/
public void testEmptyUrl() throws Exception {
WebConversation conversation = new WebConversation();
@ -88,5 +88,27 @@ 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() );
WebResponse response = TestUtils.tryGetResponse(conversation, request );
WebForm formDitaaText = response.getForms()[0];
formDitaaText.setParameter("text", "@startditaa \n*--> \n@endditaa");
response = formDitaaText.submit();
// Analyze response
WebForm forms[] = response.getForms();
assertEquals( 2, forms.length );
// Ensure the Text field is correct
assertTrue( forms[0].getParameterValue("text").startsWith( "@startditaa"));
// Ensure the URL field is correct
assertTrue( forms[1].getParameterValue("url").endsWith("/img/SoWkIImgISaiIKnKuDBIrRLJu798pKi12m00"));
// Ensure the image is present
assertEquals( 1, response.getImages().length);
}
}