"));
- assertTrue(xmlString.contains("This is child element 1"));
- assertTrue(xmlString.contains("This is child element 2"));
- } catch (XmlException e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/xml-2/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java b/xml-2/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java
new file mode 100644
index 0000000000..b05123cbdc
--- /dev/null
+++ b/xml-2/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java
@@ -0,0 +1,61 @@
+package com.baeldung.xmlhtml.delhtmltags;
+
+import net.htmlparser.jericho.Renderer;
+import net.htmlparser.jericho.Segment;
+import net.htmlparser.jericho.Source;
+import org.htmlcleaner.CleanerProperties;
+import org.htmlcleaner.HtmlCleaner;
+import org.jsoup.Jsoup;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+class RemoveHtmlTagsLiveTest {
+
+ @Test
+ void givenHtml1_whenRemoveTagsByRegex_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example1.html").toURI()))));
+ String result = html.replaceAll("<[^>]*>", "")
+ .replaceAll("(?m)^\\s*$", ""); // remove empty and blank lines
+ System.out.println(result);
+ }
+
+ @Test
+ void givenHtml2_whenRemoveTagsByRegex_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI()))));
+ String result = html.replaceAll("<[^>]*>", "");
+ System.out.println(result);
+ }
+
+ @Test
+ void givenHtml2_whenRemoveTagsByJsoup_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI()))));
+ System.out.println(Jsoup.parse(html).text());
+ }
+
+ @Test
+ void givenHtml2_whenRemoveTagsByHtmlCleaner_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI()))));
+ CleanerProperties props = new CleanerProperties();
+ props.setPruneTags("script");
+ String result = new HtmlCleaner(props).clean(html).getText().toString();
+ System.out.println(result);
+ }
+
+ @Test
+ void givenHtml2_whenRemoveTagsByJericho_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI()))));
+ Source htmlSource = new Source(html);
+ Segment segment = new Segment(htmlSource, 0, htmlSource.length());
+ Renderer htmlRender = new Renderer(segment).setIncludeHyperlinkURLs(true);
+ System.out.println(htmlRender);
+ }
+}
diff --git a/xml-2/src/test/java/com/baeldung/xmlhtml/freemarker/FreemarkerTransformerUnitTest.java b/xml-2/src/test/java/com/baeldung/xmlhtml/freemarker/FreemarkerTransformerUnitTest.java
new file mode 100644
index 0000000000..c110f88e99
--- /dev/null
+++ b/xml-2/src/test/java/com/baeldung/xmlhtml/freemarker/FreemarkerTransformerUnitTest.java
@@ -0,0 +1,32 @@
+package com.baeldung.xmlhtml.freemarker;
+
+import com.baeldung.xmlhtml.stax.StaxTransformer;
+import freemarker.template.TemplateException;
+import org.junit.jupiter.api.Test;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class FreemarkerTransformerUnitTest {
+
+ @Test
+ public void givenXml_whenTransform_thenGetHtml() throws IOException, URISyntaxException, XMLStreamException, TemplateException {
+ String expectedHtml = new String(Files.readAllBytes((Paths.get(getClass()
+ .getResource("/xmlhtml/notification.html")
+ .toURI()))));
+ StaxTransformer staxTransformer = new StaxTransformer("src/test/resources/xmlhtml/notification.xml");
+ String templateFile = "freemarker.html";
+ String templateDirectory = "src/test/resources/templates";
+ FreemarkerTransformer transformer = new FreemarkerTransformer(staxTransformer, templateDirectory, templateFile);
+
+ String result = transformer.html();
+
+ assertThat(result).isEqualTo(expectedHtml);
+ }
+
+}
diff --git a/xml-2/src/test/java/com/baeldung/xmlhtml/jaxp/JaxpTransformerUnitTest.java b/xml-2/src/test/java/com/baeldung/xmlhtml/jaxp/JaxpTransformerUnitTest.java
new file mode 100644
index 0000000000..02fc422ee9
--- /dev/null
+++ b/xml-2/src/test/java/com/baeldung/xmlhtml/jaxp/JaxpTransformerUnitTest.java
@@ -0,0 +1,33 @@
+package com.baeldung.xmlhtml.jaxp;
+
+import org.junit.jupiter.api.Test;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JaxpTransformerUnitTest {
+
+ @Test
+ public void givenXml_whenTransform_thenGetHtml() throws IOException, SAXException, ParserConfigurationException, TransformerException, URISyntaxException {
+ String path = getClass()
+ .getResource("/xmlhtml/notification.xml")
+ .toString();
+ String expectedHtml = new String(Files.readAllBytes((Paths.get(getClass()
+ .getResource("/xmlhtml/notification.html")
+ .toURI()))));
+ JaxpTransformer transformer = new JaxpTransformer(path);
+
+ String result = transformer
+ .html()
+ .replaceAll("(?m)^\\s+", "");//Delete extra spaces added by Java 11
+
+ assertThat(result).isEqualTo(expectedHtml);
+ }
+}
diff --git a/xml-2/src/test/java/com/baeldung/xmlhtml/mustache/MustacheTransformerUnitTest.java b/xml-2/src/test/java/com/baeldung/xmlhtml/mustache/MustacheTransformerUnitTest.java
new file mode 100644
index 0000000000..b53a23d4fb
--- /dev/null
+++ b/xml-2/src/test/java/com/baeldung/xmlhtml/mustache/MustacheTransformerUnitTest.java
@@ -0,0 +1,30 @@
+package com.baeldung.xmlhtml.mustache;
+
+import com.baeldung.xmlhtml.stax.StaxTransformer;
+import org.junit.jupiter.api.Test;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MustacheTransformerUnitTest {
+
+ @Test
+ public void givenXml_whenTransform_thenGetHtml() throws IOException, URISyntaxException, XMLStreamException {
+ String expectedHtml = new String(Files.readAllBytes((Paths.get(getClass()
+ .getResource("/xmlhtml/notification.html")
+ .toURI()))));
+ StaxTransformer staxTransformer = new StaxTransformer("src/test/resources/xmlhtml/notification.xml");
+ String templateFile = "src/test/resources/templates/template.mustache";
+ MustacheTransformer transformer = new MustacheTransformer(staxTransformer, templateFile);
+
+ String result = transformer.html();
+
+ assertThat(result).isEqualTo(expectedHtml);
+ }
+
+}
diff --git a/xml-2/src/test/java/com/baeldung/xmlhtml/stax/StaxTransformerUnitTest.java b/xml-2/src/test/java/com/baeldung/xmlhtml/stax/StaxTransformerUnitTest.java
new file mode 100644
index 0000000000..efb2edc7a3
--- /dev/null
+++ b/xml-2/src/test/java/com/baeldung/xmlhtml/stax/StaxTransformerUnitTest.java
@@ -0,0 +1,30 @@
+package com.baeldung.xmlhtml.stax;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class StaxTransformerUnitTest {
+
+ @Disabled // JAVA-39223
+ @Test
+ public void givenXml_whenTransform_thenGetHtml() throws IOException, URISyntaxException, XMLStreamException {
+ String path = "src/test/resources/xmlhtml/notification.xml";
+ String expectedHtml = new String(Files.readAllBytes((Paths.get(getClass()
+ .getResource("/xmlhtml/notification.html")
+ .toURI()))));
+ StaxTransformer transformer = new StaxTransformer(path);
+
+ String result = transformer.html();
+
+ assertThat(result).isEqualTo(expectedHtml);
+ }
+
+}
diff --git a/xml-2/src/test/resources/Customer1.xml b/xml-2/src/test/resources/Customer1.xml
new file mode 100644
index 0000000000..7f4fbc79af
--- /dev/null
+++ b/xml-2/src/test/resources/Customer1.xml
@@ -0,0 +1,16 @@
+
+
+
+ 12345
+ Stefan Jaeger
+
+
+ 234678
+
+
+
+ 234678
+
+ Davos Dorf
+
+
\ No newline at end of file
diff --git a/xml-2/src/test/resources/templates/freemarker.html b/xml-2/src/test/resources/templates/freemarker.html
new file mode 100644
index 0000000000..15ec7f9fff
--- /dev/null
+++ b/xml-2/src/test/resources/templates/freemarker.html
@@ -0,0 +1,11 @@
+
+
+
+
+${heading}
+
+
+${from}
+${content}
+
+
diff --git a/xml-2/src/test/resources/templates/template.mustache b/xml-2/src/test/resources/templates/template.mustache
new file mode 100644
index 0000000000..8c209843e1
--- /dev/null
+++ b/xml-2/src/test/resources/templates/template.mustache
@@ -0,0 +1,11 @@
+
+
+
+
+{{heading}}
+
+
+{{from}}
+{{content}}
+
+
diff --git a/xml-2/src/test/resources/xml/attribute.xml b/xml-2/src/test/resources/xml/attribute.xml
new file mode 100644
index 0000000000..c8fa3f1071
--- /dev/null
+++ b/xml-2/src/test/resources/xml/attribute.xml
@@ -0,0 +1,5 @@
+
+
+ john@email.com
+ mary@email.com
+
\ No newline at end of file
diff --git a/xml-2/src/test/resources/xml/attribute_expected.xml b/xml-2/src/test/resources/xml/attribute_expected.xml
new file mode 100644
index 0000000000..1d5d7b0cea
--- /dev/null
+++ b/xml-2/src/test/resources/xml/attribute_expected.xml
@@ -0,0 +1,5 @@
+
+
+ john@email.com
+ mary@email.com
+
\ No newline at end of file
diff --git a/xml-2/src/test/resources/xml/xee_attribute.xml b/xml-2/src/test/resources/xml/xee_attribute.xml
new file mode 100644
index 0000000000..2e98df076b
--- /dev/null
+++ b/xml-2/src/test/resources/xml/xee_attribute.xml
@@ -0,0 +1,9 @@
+
+ ]>
+
+ &xxe;
+
+ john@email.com
+ mary@email.com
+
\ No newline at end of file
diff --git a/xml-2/src/test/resources/xmlhtml/delhtmltags/example1.html b/xml-2/src/test/resources/xmlhtml/delhtmltags/example1.html
new file mode 100644
index 0000000000..43f3a22ef4
--- /dev/null
+++ b/xml-2/src/test/resources/xmlhtml/delhtmltags/example1.html
@@ -0,0 +1,15 @@
+
+
+
+ This is the page title
+
+
+
+ If the application X doesn't start, the possible causes could be:
+ 1. Maven is not installed.
+ 2. Not enough disk space.
+ 3. Not enough memory.
+
+
+
\ No newline at end of file
diff --git a/xml-2/src/test/resources/xmlhtml/delhtmltags/example2.html b/xml-2/src/test/resources/xmlhtml/delhtmltags/example2.html
new file mode 100644
index 0000000000..532eadc101
--- /dev/null
+++ b/xml-2/src/test/resources/xmlhtml/delhtmltags/example2.html
@@ -0,0 +1,22 @@
+
+
+
+ This is the page title
+
+
+
+
+ If the application X doesn't start, the possible causes could be:
+ 1.
+ Maven
+ is not installed.
+ 2. Not enough (<1G) disk space.
+ 3. Not enough (<64MB) memory.
+
+
+
\ No newline at end of file
diff --git a/xml-2/src/test/resources/xmlhtml/notification.html b/xml-2/src/test/resources/xmlhtml/notification.html
new file mode 100644
index 0000000000..4a0ef09c5d
--- /dev/null
+++ b/xml-2/src/test/resources/xmlhtml/notification.html
@@ -0,0 +1,11 @@
+
+
+
+
+Build #7 passed
+
+
+from: builds@baeldung.com
+Success: The Jenkins CI build passed
+
+
diff --git a/xml-2/src/test/resources/xmlhtml/notification.xml b/xml-2/src/test/resources/xmlhtml/notification.xml
new file mode 100644
index 0000000000..c3550d6f04
--- /dev/null
+++ b/xml-2/src/test/resources/xmlhtml/notification.xml
@@ -0,0 +1,6 @@
+
+
+ builds@baeldung.com
+ Build #7 passed
+ Success: The Jenkins CI build passed
+
\ No newline at end of file