Better support of ditaa diagrams.
This commit is contained in:
@@ -47,21 +47,28 @@ public abstract class UmlDiagramService extends HttpServlet {
|
|||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
|
||||||
// build the UML source from the compressed request parameter
|
// 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();
|
Transcoder transcoder = getTranscoder();
|
||||||
text = transcoder.decode(text);
|
text = transcoder.decode(text);
|
||||||
StringBuilder plantUmlSource = new StringBuilder();
|
|
||||||
plantUmlSource.append("@startuml\n");
|
// encapsulate the UML syntax if necessary
|
||||||
plantUmlSource.append( text);
|
String uml;
|
||||||
if (text.endsWith("\n") == false) {
|
if (text.startsWith("@start")) {
|
||||||
plantUmlSource.append("\n");
|
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
|
// generate the response
|
||||||
DiagramResponse dr = new DiagramResponse( response, getOutputFormat());
|
DiagramResponse dr = new DiagramResponse( response, getOutputFormat());
|
||||||
dr.sendDiagram( uml);
|
dr.sendDiagram(uml);
|
||||||
dr = null;
|
dr = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
public void testEmptyUrl() throws Exception {
|
||||||
WebConversation conversation = new WebConversation();
|
WebConversation conversation = new WebConversation();
|
||||||
@@ -88,5 +88,27 @@ public class TestForm extends TestCase {
|
|||||||
// Ensure there is no image
|
// Ensure there is no image
|
||||||
assertEquals( 0, response.getImages().length);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user