From e5d11fb89a7e1a3b8c12d2f5def476280da31cc6 Mon Sep 17 00:00:00 2001 From: Florian Date: Fri, 5 May 2023 17:50:02 +0200 Subject: [PATCH] update all dependencies (maven artifacts) - PDF dependency was missing in the pom file the JDK8 * We should think about creating a parent pom - in that case all plantuml dependencies could be in the parent pom and we would only the mantain one pom file. (It is also possible to drop the Java 8 support.) * Why do we not have any PDF tests? - add rule to ignore version update hint with `-dev` followed by a dot and date (e.g. `0.37.0-dev.20230308`) - migration from JUnit4 to JUnit5 --- Dockerfile.jetty | 4 +- pom.jdk8.xml | 73 ++++++----- pom.xml | 84 +++++++------ src/main/config/rules.xml | 1 + .../plantuml/servlet/AllTests.java | 44 +++---- .../plantuml/servlet/TestAsciiArt.java | 14 ++- .../plantuml/servlet/TestAsciiCoder.java | 27 ++-- .../plantuml/servlet/TestCharset.java | 21 ++-- .../plantuml/servlet/TestCheck.java | 23 ++-- .../sourceforge/plantuml/servlet/TestEPS.java | 14 ++- .../plantuml/servlet/TestImage.java | 34 ++--- .../plantuml/servlet/TestLanguage.java | 6 +- .../sourceforge/plantuml/servlet/TestMap.java | 42 ++++--- .../plantuml/servlet/TestMultipageUml.java | 119 ++++++++++-------- .../plantuml/servlet/TestOldProxy.java | 45 ++++--- .../plantuml/servlet/TestProxy.java | 68 +++++----- .../sourceforge/plantuml/servlet/TestSVG.java | 43 ++++--- .../plantuml/servlet/TestWebUI.java | 103 ++++++++------- .../servlet/utils/WebappTestCase.java | 23 ++-- .../servlet/utils/WebappUITestCase.java | 6 +- 20 files changed, 435 insertions(+), 359 deletions(-) diff --git a/Dockerfile.jetty b/Dockerfile.jetty index 59863aa..2d1c76b 100644 --- a/Dockerfile.jetty +++ b/Dockerfile.jetty @@ -8,7 +8,7 @@ RUN mvn --batch-mode --define java.net.useSystemProxies=true package ######################################################################################## -FROM jetty:11.0.7-jre11-slim +FROM jetty:11.0.15-jre11-slim # Proxy and OldProxy need empty path segments support in URIs # Hence: allow AMBIGUOUS_EMPTY_SEGMENT @@ -65,7 +65,7 @@ COPY ROOT.jetty.xml $WEBAPP_PATH/ROOT.xml ENTRYPOINT ["/entrypoint.sh"] # Openshift https://docs.openshift.com/container-platform/4.9/openshift_images/create-images.html#images-create-guide-openshift_create-images -USER root +USER root RUN chgrp -R 0 $JETTY_BASE && chmod -R g=u $JETTY_BASE RUN chgrp -R 0 /tmp && chmod -R g=u /tmp USER jetty diff --git a/pom.jdk8.xml b/pom.jdk8.xml index 37c595d..7a36a5c 100644 --- a/pom.jdk8.xml +++ b/pom.jdk8.xml @@ -55,7 +55,7 @@ 1.2023.6 - 11.0.7 + 11.0.15 0.36.1 @@ -63,41 +63,44 @@ ${jetty.version} ${jetty.version} ${jetty.version} - 1.14 1.0.7 ${jlatexmath.version} ${jlatexmath.version} + + 1.16 + 2.8 - 4.13.2 - 4.8.3 + 5.9.3 + 1.9.3 + 4.9.0 5.3.2 2.11.0 ${jetty.version} - 3.1.0 - 3.2.0 - 3.2.0 - 3.8.1 - 2.8.1 - 2.22.2 + 3.2.0 + 3.5.0 + 3.3.1 + 3.11.0 + 2.15.0 + 3.0.0 3.3.2 - 2.5.2 - 2.8.2 - 3.9.1 - 3.1.2 - 3.1.2 - 9.0.1 + 3.1.1 + 3.1.1 + 3.12.1 + 3.4.3 + 3.2.2 + 10.10.0 2.10 ${jetty.version} ${jetty.version} - 1.5.0 - 3.3.1 + 1.5.1 + 3.5.0 @@ -145,13 +148,6 @@ - - - org.apache.xmlgraphics - batik-all - ${batik-all.version} - pom - org.scilab.forge @@ -168,14 +164,35 @@ jlatexmath-font-cyrillic ${jlatexmath-font-cyrillic.version} + + + + org.apache.xmlgraphics + batik-all + ${batik-all.version} + pom + + + + org.apache.xmlgraphics + fop + ${fop.version} + pom + - junit - junit + org.junit.jupiter + junit-jupiter-api ${junit.version} test + + org.junit.platform + junit-platform-suite-api + ${junit-suite.version} + test + org.seleniumhq.selenium selenium-java @@ -220,7 +237,7 @@ maven-dependency-plugin ${maven-dependency-plugin.version} - + maven-resources-plugin ${maven-resources-plugin.version} diff --git a/pom.xml b/pom.xml index af2be3e..c4a5d77 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ 1.2023.6 - 11.0.7 + 11.0.15 0.36.1 @@ -63,41 +63,44 @@ ${jetty.version} ${jetty.version} ${jetty.version} - 1.14 1.0.7 ${jlatexmath.version} ${jlatexmath.version} + + 1.16 + 2.8 - 4.13.2 - 4.8.3 + 5.9.3 + 1.9.3 + 4.9.0 5.3.2 2.11.0 ${jetty.version} - 3.1.0 - 3.2.0 - 3.2.0 - 3.8.1 - 2.8.1 - 2.22.2 + 3.2.0 + 3.5.0 + 3.3.1 + 3.11.0 + 2.15.0 + 3.0.0 3.3.2 - 2.5.2 - 2.8.2 - 3.9.1 - 3.1.2 - 3.1.2 - 9.0.1 + 3.1.1 + 3.1.1 + 3.12.1 + 3.4.3 + 3.2.2 + 10.10.0 2.10 ${jetty.version} ${jetty.version} - 1.5.0 - 3.3.1 + 1.5.1 + 3.5.0 @@ -123,13 +126,6 @@ ${jetty-annotations.version} provided - - - org.apache.xmlgraphics - batik-all - ${batik-all.version} - pom - org.scilab.forge @@ -146,14 +142,35 @@ jlatexmath-font-cyrillic ${jlatexmath-font-cyrillic.version} - + + + + org.apache.xmlgraphics + batik-all + ${batik-all.version} + pom + + + + org.apache.xmlgraphics + fop + ${fop.version} + pom + + - junit - junit + org.junit.jupiter + junit-jupiter-api ${junit.version} test + + org.junit.platform + junit-platform-suite-api + ${junit-suite.version} + test + org.seleniumhq.selenium selenium-java @@ -178,15 +195,6 @@ ${jetty-server.version} test - - - - - org.apache.xmlgraphics - fop - 2.7 - pom - @@ -201,7 +209,7 @@ maven-dependency-plugin ${maven-dependency-plugin.version} - + maven-resources-plugin ${maven-resources-plugin.version} diff --git a/src/main/config/rules.xml b/src/main/config/rules.xml index b69193d..6a7fe6f 100644 --- a/src/main/config/rules.xml +++ b/src/main/config/rules.xml @@ -14,6 +14,7 @@ (?i).*RC(?:-?\d+)? (?i).*CR(?:-?\d+)? (?i).*M(?:-?\d+)? + (?i).*-dev((?:-?\d+)|(?:\.20\d{6}))? diff --git a/src/test/java/net/sourceforge/plantuml/servlet/AllTests.java b/src/test/java/net/sourceforge/plantuml/servlet/AllTests.java index c0c2d8f..8a4fd21 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/AllTests.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/AllTests.java @@ -1,28 +1,22 @@ package net.sourceforge.plantuml.servlet; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; -public class AllTests extends TestSuite { - - public static Test suite() { - TestSuite suite = new TestSuite(AllTests.class.getName()); - // $JUnit-BEGIN$ - suite.addTestSuite(TestAsciiArt.class); - suite.addTestSuite(TestAsciiCoder.class); - suite.addTestSuite(TestCharset.class); - suite.addTestSuite(TestCheck.class); - suite.addTestSuite(TestEPS.class); - suite.addTestSuite(TestImage.class); - suite.addTestSuite(TestLanguage.class); - suite.addTestSuite(TestMap.class); - suite.addTestSuite(TestMultipageUml.class); - suite.addTestSuite(TestOldProxy.class); - suite.addTestSuite(TestProxy.class); - suite.addTestSuite(TestSVG.class); - suite.addTestSuite(TestWebUI.class); - // $JUnit-END$ - return suite; - } - -} +@Suite +@SelectClasses({ + TestAsciiArt.class, + TestAsciiCoder.class, + TestCharset.class, + TestCheck.class, + TestEPS.class, + TestImage.class, + TestLanguage.class, + TestMap.class, + TestMultipageUml.class, + TestOldProxy.class, + TestProxy.class, + TestSVG.class, + TestWebUI.class +}) +public class AllTests {} diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java index 6ebf2b2..7cd1939 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.net.URL; import java.net.URLConnection; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.TestUtils; import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -13,21 +16,22 @@ public class TestAsciiArt extends WebappTestCase { /** * Verifies the generation of the ascii art for the Bob -> Alice sample */ + @Test public void testSimpleSequenceDiagram() throws IOException { final URL url = new URL(getServerUrl() + "/txt/" + TestUtils.SEQBOB); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertTrue(diagramLen > 200); - assertTrue(diagramLen < 250); + Assertions.assertTrue(diagramLen > 200); + Assertions.assertTrue(diagramLen < 250); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiCoder.java b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiCoder.java index 802ba30..e65af49 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiCoder.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiCoder.java @@ -6,6 +6,9 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.TestUtils; import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -15,24 +18,26 @@ public class TestAsciiCoder extends WebappTestCase { /** * Verifies the decoding for the Bob -> Alice sample */ + @Test public void testBobAliceSampleDiagramDecoding() throws IOException { final URL url = new URL(getServerUrl() + "/coder/" + TestUtils.SEQBOB); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get and verify the content final String diagram = getContentText(conn); - assertEquals(TestUtils.SEQBOBCODE, diagram); + Assertions.assertEquals(TestUtils.SEQBOBCODE, diagram); } /** * Verifies the encoding for the Bob -> Alice sample */ + @Test public void testBobAliceSampleDiagramEncoding() throws IOException { final URL url = new URL(getServerUrl() + "/coder"); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); @@ -45,20 +50,16 @@ public class TestAsciiCoder extends WebappTestCase { } // Analyze response // HTTP response 200 - assertEquals( - "Bad HTTP status received", - 200, - conn.getResponseCode() - ); + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); // Verifies the Content-Type header - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the content and verify its size final String diagram = getContentText(conn.getInputStream()); - assertEquals(TestUtils.SEQBOB, diagram); + Assertions.assertEquals(TestUtils.SEQBOB, diagram); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestCharset.java b/src/test/java/net/sourceforge/plantuml/servlet/TestCharset.java index 7c0bdd6..7683e85 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestCharset.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestCharset.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.net.URL; import java.net.URLConnection; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -12,25 +15,27 @@ public class TestCharset extends WebappTestCase { /** * Verifies the preservation of unicode characters for the "Bob -> Alice : hell‽" sample */ + @Test public void testUnicodeSupport() throws IOException { final URL url = new URL(getServerUrl() + "/txt/SyfFKj2rKt3CoKnELR1Io4ZDoNdKi1S0"); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the content and verify that the interrobang unicode character is present String diagram = getContentText(conn); - assertTrue("Interrobang unicode character is not preserved", diagram.contains("‽")); + Assertions.assertTrue(diagram.contains("‽"), "Interrobang unicode character is not preserved"); } /** * Verifies the preservation of unicode characters for the * "participant Bob [[http://www.snow.com/❄]]\nBob -> Alice" sample */ + @Test public void testUnicodeInCMap() throws IOException { final URL url = new URL( getServerUrl() + @@ -39,14 +44,14 @@ public class TestCharset extends WebappTestCase { final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the content and verify that the snow unicode character is present String map = getContentText(conn); - assertTrue("Snow unicode character is not preserved", map.contains("❄")); + Assertions.assertTrue(map.contains("❄"), "Snow unicode character is not preserved"); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestCheck.java b/src/test/java/net/sourceforge/plantuml/servlet/TestCheck.java index 71a6042..5233d16 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestCheck.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestCheck.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.net.URL; import java.net.URLConnection; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.TestUtils; import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -14,36 +17,38 @@ public class TestCheck extends WebappTestCase { * Verifies the generation of a syntax check for the following sample: * Bob -> Alice : hello */ + @Test public void testCorrectSequenceDiagram() throws IOException { final URL url = new URL(getServerUrl() + "/check/" + TestUtils.SEQBOB); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the content, check its first characters and verify its size String checkResult = getContentText(conn); - assertTrue( - "Response content is not starting with (2 participants)", - checkResult.startsWith("(2 participants)") + Assertions.assertTrue( + checkResult.startsWith("(2 participants)"), + "Response content is not starting with (2 participants)" ); int checkLen = checkResult.length(); - assertTrue(checkLen > 1); - assertTrue(checkLen < 100); + Assertions.assertTrue(checkLen > 1); + Assertions.assertTrue(checkLen < 100); } /** * Check the syntax of an invalid sequence diagram : * Bob - */ + @Test public void testWrongDiagramSyntax() throws IOException { final URL url = new URL(getServerUrl() + "/check/SyfFKj050000"); // Analyze response String checkResult = getContentText(url); - assertTrue("Response is not an error", checkResult.startsWith("(Error)")); + Assertions.assertTrue(checkResult.startsWith("(Error)"), "Response is not an error"); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestEPS.java b/src/test/java/net/sourceforge/plantuml/servlet/TestEPS.java index 08c3ba6..1fb0ca6 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestEPS.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestEPS.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.net.URL; import java.net.URLConnection; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.TestUtils; import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -13,21 +16,22 @@ public class TestEPS extends WebappTestCase { /** * Verifies the generation of the EPS for the Bob -> Alice sample */ + @Test public void testSimpleSequenceDiagram() throws IOException { final URL url = new URL(getServerUrl() + "/eps/" + TestUtils.SEQBOB); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not EPS", + Assertions.assertEquals( "application/postscript", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not EPS" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertTrue(diagramLen > 7000); - assertTrue(diagramLen < 10000); + Assertions.assertTrue(diagramLen > 7000); + Assertions.assertTrue(diagramLen < 10000); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java b/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java index b4222b3..9ecc40b 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java @@ -8,6 +8,9 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.TestUtils; import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -17,44 +20,46 @@ public class TestImage extends WebappTestCase { /** * Verifies the generation of the version image from an encoded URL */ + @Test public void testVersionImage() throws IOException { final URL url = new URL(getServerUrl() + "/png/" + TestUtils.VERSION); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not PNG", + Assertions.assertEquals( "image/png", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not PNG" ); // Get the image and verify its size byte[] inMemoryImage = getContentAsBytes(conn); int diagramLen = inMemoryImage.length; - assertTrue(diagramLen > 10000); - assertTrue(diagramLen < 20000); + Assertions.assertTrue(diagramLen > 10000); + Assertions.assertTrue(diagramLen < 20000); } /** * Verifies that the HTTP header of a diagram incites the browser to cache it. */ + @Test public void testDiagramHttpHeader() throws IOException, ParseException { final URL url = new URL(getServerUrl() + "/png/" + TestUtils.SEQBOB); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not PNG", + Assertions.assertEquals( "image/png", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not PNG" ); // Verifies the availability of the Expires entry in the response header - assertNotNull(conn.getHeaderField("Expires")); + Assertions.assertNotNull(conn.getHeaderField("Expires")); // Verifies the availability of the Last-Modified entry in the response header - assertNotNull(conn.getHeaderField("Last-Modified")); + Assertions.assertNotNull(conn.getHeaderField("Last-Modified")); // Verifies the Last-Modified value is in the past SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ZZZ", Locale.ENGLISH); Date lastModified = format.parse(conn.getHeaderField("Last-Modified")); - assertTrue("Last-Modified is not in the past", lastModified.before(new Date())); + Assertions.assertTrue(lastModified.before(new Date()), "Last-Modified is not in the past"); // Consume the response but do nothing with it getContentAsBytes(conn); } @@ -62,15 +67,16 @@ public class TestImage extends WebappTestCase { /** * Verifies that the HTTP header of a diagram incites the browser to cache it. */ + @Test public void testOldImgURL() throws IOException { final URL url = new URL(getServerUrl() + "/img/" + TestUtils.SEQBOB); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not PNG", + Assertions.assertEquals( "image/png", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not PNG" ); // Consume the response but do nothing with it getContentAsBytes(conn); diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestLanguage.java b/src/test/java/net/sourceforge/plantuml/servlet/TestLanguage.java index cca15eb..e34d66a 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestLanguage.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestLanguage.java @@ -3,6 +3,9 @@ package net.sourceforge.plantuml.servlet; import java.io.IOException; import java.net.URL; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -11,10 +14,11 @@ public class TestLanguage extends WebappTestCase { /** * Tests that the language for the current PlantUML server can be obtained through HTTP */ + @Test public void testRetrieveLanguage() throws IOException { final URL url = new URL(getServerUrl() + "/language"); String languageText = getContentText(url); - assertTrue("Language contains @startuml", languageText.indexOf("@startuml") > 0); + Assertions.assertTrue(languageText.indexOf("@startuml") > 0, "Language contains @startuml"); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestMap.java b/src/test/java/net/sourceforge/plantuml/servlet/TestMap.java index 0bbf0e5..dcdec87 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestMap.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestMap.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.net.URL; import java.net.URLConnection; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.TestUtils; import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -16,6 +19,7 @@ public class TestMap extends WebappTestCase { * participant Bob [[http://www.yahoo.com]] * Bob -> Alice : [[http://www.google.com]] hello */ + @Test public void testSimpleSequenceDiagram() throws IOException { final URL url = new URL( getServerUrl() + @@ -24,30 +28,31 @@ public class TestMap extends WebappTestCase { final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the content, check its first characters and verify its size String diagram = getContentText(conn); - assertTrue( - "Response content is not starting with 200); - assertTrue(diagramLen < 300); + Assertions.assertTrue(diagramLen > 200); + Assertions.assertTrue(diagramLen < 300); } /** * Check the content of the MAP for the sequence diagram sample * Verify structure of the area tags */ + @Test public void testSequenceDiagramContent() throws IOException { final URL url = new URL( getServerUrl() + @@ -61,9 +66,9 @@ public class TestMap extends WebappTestCase { // // // - assertTrue( - "Response doesn't match shape", - map.matches("^\n(\n){2}\n*$") + Assertions.assertTrue( + map.matches("^\n(\n){2}\n*$"), + "Response doesn't match shape" ); } @@ -71,20 +76,21 @@ public class TestMap extends WebappTestCase { * Check the empty MAP of a sequence diagram without link * This test uses the simple Bob -> Alice */ + @Test public void testSequenceDiagramWithoutLink() throws IOException { final URL url = new URL(getServerUrl() + "/map/" + TestUtils.SEQBOB); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the data contained in the XML String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertEquals(0, diagramLen); + Assertions.assertEquals(0, diagramLen); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestMultipageUml.java b/src/test/java/net/sourceforge/plantuml/servlet/TestMultipageUml.java index 5494462..3f3e35b 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestMultipageUml.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestMultipageUml.java @@ -1,11 +1,12 @@ package net.sourceforge.plantuml.servlet; -import static org.junit.Assert.assertNotEquals; - import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.TestUtils; import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -15,182 +16,190 @@ public class TestMultipageUml extends WebappTestCase { /** * Verifies that an multipage diagram renders correct given index (PNG). */ + @Test public void testPngIndexPage() throws IOException { final URL url = new URL(getServerUrl() + "/png/1/" + TestUtils.SEQMULTIPAGE); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not PNG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/png", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not PNG" ); // Get the image and verify its size byte[] inMemoryImage = getContentAsBytes(conn); int diagramLen = inMemoryImage.length; // 7525 - assertTrue(diagramLen > 6000); - assertTrue(diagramLen < 9000); + Assertions.assertTrue(diagramLen > 6000); + Assertions.assertTrue(diagramLen < 9000); } /** * Verifies that an multipage diagram renders correct even if no index is specified (PNG). */ + @Test public void testPngIndexPageNoIndex() throws IOException { final URL url = new URL(getServerUrl() + "/png/" + TestUtils.SEQMULTIPAGE); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not PNG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/png", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not PNG" ); // Get the image and verify its size byte[] inMemoryImage = getContentAsBytes(conn); int diagramLen = inMemoryImage.length; // 4196 - assertTrue(diagramLen > 3000); - assertTrue(diagramLen < 5000); + Assertions.assertTrue(diagramLen > 3000); + Assertions.assertTrue(diagramLen < 5000); } /** * Verifies that an multipage diagram renders correct given index (SVG). */ + @Test public void testSvgIndexPage() throws IOException { final URL url = new URL(getServerUrl() + "/svg/1/" + TestUtils.SEQMULTIPAGE); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not SVG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/svg+xml", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not SVG" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertTrue(diagramLen > 4500); - assertTrue(diagramLen < 6000); + Assertions.assertTrue(diagramLen > 4500); + Assertions.assertTrue(diagramLen < 6000); } /** * Verifies that an multipage diagram renders correct even if no index is specified (SVG). */ + @Test public void testSvgIndexPageNoIndex() throws IOException { final URL url = new URL(getServerUrl() + "/svg/" + TestUtils.SEQMULTIPAGE); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not SVG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/svg+xml", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not SVG" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertTrue(diagramLen > 1500); - assertTrue(diagramLen < 4000); + Assertions.assertTrue(diagramLen > 1500); + Assertions.assertTrue(diagramLen < 4000); } /** * Verifies that an multipage diagram renders correct given index (AsciiArt). */ + @Test public void testAsciiArtIndexPage() throws IOException { final URL url = new URL(getServerUrl() + "/txt/1/" + TestUtils.SEQMULTIPAGE); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertNotEquals(0, diagramLen); + Assertions.assertNotEquals(0, diagramLen); // BUG/Missing Feature: plantuml renders always whole AsciiArt diagram - //assertTrue(diagramLen > ??); - //assertTrue(diagramLen < ??); + //Assertions.assertTrue(diagramLen > ??); + //Assertions.assertTrue(diagramLen < ??); } /** * Verifies that an multipage diagram renders correct even if no index is specified (AsciiArt). */ + @Test public void testAsciiArtIndexPageNoIndex() throws IOException { final URL url = new URL(getServerUrl() + "/txt/" + TestUtils.SEQMULTIPAGE); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertNotEquals(0, diagramLen); + Assertions.assertNotEquals(0, diagramLen); // BUG/Missing Feature: plantuml renders always whole AsciiArt diagram - //assertTrue(diagramLen > ??); - //assertTrue(diagramLen < ??); + //Assertions.assertTrue(diagramLen > ??); + //Assertions.assertTrue(diagramLen < ??); } /** * Verifies that an multipage diagram renders correct given index (Map). */ + @Test public void testMapIndexPage() throws IOException { final URL url = new URL(getServerUrl() + "/map/1/" + TestUtils.SEQMULTIPAGE); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the data contained in the XML String map = getContentText(url); // map contains "tel:0123456789" - assertTrue( - "Response does not contain 'tel:0123456789'", - map.contains("tel:0123456789") + Assertions.assertTrue( + map.contains("tel:0123456789"), + "Response does not contain 'tel:0123456789'" ); // Verify shape: // // // - assertTrue( - "Response doesn't match shape", - map.matches("^\n(\n)\n*$") + Assertions.assertTrue( + map.matches("^\n(\n)\n*$"), + "Response doesn't match shape" ); } /** * Verifies that an multipage diagram renders correct even if no index is specified (Map). */ + @Test public void testMapIndexPageNoIndex() throws IOException { final URL url = new URL(getServerUrl() + "/map/" + TestUtils.SEQMULTIPAGE); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not TEXT PLAIN or UTF-8", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "text/plain;charset=utf-8", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not TEXT PLAIN or UTF-8" ); // Get the data contained in the XML String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertEquals(0, diagramLen); + Assertions.assertEquals(0, diagramLen); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestOldProxy.java b/src/test/java/net/sourceforge/plantuml/servlet/TestOldProxy.java index 0fb300d..54c6599 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestOldProxy.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestOldProxy.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -12,59 +15,61 @@ public class TestOldProxy extends WebappTestCase { /** * Verifies the proxified reception of the default Bob and Alice diagram */ + @Test public void testDefaultProxy() throws IOException { final URL url = new URL(getServerUrl() + "/proxy/" + getTestDiagramUrl()); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not PNG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/png", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not PNG" ); // Get the image and verify its size (~2000 bytes) byte[] inMemoryImage = getContentAsBytes(conn); int diagramLen = inMemoryImage.length; - assertTrue(diagramLen > 2000); - assertTrue(diagramLen < 3000); + Assertions.assertTrue(diagramLen > 2000); + Assertions.assertTrue(diagramLen < 3000); } + /** + * Verifies the proxified reception of the default Bob and Alice diagram in a specific format (SVG) + */ + @Test public void testProxyWithFormat() throws IOException { final URL url = new URL(getServerUrl() + "/proxy/svg/" + getTestDiagramUrl()); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not SVG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/svg+xml", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not SVG" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertTrue(diagramLen > 1000); - assertTrue(diagramLen < 3000); + Assertions.assertTrue(diagramLen > 1000); + Assertions.assertTrue(diagramLen < 3000); } /** * Verifies that the HTTP header of a diagram incites the browser to cache it. */ + @Test public void testInvalidUrl() throws IOException { final URL url = new URL(getServerUrl() + "/proxy/invalidURL"); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Check if status code is 400 - assertEquals( - "Bad HTTP status received", - 400, - conn.getResponseCode() - ); + Assertions.assertEquals(400, conn.getResponseCode(), "Bad HTTP status received"); // Check error message - assertTrue( - "Response is not malformed URL", - getContentText(conn.getErrorStream()).contains("URL malformed.") + Assertions.assertTrue( + getContentText(conn.getErrorStream()).contains("URL malformed."), + "Response is not malformed URL" ); } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestProxy.java b/src/test/java/net/sourceforge/plantuml/servlet/TestProxy.java index b95ff89..a56ecb5 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestProxy.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestProxy.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -12,103 +15,104 @@ public class TestProxy extends WebappTestCase { /** * Verifies the proxified reception of the default Bob and Alice diagram */ + @Test public void testDefaultProxy() throws IOException { final URL url = new URL(getServerUrl() + "/proxy?src=" + getTestDiagramUrl()); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not PNG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/png", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not PNG" ); // Get the image and verify its size (~2000 bytes) byte[] inMemoryImage = getContentAsBytes(conn); int diagramLen = inMemoryImage.length; - assertTrue(diagramLen > 2000); - assertTrue(diagramLen < 3000); + Assertions.assertTrue(diagramLen > 2000); + Assertions.assertTrue(diagramLen < 3000); } /** * Verifies the proxified reception of the default Bob and Alice diagram with defined format. */ + @Test public void testProxyWithFormat() throws IOException { final URL url = new URL(getServerUrl() + "/proxy?fmt=svg&src=" + getTestDiagramUrl()); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not SVG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/svg+xml", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not SVG" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertTrue(diagramLen > 1500); - assertTrue(diagramLen < 3000); + Assertions.assertTrue(diagramLen > 1500); + Assertions.assertTrue(diagramLen < 3000); } /** * Verifies the proxified reception of the default Bob and Alice diagram with defined format and format (idx=0). */ + @Test public void testProxyWithFormatIdx0() throws IOException { final URL url = new URL(getServerUrl() + "/proxy?fmt=svg&idx=0&src=" + getTestDiagramUrl()); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not SVG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/svg+xml", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not SVG" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertTrue(diagramLen > 1500); - assertTrue(diagramLen < 3000); + Assertions.assertTrue(diagramLen > 1500); + Assertions.assertTrue(diagramLen < 3000); } /** * Verifies the proxified reception of the default Bob and Alice diagram with defined format and format (idx=1). */ + @Test public void testProxyWithFormatIdx1() throws IOException { final URL url = new URL(getServerUrl() + "/proxy?fmt=svg&idx=1&src=" + getTestDiagramUrl()); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response // Verifies HTTP status code and the Content-Type - assertEquals("Bad HTTP status received", 200, conn.getResponseCode()); - assertEquals( - "Response content type is not SVG", + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); + Assertions.assertEquals( "image/svg+xml", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not SVG" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertTrue(diagramLen > 5000); - assertTrue(diagramLen < 6000); + Assertions.assertTrue(diagramLen > 5000); + Assertions.assertTrue(diagramLen < 6000); } /** * Verifies that the HTTP header of a diagram incites the browser to cache it. */ + @Test public void testInvalidUrl() throws IOException { final URL url = new URL(getServerUrl() + "/proxy?src=invalidURL"); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Analyze response, it must be HTTP error 400 - assertEquals( - "Bad HTTP status received", - 400, - conn.getResponseCode() - ); + Assertions.assertEquals(400, conn.getResponseCode(), "Bad HTTP status received"); // Check error message - assertTrue( - "Response is not malformed URL", - getContentText(conn.getErrorStream()).contains("URL malformed.") + Assertions.assertTrue( + getContentText(conn.getErrorStream()).contains("URL malformed."), + "Response is not malformed URL" ); } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java b/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java index 30406a8..9f78908 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestSVG.java @@ -8,6 +8,9 @@ import java.net.URL; import java.net.URLConnection; import java.util.Scanner; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import net.sourceforge.plantuml.servlet.utils.TestUtils; import net.sourceforge.plantuml.servlet.utils.WebappTestCase; @@ -17,26 +20,28 @@ public class TestSVG extends WebappTestCase { /** * Verifies the generation of the SVG for the Bob -> Alice sample */ + @Test public void testSimpleSequenceDiagram() throws IOException { final URL url = new URL(getServerUrl() + "/svg/" + TestUtils.SEQBOB); final URLConnection conn = url.openConnection(); // Analyze response // Verifies the Content-Type header - assertEquals( - "Response content type is not SVG", + Assertions.assertEquals( "image/svg+xml", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not SVG" ); // Get the content and verify its size String diagram = getContentText(conn); int diagramLen = diagram.length(); - assertTrue(diagramLen > 1000); - assertTrue(diagramLen < 3000); + Assertions.assertTrue(diagramLen > 1000); + Assertions.assertTrue(diagramLen < 3000); } /** * Verifies the generation of the SVG for the Bob -> Alice sample */ + @Test public void testPostedSequenceDiagram() throws IOException { final URL url = new URL(getServerUrl() + "/svg"); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); @@ -49,27 +54,24 @@ public class TestSVG extends WebappTestCase { } // Analyze response // HTTP response 200 - assertEquals( - "Bad HTTP status received", - 200, - conn.getResponseCode() - ); + Assertions.assertEquals(200, conn.getResponseCode(), "Bad HTTP status received"); // Verifies the Content-Type header - assertEquals( - "Response content type is not SVG", + Assertions.assertEquals( "image/svg+xml", - conn.getContentType().toLowerCase() + conn.getContentType().toLowerCase(), + "Response content type is not SVG" ); // Get the content and verify its size String diagram = getContentText(conn.getInputStream()); int diagramLen = diagram.length(); - assertTrue(diagramLen > 1000); - assertTrue(diagramLen < 3000); + Assertions.assertTrue(diagramLen > 1000); + Assertions.assertTrue(diagramLen < 3000); } /** * Verifies the generation of the SVG for the Bob -> Alice sample */ + @Test public void testPostedInvalidSequenceDiagram() throws IOException { final URL url = new URL(getServerUrl() + "/svg"); final HttpURLConnection conn = (HttpURLConnection)url.openConnection(); @@ -82,16 +84,13 @@ public class TestSVG extends WebappTestCase { } // Analyze response // HTTP response 400 - assertEquals( - "Bad HTTP status received", - 400, - conn.getResponseCode() - ); + Assertions.assertEquals(400, conn.getResponseCode(), "Bad HTTP status received"); } /** * Check the content of the SVG */ + @Test public void testSequenceDiagramContent() throws IOException { final URL url = new URL(getServerUrl() + "/svg/" + TestUtils.SEQBOB); // Analyze response @@ -112,8 +111,8 @@ public class TestSVG extends WebappTestCase { aliceCounter++; } } - assertTrue(bobCounter == 2); - assertTrue(aliceCounter == 2); + Assertions.assertTrue(bobCounter == 2); + Assertions.assertTrue(aliceCounter == 2); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestWebUI.java b/src/test/java/net/sourceforge/plantuml/servlet/TestWebUI.java index c075b50..1b76917 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestWebUI.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestWebUI.java @@ -1,7 +1,7 @@ package net.sourceforge.plantuml.servlet; -import static org.junit.Assert.assertNotEquals; - +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.WebElement; @@ -15,46 +15,49 @@ public class TestWebUI extends WebappUITestCase { /** * Verifies that the welcome page has exactly two form with the Bob --> Alice sample */ + @Test public void testWelcomePage() { driver.get(getServerUrl()); - assertTrue("UI loading completed", waitUntilUIIsLoaded()); + Assertions.assertTrue(waitUntilUIIsLoaded(), "UI loading completed"); // ensure the editor text is correct String text = getEditorValue(); - assertEquals(TestUtils.SEQBOBCODE, text); + Assertions.assertEquals(TestUtils.SEQBOBCODE, text); // ensure the URL field is correct String url = getURLValue(); - assertTrue(url.endsWith("/png/" + TestUtils.SEQBOB)); + Assertions.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 + Assertions.assertNotEquals(0, dim.getHeight()); // 145 + Assertions.assertNotEquals(0, dim.getWidth()); // 134 } /** * Verifies that the version image is generated */ + @Test public void testVersion() { driver.get(getServerUrl()); - assertTrue("UI loading completed", waitUntilUIIsLoaded()); + Assertions.assertTrue(waitUntilUIIsLoaded(), "UI loading completed"); // change code and observe result setEditorValue(TestUtils.VERSIONCODE); - assertTrue("Auto update done", waitUntilAutoRefreshCompleted()); + Assertions.assertTrue(waitUntilAutoRefreshCompleted(), "Auto update done"); // ensure the editor text is correct String text = getEditorValue(); - assertEquals(TestUtils.VERSIONCODE, text); + Assertions.assertEquals(TestUtils.VERSIONCODE, text); // ensure the URL field is correct String url = getURLValue(); - assertTrue(url.endsWith("/png/" + TestUtils.VERSION)); + Assertions.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 + Assertions.assertNotEquals(0, dim.getHeight()); // 242 + Assertions.assertNotEquals(0, dim.getWidth()); // 472 } // /** // * Verifies that when the UML text is empty, ... // * old behavior: default page and image is generated // */ + // @Test // public void testEmptyText() { // // ... // } @@ -63,6 +66,7 @@ public class TestWebUI extends WebappUITestCase { // * Verifies that when the encoded URL is empty, ... // * old behavior: default page and image is generated // */ + // @Test // public void testEmptyUrl() { // // ... // } @@ -70,69 +74,72 @@ public class TestWebUI extends WebappUITestCase { /** * Verifies that a ditaa diagram is generated */ + @Test public void testDitaaText() { driver.get(getServerUrl()); - assertTrue("UI loading completed", waitUntilUIIsLoaded()); + Assertions.assertTrue(waitUntilUIIsLoaded(), "UI loading completed"); // change code and observe result setEditorValue("@startditaa \n*--> \n@endditaa"); - assertTrue("Auto update done", waitUntilAutoRefreshCompleted()); + Assertions.assertTrue(waitUntilAutoRefreshCompleted(), "Auto update done"); // ensure the editor text is correct String text = getEditorValue(); - assertEquals("@startditaa \n*--> \n@endditaa", text); + Assertions.assertEquals("@startditaa \n*--> \n@endditaa", text); // ensure the URL field is correct String url = getURLValue(); - assertTrue(url.endsWith("/png/SoWkIImgISaiIKnKuDBIrRLJu798pKi12m00")); + Assertions.assertTrue(url.endsWith("/png/SoWkIImgISaiIKnKuDBIrRLJu798pKi12m00")); // ensure the generated image is present Dimension dim = getImageSize(); - assertNotEquals(0, dim.getHeight()); - assertNotEquals(0, dim.getWidth()); + Assertions.assertNotEquals(0, dim.getHeight()); + Assertions.assertNotEquals(0, dim.getWidth()); } /** * Verifies that an image map is produced if the diagram contains a link */ + @Test public void testImageMap() { driver.get(getServerUrl()); - assertTrue("UI loading completed", waitUntilUIIsLoaded()); + Assertions.assertTrue(waitUntilUIIsLoaded(), "UI loading completed"); // change code and observe result setEditorValue("@startuml\nBob -> Alice : [[http://yahoo.com]] Hello\n@enduml"); - assertTrue("Auto update done", waitUntilAutoRefreshCompleted()); + Assertions.assertTrue(waitUntilAutoRefreshCompleted(), "Auto update done"); // ensure the editor text is correct String text = getEditorValue(); - assertEquals("@startuml\nBob -> Alice : [[http://yahoo.com]] Hello\n@enduml", text); + Assertions.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")); + Assertions.assertTrue(url.endsWith("/png/SyfFKj2rKt3CoKnELR1IY8xEA2afiDBNhqpCoC_NIyxFZOrLy4ZDoSa70000")); // ensure the generated image is present Dimension dim = getImageSize(); - assertNotEquals(0, dim.getHeight()); - assertNotEquals(0, dim.getWidth()); + Assertions.assertNotEquals(0, dim.getHeight()); + Assertions.assertNotEquals(0, dim.getWidth()); // ensure the image map is present WebElement map = getImageMap(); - assertNotNull(map); - assertEquals(1, Integer.parseInt(map.getAttribute("childElementCount"))); + Assertions.assertNotNull(map); + Assertions.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()); + Assertions.assertTrue(btnMap.isDisplayed()); } /** * Verifies that when the encoded source is specified as an URL parameter * the diagram is displayed and the source is decoded */ + @Test public void testUrlParameter() { driver.get(getServerUrl() + "/form?url=" + TestUtils.SEQBOB); - assertTrue("UI loading completed", waitUntilUIIsLoaded()); + Assertions.assertTrue(waitUntilUIIsLoaded(), "UI loading completed"); // ensure the editor text is correct String text = getEditorValue(); - assertEquals(TestUtils.SEQBOBCODE, text); + Assertions.assertEquals(TestUtils.SEQBOBCODE, text); // ensure the URL field is correct String url = getURLValue(); - assertTrue(url.endsWith("/png/" + TestUtils.SEQBOB)); + Assertions.assertTrue(url.endsWith("/png/" + TestUtils.SEQBOB)); // ensure the generated image is present Dimension dim = getImageSize(); - assertNotEquals(0, dim.getHeight()); - assertNotEquals(0, dim.getWidth()); + Assertions.assertNotEquals(0, dim.getHeight()); + Assertions.assertNotEquals(0, dim.getWidth()); } /** @@ -147,28 +154,29 @@ public class TestWebUI extends WebappUITestCase { * newpage * Bob <- Alice : bye */ + @Test public void testIndexPage() { driver.get( getServerUrl() + "/uml/1/" + "SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00" ); - assertTrue("UI loading completed", waitUntilUIIsLoaded()); + Assertions.assertTrue(waitUntilUIIsLoaded(), "UI loading completed"); // ensure the editor text is correct String text = getEditorValue(); - assertEquals( + Assertions.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")); + Assertions.assertTrue(url.endsWith("/png/1/SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00")); // ensure the generated image is present Dimension dim = getImageSize(); - assertNotEquals(0, dim.getHeight()); - assertNotEquals(0, dim.getWidth()); + Assertions.assertNotEquals(0, dim.getHeight()); + Assertions.assertNotEquals(0, dim.getWidth()); // ensure the correct index was generated - assertTrue(dim.getHeight() > 200); // 222 - assertTrue(dim.getHeight() < 250); // 222 + Assertions.assertTrue(dim.getHeight() > 200); // 222 + Assertions.assertTrue(dim.getHeight() < 250); // 222 } /** @@ -183,27 +191,28 @@ public class TestWebUI extends WebappUITestCase { * newpage * Bob <- Alice : bye */ + @Test public void testIndexPageWithNoDefinedIndex() { driver.get( getServerUrl() + "/uml/" + "SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00" ); - assertTrue("UI loading completed", waitUntilUIIsLoaded()); + Assertions.assertTrue(waitUntilUIIsLoaded(), "UI loading completed"); // ensure the editor text is correct String text = getEditorValue(); - assertEquals( + Assertions.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")); + Assertions.assertTrue(url.endsWith("/png/SyfFKj2rKt3CoKnELR1Io4ZDoSddoaijBqXCJ-Lo0ahQwA99Eg7go4ajKIzMA4dCoKPNdfHQKf9Qf92NNuAknqQjA34ppquXgJ8Lbrr0AG00")); // ensure the generated image is present Dimension dim = getImageSize(); - assertNotEquals(0, dim.getHeight()); - assertNotEquals(0, dim.getWidth()); + Assertions.assertNotEquals(0, dim.getHeight()); + Assertions.assertNotEquals(0, dim.getWidth()); // ensure the correct index was generated - assertTrue(dim.getHeight() > 100); // 132 - assertTrue(dim.getHeight() < 150); // 132 + Assertions.assertTrue(dim.getHeight() > 100); // 132 + Assertions.assertTrue(dim.getHeight() < 150); // 132 } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/utils/WebappTestCase.java b/src/test/java/net/sourceforge/plantuml/servlet/utils/WebappTestCase.java index b11f706..3b97d8e 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/utils/WebappTestCase.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/utils/WebappTestCase.java @@ -7,15 +7,17 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; +import java.util.stream.Collectors; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import net.sourceforge.plantuml.servlet.server.EmbeddedJettyServer; import net.sourceforge.plantuml.servlet.server.ExternalServer; import net.sourceforge.plantuml.servlet.server.ServerUtils; -public abstract class WebappTestCase extends TestCase { +public abstract class WebappTestCase { private final ServerUtils serverUtils; @@ -34,12 +36,12 @@ public abstract class WebappTestCase extends TestCase { serverUtils = new EmbeddedJettyServer(); } - @Override + @BeforeEach public void setUp() throws Exception { serverUtils.startServer(); } - @Override + @AfterEach public void tearDown() throws Exception { serverUtils.stopServer(); } @@ -67,17 +69,8 @@ public abstract class WebappTestCase extends TestCase { } public String getContentText(final InputStream stream) throws IOException { - try ( - final InputStreamReader isr = new InputStreamReader(stream); - final BufferedReader br = new BufferedReader(isr); - ) { - String line; - StringBuffer sb = new StringBuffer(); - while ((line = br.readLine()) != null) { - sb.append(line); - sb.append("\n"); - } - return sb.toString().trim(); + try (final BufferedReader br = new BufferedReader(new InputStreamReader(stream))) { + return br.lines().collect(Collectors.joining("\n")); } } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/utils/WebappUITestCase.java b/src/test/java/net/sourceforge/plantuml/servlet/utils/WebappUITestCase.java index 59590bd..f802d9d 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/utils/WebappUITestCase.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/utils/WebappUITestCase.java @@ -2,6 +2,8 @@ package net.sourceforge.plantuml.servlet.utils; import java.time.Duration; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.JavascriptExecutor; @@ -16,14 +18,14 @@ public abstract class WebappUITestCase extends WebappTestCase { public WebDriver driver; public JavascriptExecutor js; - @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); driver = JUnitWebDriver.getDriver(); js = (JavascriptExecutor)driver; } - @Override + @AfterEach public void tearDown() throws Exception { driver.close(); super.tearDown();