frontend 2.0: initial version
- auto refresh function
- light and dark theme
- monaco editor (vscode) with "apex" as syntax highlighting language
* apex seems to work quite fine (better than no highlighting)
* future possibility: own plantuml language syntax support
* future possibility: autocomplete (to much work but maybe partial)
- implemented example for `!theme ...`
- implemented example for `<&icon>`
* future possibility: code validation
- implemented example for `@start...` and `@end...`:
* should be the first or last command
* should be of the some type (e.g. `@startyaml` and @endyaml)
* should be used exactly once per document/diagram
- editor and preview is splitable into two windows like the
"Extract window" functionality on
(plantuml.com)[https://www.plantuml.com/plantuml]
- multi index / multi paging diagram support
- diagram can be displayed/rended as PNG, SVG, ASCII Art or PDF
- Ctrl+s download the PlantUML Code as code file (diagram.puml)
- Ctrl+, opens the settings and Esc closes the settings
This commit is contained in:
@@ -8,7 +8,7 @@ public class AllTests extends TestSuite {
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite(AllTests.class.getName());
|
||||
// $JUnit-BEGIN$
|
||||
suite.addTestSuite(TestForm.class);
|
||||
suite.addTestSuite(TestWebUI.class);
|
||||
suite.addTestSuite(TestImage.class);
|
||||
suite.addTestSuite(TestAsciiArt.class);
|
||||
suite.addTestSuite(TestSVG.class);
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.utils.TestUtils;
|
||||
import net.sourceforge.plantuml.servlet.utils.WebappTestCase;
|
||||
|
||||
|
||||
public class TestAsciiArt extends WebappTestCase {
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.utils.TestUtils;
|
||||
import net.sourceforge.plantuml.servlet.utils.WebappTestCase;
|
||||
|
||||
|
||||
public class TestAsciiCoder extends WebappTestCase {
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.utils.WebappTestCase;
|
||||
|
||||
|
||||
public class TestCharset extends WebappTestCase {
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.utils.TestUtils;
|
||||
import net.sourceforge.plantuml.servlet.utils.WebappTestCase;
|
||||
|
||||
|
||||
public class TestCheck extends WebappTestCase {
|
||||
|
||||
|
||||
@@ -1,303 +0,0 @@
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.html.DomElement;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlForm;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlImage;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlInput;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
|
||||
|
||||
|
||||
public class TestForm extends WebappTestCase {
|
||||
|
||||
/**
|
||||
* Verifies that the welcome page has exactly two form with the Bob --> Alice sample
|
||||
*/
|
||||
public void testWelcomePage() throws IOException {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
HtmlPage page = webClient.getPage(getServerUrl());
|
||||
// Analyze response
|
||||
List<HtmlForm> forms = page.getForms();
|
||||
assertEquals(2, forms.size());
|
||||
// Ensure the Text field is correct
|
||||
String text = ((HtmlTextArea)(forms.get(0).getFirstByXPath("//textarea[contains(@name, 'text')]"))).getTextContent();
|
||||
assertEquals(TestUtils.SEQBOBCODE, text);
|
||||
// Ensure the URL field is correct
|
||||
HtmlInput url = forms.get(1).getInputByName("url");
|
||||
assertNotNull(url);
|
||||
assertTrue(url.getAttribute("value").endsWith("/png/" + TestUtils.SEQBOB));
|
||||
// Ensure the generated image is present
|
||||
HtmlImage img = page.getFirstByXPath("//img[contains(@alt, 'PlantUML diagram')]");
|
||||
assertNotEquals(0, img.getImageReader().getHeight(0)); // 131
|
||||
assertNotEquals(0, img.getImageReader().getWidth(0)); // 120
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the version image is generated
|
||||
*/
|
||||
public void testVersion() throws IOException {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
HtmlPage page = webClient.getPage(getServerUrl());
|
||||
page.initialize();
|
||||
// Fill the form and submit it
|
||||
page.executeJavaScript("document.myCodeMirror.setValue('version')");
|
||||
HtmlForm form = page.getForms().get(0);
|
||||
HtmlSubmitInput btn = form.getFirstByXPath("//input[contains(@type, 'submit')]");
|
||||
page = btn.click();
|
||||
// Analyze response
|
||||
List<HtmlForm> forms = page.getForms();
|
||||
assertEquals(2, forms.size());
|
||||
// Ensure the Text field is correct
|
||||
String text = ((HtmlTextArea)(forms.get(0).getFirstByXPath("//textarea[contains(@name, 'text')]"))).getTextContent();
|
||||
assertEquals(TestUtils.VERSIONCODE, text);
|
||||
// Ensure the URL field is correct
|
||||
HtmlInput url = forms.get(1).getInputByName("url");
|
||||
assertNotNull(url);
|
||||
assertTrue(url.getAttribute("value").endsWith("/png/" + TestUtils.VERSION));
|
||||
// Ensure the generated image is present
|
||||
HtmlImage img = page.getFirstByXPath("//img[contains(@alt, 'PlantUML diagram')]");
|
||||
assertNotEquals(0, img.getImageReader().getHeight(0)); // 186
|
||||
assertNotEquals(0, img.getImageReader().getWidth(0)); // 519
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that when the UML text is empty, default page and image is generated
|
||||
*/
|
||||
public void testEmptyText() throws IOException {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
HtmlPage page = webClient.getPage(getServerUrl());
|
||||
page.initialize();
|
||||
// Fill the form and submit it
|
||||
page.executeJavaScript("document.myCodeMirror.setValue('')");
|
||||
HtmlForm form = page.getForms().get(0);
|
||||
HtmlSubmitInput btn = form.getFirstByXPath("//input[contains(@type, 'submit')]");
|
||||
page = btn.click();
|
||||
// Analyze response
|
||||
List<HtmlForm> forms = page.getForms();
|
||||
assertEquals(2, forms.size());
|
||||
// Ensure the Text field is correct
|
||||
String text = ((HtmlTextArea)(forms.get(0).getFirstByXPath("//textarea[contains(@name, 'text')]"))).getTextContent();
|
||||
assertEquals(TestUtils.SEQBOBCODE, text);
|
||||
// Ensure the URL field is correct
|
||||
HtmlInput url = forms.get(1).getInputByName("url");
|
||||
assertNotNull(url);
|
||||
assertTrue(url.getAttribute("value").endsWith("/png/" + TestUtils.SEQBOB));
|
||||
// Ensure the generated image is present
|
||||
HtmlImage img = page.getFirstByXPath("//img[contains(@alt, 'PlantUML diagram')]");
|
||||
assertNotEquals(0, img.getImageReader().getHeight(0)); // 131
|
||||
assertNotEquals(0, img.getImageReader().getWidth(0)); // 120
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that when the encoded URL is empty, default page and image is generated
|
||||
*/
|
||||
public void testEmptyUrl() throws IOException {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
HtmlPage page = webClient.getPage(getServerUrl());
|
||||
page.initialize();
|
||||
// Fill the form and submit it
|
||||
List<HtmlForm> forms = page.getForms();
|
||||
HtmlInput url = forms.get(1).getInputByName("url");
|
||||
url.setAttribute("value", "");
|
||||
HtmlSubmitInput btn = forms.get(1).getFirstByXPath("//input[contains(@type, 'submit')]");
|
||||
page = btn.click();
|
||||
// Analyze response
|
||||
forms = page.getForms();
|
||||
assertEquals(2, forms.size());
|
||||
// Ensure the Text field is correct
|
||||
String text = ((HtmlTextArea)(forms.get(0).getFirstByXPath("//textarea[contains(@name, 'text')]"))).getTextContent();
|
||||
assertEquals(TestUtils.SEQBOBCODE, text);
|
||||
// Ensure the URL field is correct
|
||||
url = forms.get(1).getInputByName("url");
|
||||
assertNotNull(url);
|
||||
assertTrue(url.getAttribute("value").endsWith("/png/" + TestUtils.SEQBOB));
|
||||
// Ensure the generated image is present
|
||||
HtmlImage img = page.getFirstByXPath("//img[contains(@alt, 'PlantUML diagram')]");
|
||||
assertNotEquals(0, img.getImageReader().getHeight(0)); // 131
|
||||
assertNotEquals(0, img.getImageReader().getWidth(0)); // 120
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a ditaa diagram is generated
|
||||
*/
|
||||
public void testDitaaText() throws IOException {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
HtmlPage page = webClient.getPage(getServerUrl());
|
||||
page.initialize();
|
||||
// Fill the form and submit it
|
||||
page.executeJavaScript("document.myCodeMirror.setValue(`@startditaa \n*--> \n@endditaa`)");
|
||||
HtmlForm form = page.getForms().get(0);
|
||||
HtmlSubmitInput btn = form.getFirstByXPath("//input[contains(@type, 'submit')]");
|
||||
page = btn.click();
|
||||
// Analyze response
|
||||
List<HtmlForm> forms = page.getForms();
|
||||
assertEquals(2, forms.size());
|
||||
// Ensure the Text field is correct
|
||||
String text = ((HtmlTextArea)(forms.get(0).getFirstByXPath("//textarea[contains(@name, 'text')]"))).getTextContent();
|
||||
assertEquals("@startditaa \n*--> \n@endditaa", text);
|
||||
// Ensure the URL field is correct
|
||||
HtmlInput url = forms.get(1).getInputByName("url");
|
||||
assertNotNull(url);
|
||||
assertTrue(url.getAttribute("value").endsWith("/png/SoWkIImgISaiIKnKuDBIrRLJu798pKi12m00"));
|
||||
// Ensure the generated image is present
|
||||
HtmlImage img = page.getFirstByXPath("//img[contains(@alt, 'PlantUML diagram')]");
|
||||
assertNotEquals(0, img.getImageReader().getHeight(0)); // 70
|
||||
assertNotEquals(0, img.getImageReader().getWidth(0)); // 90
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that an image map is produced if the diagram contains a link
|
||||
*/
|
||||
public void testImageMap() throws IOException {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
HtmlPage page = webClient.getPage(getServerUrl());
|
||||
page.initialize();
|
||||
// Fill the form and submit it
|
||||
page.executeJavaScript("document.myCodeMirror.setValue(`@startuml\nBob -> Alice : [[http://yahoo.com]] Hello\n@enduml`)");
|
||||
HtmlForm form = page.getForms().get(0);
|
||||
HtmlSubmitInput btn = form.getFirstByXPath("//input[contains(@type, 'submit')]");
|
||||
page = btn.click();
|
||||
// Analyze response
|
||||
List<HtmlForm> forms = page.getForms();
|
||||
assertEquals(2, forms.size());
|
||||
// Ensure the Text field is correct
|
||||
String text = ((HtmlTextArea)(forms.get(0).getFirstByXPath("//textarea[contains(@name, 'text')]"))).getTextContent();
|
||||
assertEquals("@startuml\nBob -> Alice : [[http://yahoo.com]] Hello\n@enduml", text);
|
||||
// Ensure the URL field is correct
|
||||
HtmlInput url = forms.get(1).getInputByName("url");
|
||||
assertNotNull(url);
|
||||
assertTrue(url.getAttribute("value").endsWith("/png/SyfFKj2rKt3CoKnELR1IY8xEA2afiDBNhqpCoC_NIyxFZOrLy4ZDoSa70000"));
|
||||
// Ensure the generated image is present
|
||||
HtmlImage img = page.getFirstByXPath("//img[contains(@alt, 'PlantUML diagram')]");
|
||||
assertNotEquals(0, img.getImageReader().getHeight(0)); // 131
|
||||
assertNotEquals(0, img.getImageReader().getWidth(0)); // 231
|
||||
// Ensure the image map is present
|
||||
DomElement map = page.getElementById("plantuml_map");
|
||||
assertNotNull(map);
|
||||
assertEquals(1, map.getChildElementCount());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that when the encoded source is specified as an URL parameter
|
||||
* the diagram is displayed and the source is decoded
|
||||
*/
|
||||
public void testUrlParameter() throws IOException {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
// Submit the request with a url parameter
|
||||
HtmlPage page = webClient.getPage(getServerUrl() + "/form?url=" + TestUtils.SEQBOB);
|
||||
page.initialize();
|
||||
// Analyze response
|
||||
List<HtmlForm> forms = page.getForms();
|
||||
assertEquals(2, forms.size());
|
||||
// Ensure the Text field is correct
|
||||
String text = ((HtmlTextArea)(forms.get(0).getFirstByXPath("//textarea[contains(@name, 'text')]"))).getTextContent();
|
||||
assertEquals(TestUtils.SEQBOBCODE, text);
|
||||
// Ensure the URL field is correct
|
||||
HtmlInput url = forms.get(1).getInputByName("url");
|
||||
assertNotNull(url);
|
||||
assertTrue(url.getAttribute("value").endsWith("/png/" + TestUtils.SEQBOB));
|
||||
// Ensure the generated image is present
|
||||
HtmlImage img = page.getFirstByXPath("//img[contains(@alt, 'PlantUML diagram')]");
|
||||
assertNotEquals(0, img.getImageReader().getHeight(0)); // 131
|
||||
assertNotEquals(0, img.getImageReader().getWidth(0)); // 120
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that an multipage diagram renders correct given index.
|
||||
*
|
||||
* Bob -> Alice : hello
|
||||
* newpage
|
||||
* Bob <- Alice : hello
|
||||
* Bob -> Alice : let's talk
|
||||
* Bob <- Alice : better not
|
||||
* Bob -> Alice : <&rain> bye
|
||||
* newpage
|
||||
* Bob <- Alice : bye
|
||||
*/
|
||||
public void testIndexPage() throws IOException {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
HtmlPage page = webClient.getPage(
|
||||
getServerUrl() + "/uml/1/" +
|
||||
"SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00"
|
||||
);
|
||||
// Analyze response
|
||||
List<HtmlForm> forms = page.getForms();
|
||||
assertEquals(2, forms.size());
|
||||
// Ensure the Text field is correct
|
||||
String text = ((HtmlTextArea)(forms.get(0).getFirstByXPath("//textarea[contains(@name, 'text')]"))).getTextContent();
|
||||
assertEquals(
|
||||
"@startuml\nBob -> Alice : hello\nnewpage\nBob <- Alice : hello\nBob -> Alice : let's talk\nBob <- Alice : better not\nBob -> Alice : <&rain> bye\nnewpage\nBob <- Alice : bye\n@enduml",
|
||||
text
|
||||
);
|
||||
// Ensure the URL field is correct
|
||||
HtmlInput url = forms.get(1).getInputByName("url");
|
||||
assertNotNull(url);
|
||||
assertTrue(url.getAttribute("value").endsWith("/png/1/SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00"));
|
||||
// Ensure the generated image is present
|
||||
HtmlImage img = page.getFirstByXPath("//img[contains(@alt, 'PlantUML diagram')]");
|
||||
int height = img.getImageReader().getHeight(0);
|
||||
assertNotEquals(0, height); // 222
|
||||
assertNotEquals(0, img.getImageReader().getWidth(0)); // 152
|
||||
// Ensure the correct index was generated
|
||||
assertTrue(height > 200); // 222
|
||||
assertTrue(height < 250); // 222
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that an multipage diagram renders correct even if no index is specified.
|
||||
*
|
||||
* Bob -> Alice : hello
|
||||
* newpage
|
||||
* Bob <- Alice : hello
|
||||
* Bob -> Alice : let's talk
|
||||
* Bob <- Alice : better not
|
||||
* Bob -> Alice : <&rain> bye
|
||||
* newpage
|
||||
* Bob <- Alice : bye
|
||||
*/
|
||||
public void testIndexPageWithNoDefinedIndex() throws IOException {
|
||||
try (final WebClient webClient = new WebClient()) {
|
||||
HtmlPage page = webClient.getPage(
|
||||
getServerUrl() + "/uml/" +
|
||||
"SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00"
|
||||
);
|
||||
// Analyze response
|
||||
List<HtmlForm> forms = page.getForms();
|
||||
assertEquals(2, forms.size());
|
||||
// Ensure the Text field is correct
|
||||
String text = ((HtmlTextArea)(forms.get(0).getFirstByXPath("//textarea[contains(@name, 'text')]"))).getTextContent();
|
||||
assertEquals(
|
||||
"@startuml\nBob -> Alice : hello\nnewpage\nBob <- Alice : hello\nBob -> Alice : let's talk\nBob <- Alice : better not\nBob -> Alice : <&rain> bye\nnewpage\nBob <- Alice : bye\n@enduml",
|
||||
text
|
||||
);
|
||||
// Ensure the URL field is correct
|
||||
HtmlInput url = forms.get(1).getInputByName("url");
|
||||
assertNotNull(url);
|
||||
assertTrue(url.getAttribute("value").endsWith("/png/SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00"));
|
||||
// Ensure the generated image is present
|
||||
HtmlImage img = page.getFirstByXPath("//img[contains(@alt, 'PlantUML diagram')]");
|
||||
int height = img.getImageReader().getHeight(0);
|
||||
assertNotEquals(0, height); // 132
|
||||
assertNotEquals(0, img.getImageReader().getWidth(0)); // 152
|
||||
// Ensure the correct index was generated
|
||||
assertTrue(height > 100); // 132
|
||||
assertTrue(height < 150); // 132
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,9 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.utils.TestUtils;
|
||||
import net.sourceforge.plantuml.servlet.utils.WebappTestCase;
|
||||
|
||||
|
||||
public class TestImage extends WebappTestCase {
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.sourceforge.plantuml.servlet;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.utils.WebappTestCase;
|
||||
|
||||
|
||||
public class TestLanguage extends WebappTestCase {
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.utils.TestUtils;
|
||||
import net.sourceforge.plantuml.servlet.utils.WebappTestCase;
|
||||
|
||||
|
||||
public class TestMap extends WebappTestCase {
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.utils.TestUtils;
|
||||
import net.sourceforge.plantuml.servlet.utils.WebappTestCase;
|
||||
|
||||
|
||||
public class TestSVG extends WebappTestCase {
|
||||
|
||||
|
||||
209
src/test/java/net/sourceforge/plantuml/servlet/TestWebUI.java
Normal file
209
src/test/java/net/sourceforge/plantuml/servlet/TestWebUI.java
Normal file
@@ -0,0 +1,209 @@
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.Dimension;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.utils.TestUtils;
|
||||
import net.sourceforge.plantuml.servlet.utils.WebappUITestCase;
|
||||
|
||||
|
||||
public class TestWebUI extends WebappUITestCase {
|
||||
|
||||
/**
|
||||
* Verifies that the welcome page has exactly two form with the Bob --> Alice sample
|
||||
*/
|
||||
public void testWelcomePage() {
|
||||
driver.get(getServerUrl());
|
||||
assertTrue("UI loading completed", waitUntilUIIsLoaded());
|
||||
// ensure the editor text is correct
|
||||
String text = getEditorValue();
|
||||
assertEquals(TestUtils.SEQBOBCODE, text);
|
||||
// ensure the URL field is correct
|
||||
String url = getURLValue();
|
||||
assertTrue(url.endsWith("/png/" + TestUtils.SEQBOB));
|
||||
// ensure the generated image is present
|
||||
Dimension dim = getImageSize();
|
||||
assertNotEquals(0, dim.getHeight()); // 145
|
||||
assertNotEquals(0, dim.getWidth()); // 134
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the version image is generated
|
||||
*/
|
||||
public void testVersion() {
|
||||
driver.get(getServerUrl());
|
||||
assertTrue("UI loading completed", waitUntilUIIsLoaded());
|
||||
// change code and observe result
|
||||
setEditorValue(TestUtils.VERSIONCODE);
|
||||
assertTrue("Auto update done", waitUntilAutoRefreshCompleted());
|
||||
// ensure the editor text is correct
|
||||
String text = getEditorValue();
|
||||
assertEquals(TestUtils.VERSIONCODE, text);
|
||||
// ensure the URL field is correct
|
||||
String url = getURLValue();
|
||||
assertTrue(url.endsWith("/png/" + TestUtils.VERSION));
|
||||
// ensure the generated image is present
|
||||
Dimension dim = getImageSize();
|
||||
assertNotEquals(0, dim.getHeight()); // 242
|
||||
assertNotEquals(0, dim.getWidth()); // 472
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Verifies that when the UML text is empty, ...
|
||||
// * old behavior: default page and image is generated
|
||||
// */
|
||||
// public void testEmptyText() {
|
||||
// // ...
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Verifies that when the encoded URL is empty, ...
|
||||
// * old behavior: default page and image is generated
|
||||
// */
|
||||
// public void testEmptyUrl() {
|
||||
// // ...
|
||||
// }
|
||||
|
||||
/**
|
||||
* Verifies that a ditaa diagram is generated
|
||||
*/
|
||||
public void testDitaaText() {
|
||||
driver.get(getServerUrl());
|
||||
assertTrue("UI loading completed", waitUntilUIIsLoaded());
|
||||
// change code and observe result
|
||||
setEditorValue("@startditaa \n*--> \n@endditaa");
|
||||
assertTrue("Auto update done", waitUntilAutoRefreshCompleted());
|
||||
// ensure the editor text is correct
|
||||
String text = getEditorValue();
|
||||
assertEquals("@startditaa \n*--> \n@endditaa", text);
|
||||
// ensure the URL field is correct
|
||||
String url = getURLValue();
|
||||
assertTrue(url.endsWith("/png/SoWkIImgISaiIKnKuDBIrRLJu798pKi12m00"));
|
||||
// ensure the generated image is present
|
||||
Dimension dim = getImageSize();
|
||||
assertNotEquals(0, dim.getHeight());
|
||||
assertNotEquals(0, dim.getWidth());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that an image map is produced if the diagram contains a link
|
||||
*/
|
||||
public void testImageMap() {
|
||||
driver.get(getServerUrl());
|
||||
assertTrue("UI loading completed", waitUntilUIIsLoaded());
|
||||
// change code and observe result
|
||||
setEditorValue("@startuml\nBob -> Alice : [[http://yahoo.com]] Hello\n@enduml");
|
||||
assertTrue("Auto update done", waitUntilAutoRefreshCompleted());
|
||||
// ensure the editor text is correct
|
||||
String text = getEditorValue();
|
||||
assertEquals("@startuml\nBob -> Alice : [[http://yahoo.com]] Hello\n@enduml", text);
|
||||
// ensure the URL field is correct
|
||||
String url = getURLValue();
|
||||
assertTrue(url.endsWith("/png/SyfFKj2rKt3CoKnELR1IY8xEA2afiDBNhqpCoC_NIyxFZOrLy4ZDoSa70000"));
|
||||
// ensure the generated image is present
|
||||
Dimension dim = getImageSize();
|
||||
assertNotEquals(0, dim.getHeight());
|
||||
assertNotEquals(0, dim.getWidth());
|
||||
// ensure the image map is present
|
||||
WebElement map = getImageMap();
|
||||
assertNotNull(map);
|
||||
assertEquals(1, Integer.parseInt(map.getAttribute("childElementCount")));
|
||||
// ensure the map button is visible
|
||||
WebElement btnMap = driver.findElement(By.id("map-diagram-link"));
|
||||
assertTrue(btnMap.isDisplayed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that when the encoded source is specified as an URL parameter
|
||||
* the diagram is displayed and the source is decoded
|
||||
*/
|
||||
public void testUrlParameter() {
|
||||
driver.get(getServerUrl() + "/form?url=" + TestUtils.SEQBOB);
|
||||
assertTrue("UI loading completed", waitUntilUIIsLoaded());
|
||||
// ensure the editor text is correct
|
||||
String text = getEditorValue();
|
||||
assertEquals(TestUtils.SEQBOBCODE, text);
|
||||
// ensure the URL field is correct
|
||||
String url = getURLValue();
|
||||
assertTrue(url.endsWith("/png/" + TestUtils.SEQBOB));
|
||||
// ensure the generated image is present
|
||||
Dimension dim = getImageSize();
|
||||
assertNotEquals(0, dim.getHeight());
|
||||
assertNotEquals(0, dim.getWidth());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that an multipage diagram renders correct given index.
|
||||
*
|
||||
* Bob -> Alice : hello
|
||||
* newpage
|
||||
* Bob <- Alice : hello
|
||||
* Bob -> Alice : let's talk
|
||||
* Bob <- Alice : better not
|
||||
* Bob -> Alice : <&rain> bye
|
||||
* newpage
|
||||
* Bob <- Alice : bye
|
||||
*/
|
||||
public void testIndexPage() {
|
||||
driver.get(
|
||||
getServerUrl() + "/uml/1/" +
|
||||
"SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00"
|
||||
);
|
||||
assertTrue("UI loading completed", waitUntilUIIsLoaded());
|
||||
// ensure the editor text is correct
|
||||
String text = getEditorValue();
|
||||
assertEquals(
|
||||
"@startuml\nBob -> Alice : hello\nnewpage\nBob <- Alice : hello\nBob -> Alice : let's talk\nBob <- Alice : better not\nBob -> Alice : <&rain> bye\nnewpage\nBob <- Alice : bye\n@enduml",
|
||||
text
|
||||
);
|
||||
// ensure the URL field is correct
|
||||
String url = getURLValue();
|
||||
assertTrue(url.endsWith("/png/1/SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00"));
|
||||
// ensure the generated image is present
|
||||
Dimension dim = getImageSize();
|
||||
assertNotEquals(0, dim.getHeight());
|
||||
assertNotEquals(0, dim.getWidth());
|
||||
// ensure the correct index was generated
|
||||
assertTrue(dim.getHeight() > 200); // 222
|
||||
assertTrue(dim.getHeight() < 250); // 222
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that an multipage diagram renders correct even if no index is specified.
|
||||
*
|
||||
* Bob -> Alice : hello
|
||||
* newpage
|
||||
* Bob <- Alice : hello
|
||||
* Bob -> Alice : let's talk
|
||||
* Bob <- Alice : better not
|
||||
* Bob -> Alice : <&rain> bye
|
||||
* newpage
|
||||
* Bob <- Alice : bye
|
||||
*/
|
||||
public void testIndexPageWithNoDefinedIndex() {
|
||||
driver.get(
|
||||
getServerUrl() + "/uml/" +
|
||||
"SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00"
|
||||
);
|
||||
assertTrue("UI loading completed", waitUntilUIIsLoaded());
|
||||
// ensure the editor text is correct
|
||||
String text = getEditorValue();
|
||||
assertEquals(
|
||||
"@startuml\nBob -> Alice : hello\nnewpage\nBob <- Alice : hello\nBob -> Alice : let's talk\nBob <- Alice : better not\nBob -> Alice : <&rain> bye\nnewpage\nBob <- Alice : bye\n@enduml",
|
||||
text
|
||||
);
|
||||
// ensure the URL field is correct
|
||||
String url = getURLValue();
|
||||
assertTrue(url.endsWith("/png/SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00"));
|
||||
// ensure the generated image is present
|
||||
Dimension dim = getImageSize();
|
||||
assertNotEquals(0, dim.getHeight());
|
||||
assertNotEquals(0, dim.getWidth());
|
||||
// ensure the correct index was generated
|
||||
assertTrue(dim.getHeight() > 100); // 132
|
||||
assertTrue(dim.getHeight() < 150); // 132
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package net.sourceforge.plantuml.servlet.utils;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.openqa.selenium.Dimension;
|
||||
import org.openqa.selenium.PageLoadStrategy;
|
||||
import org.openqa.selenium.Point;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
import org.openqa.selenium.edge.EdgeDriver;
|
||||
import org.openqa.selenium.edge.EdgeOptions;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||
|
||||
import io.github.bonigarcia.wdm.WebDriverManager;
|
||||
|
||||
|
||||
public abstract class JUnitWebDriver {
|
||||
|
||||
public static final String browser;
|
||||
|
||||
static {
|
||||
browser = System.getProperty("system.test.browser", "firefox");
|
||||
}
|
||||
|
||||
public static WebDriver getDriver() {
|
||||
WebDriver driver;
|
||||
switch (browser.toLowerCase()) {
|
||||
case "chrome":
|
||||
driver = getChromeDriver();
|
||||
break;
|
||||
case "edge":
|
||||
driver = SystemUtils.IS_OS_WINDOWS ? getEdgeDriver() : getChromiumDriver();
|
||||
break;
|
||||
case "firefox":
|
||||
driver = getFirefoxDriver();
|
||||
break;
|
||||
default:
|
||||
driver = getChromiumDriver();
|
||||
}
|
||||
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
|
||||
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
|
||||
driver.manage().window().setPosition(new Point(0, 0));
|
||||
driver.manage().window().setSize(new Dimension(1024, 768));
|
||||
return driver;
|
||||
}
|
||||
|
||||
private static WebDriver getChromiumDriver() {
|
||||
WebDriverManager.chromiumdriver().setup();
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
options.addArguments("--headless", "--no-sandbox", "--disable-gpu");
|
||||
options.setPageLoadStrategy(PageLoadStrategy.NONE);
|
||||
return new ChromeDriver(options);
|
||||
}
|
||||
|
||||
private static WebDriver getChromeDriver() {
|
||||
WebDriverManager.chromedriver().setup();
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
options.addArguments("--headless", "--no-sandbox", "--disable-gpu");
|
||||
options.setPageLoadStrategy(PageLoadStrategy.NONE);
|
||||
return new ChromeDriver(options);
|
||||
}
|
||||
|
||||
private static WebDriver getFirefoxDriver() {
|
||||
WebDriverManager.firefoxdriver().setup();
|
||||
FirefoxOptions options = new FirefoxOptions();
|
||||
options.addArguments("--headless");
|
||||
return new FirefoxDriver(options);
|
||||
}
|
||||
|
||||
private static WebDriver getEdgeDriver() {
|
||||
WebDriverManager.edgedriver().setup();
|
||||
EdgeOptions options = new EdgeOptions();
|
||||
options.addArguments("headless");
|
||||
return new EdgeDriver(options);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
package net.sourceforge.plantuml.servlet.utils;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
package net.sourceforge.plantuml.servlet.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -9,6 +9,7 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import net.sourceforge.plantuml.servlet.server.EmbeddedJettyServer;
|
||||
import net.sourceforge.plantuml.servlet.server.ExternalServer;
|
||||
import net.sourceforge.plantuml.servlet.server.ServerUtils;
|
||||
@@ -23,27 +24,19 @@ public abstract class WebappTestCase extends TestCase {
|
||||
}
|
||||
|
||||
public WebappTestCase(String name) {
|
||||
super(name);
|
||||
// logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
String uri = System.getProperty("system.test.server", "");
|
||||
//uri = "http://localhost:8080/plantuml";
|
||||
if (!uri.isEmpty()) {
|
||||
// mvn test -DskipTests=false -DargLine="-Dsystem.test.server=http://localhost:8080/plantuml"
|
||||
// logger.info("Test against external server: " + uri);
|
||||
serverUtils = new ExternalServer(uri);
|
||||
return;
|
||||
}
|
||||
|
||||
// mvn test -DskipTests=false
|
||||
// logger.info("Test against embedded jetty server.");
|
||||
serverUtils = new EmbeddedJettyServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
serverUtils.startServer();
|
||||
// logger.info(getServerUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,7 +44,7 @@ public abstract class WebappTestCase extends TestCase {
|
||||
serverUtils.stopServer();
|
||||
}
|
||||
|
||||
protected String getServerUrl() {
|
||||
public String getServerUrl() {
|
||||
return serverUtils.getServerUrl();
|
||||
}
|
||||
|
||||
@@ -104,5 +97,4 @@ public abstract class WebappTestCase extends TestCase {
|
||||
return byteStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package net.sourceforge.plantuml.servlet.utils;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.Dimension;
|
||||
import org.openqa.selenium.JavascriptExecutor;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.ui.ExpectedCondition;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
|
||||
public abstract class WebappUITestCase extends WebappTestCase {
|
||||
|
||||
public WebDriver driver;
|
||||
public JavascriptExecutor js;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
driver = JUnitWebDriver.getDriver();
|
||||
js = (JavascriptExecutor)driver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
driver.close();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public boolean waitUntilJavascriptIsLoaded() {
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
|
||||
return wait.until(new ExpectedCondition<Boolean>() {
|
||||
@Override
|
||||
public Boolean apply(WebDriver driver) {
|
||||
return js.executeScript("return document.readyState").toString().equals("complete");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean waitUntilEditorIsLoaded() {
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
|
||||
return wait.until(new ExpectedCondition<Boolean>() {
|
||||
@Override
|
||||
public Boolean apply(WebDriver driver) {
|
||||
return js.executeScript("return document.editor === undefined").toString().equals("false");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean waitUntilAutoRefreshCompleted() {
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
||||
return wait.until(new ExpectedCondition<Boolean>() {
|
||||
@Override
|
||||
public Boolean apply(WebDriver driver) {
|
||||
return js.executeScript("return document.appConfig.autoRefreshState").toString().equals("complete");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean waitUntilUIIsLoaded() {
|
||||
return waitUntilEditorIsLoaded();
|
||||
}
|
||||
|
||||
public String getEditorValue() {
|
||||
return (String)js.executeScript("return document.editor.getValue();");
|
||||
}
|
||||
|
||||
public void setEditorValue(String code) {
|
||||
js.executeScript("return document.editor.getModel().setValue(`" + code.replace("`", "\\`") + "`);");
|
||||
}
|
||||
|
||||
public String getURLValue() {
|
||||
return driver.findElement(By.id("url")).getAttribute("value");
|
||||
}
|
||||
|
||||
public Dimension getImageSize() {
|
||||
WebElement img = driver.findElement(By.id("diagram-png"));
|
||||
return new Dimension(
|
||||
Integer.parseInt(img.getAttribute("width")),
|
||||
Integer.parseInt(img.getAttribute("height"))
|
||||
);
|
||||
// return driver.findElement(By.id("diagram-png")).getSize();
|
||||
}
|
||||
|
||||
public WebElement getImageMap() {
|
||||
return driver.findElement(By.id("plantuml_map"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user