"));
- 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/isharkfly/xml/XMLDocumentWriterUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/XMLDocumentWriterUnitTest.java
new file mode 100644
index 0000000000..7322ee061b
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xml/XMLDocumentWriterUnitTest.java
@@ -0,0 +1,52 @@
+package com.isharkfly.xml;
+
+import com.isharkfly.xml.XMLDocumentWriter;
+import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+
+public class XMLDocumentWriterUnitTest {
+
+ @Test
+ public void givenXMLDocumentWhenWriteIsCalledThenXMLIsWrittenToFile() throws Exception {
+ Document document = createSampleDocument();
+ new XMLDocumentWriter().write(document, "company_simple.xml", false, false);
+ }
+
+ @Test
+ public void givenXMLDocumentWhenWriteIsCalledWithPrettyPrintThenFormattedXMLIsWrittenToFile() throws Exception {
+ Document document = createSampleDocument();
+ new XMLDocumentWriter().write(document, "company_prettyprinted.xml", false, true);
+ }
+
+ private Document createSampleDocument() throws ParserConfigurationException {
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ Document document = documentBuilder.newDocument();
+ Element companyElement = document.createElement("Company");
+ document.appendChild(companyElement);
+ Element departmentElement = document.createElement("Department");
+ departmentElement.setAttribute("name", "Sales");
+ companyElement.appendChild(departmentElement);
+ Element employee1 = document.createElement("Employee");
+ employee1.setAttribute("name", "John Smith");
+ departmentElement.appendChild(employee1);
+ Element employee2 = document.createElement("Employee");
+ employee2.setAttribute("name", "Tim Dellor");
+ departmentElement.appendChild(employee2);
+ return document;
+ }
+
+ @After
+ public void cleanUp() throws Exception {
+ FileUtils.deleteQuietly(new File("company_simple.xml"));
+ FileUtils.deleteQuietly(new File("company_prettyprinted.xml"));
+ }
+}
diff --git a/xml-2/src/test/java/com/isharkfly/xml/attribute/Dom4jProcessorUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/attribute/Dom4jProcessorUnitTest.java
new file mode 100644
index 0000000000..467a26efe0
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xml/attribute/Dom4jProcessorUnitTest.java
@@ -0,0 +1,70 @@
+package com.isharkfly.xml.attribute;
+
+import com.isharkfly.xml.attribute.Dom4jTransformer;
+import org.dom4j.DocumentException;
+import org.junit.jupiter.api.Test;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.xpath.XPathExpressionException;
+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.assertThatThrownBy;
+import static org.xmlunit.assertj.XmlAssert.assertThat;
+
+/**
+ * Unit test for {@link Dom4jTransformer}.
+ */
+public class Dom4jProcessorUnitTest {
+
+ @Test
+ public void givenXmlWithAttributes_whenModifyAttribute_thenGetXmlUpdated() throws TransformerFactoryConfigurationError, TransformerException, DocumentException, SAXException {
+ String path = getClass().getResource("/xml/attribute.xml")
+ .toString();
+ Dom4jTransformer transformer = new Dom4jTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+
+ String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+
+ assertThat(result).hasXPath("//*[contains(@customer, 'false')]");
+ }
+
+ @Test
+ public void givenTwoXml_whenModifyAttribute_thenGetSimilarXml() throws IOException, TransformerFactoryConfigurationError, TransformerException, URISyntaxException, DocumentException, SAXException {
+ String path = getClass().getResource("/xml/attribute.xml")
+ .toString();
+ Dom4jTransformer transformer = new Dom4jTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+ String expectedXml = new String(Files.readAllBytes((Paths.get(getClass().getResource("/xml/attribute_expected.xml")
+ .toURI()))));
+
+ String result = transformer
+ .modifyAttribute(attribute, oldValue, newValue)
+ .replaceAll("(?m)^[ \t]*\r?\n", "");//Delete extra spaces added by Java 11
+
+ assertThat(result).and(expectedXml)
+ .areSimilar();
+ }
+
+ @Test
+ public void givenXmlXee_whenInit_thenThrowException() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException, TransformerFactoryConfigurationError, TransformerException {
+ String path = getClass().getResource("/xml/xee_attribute.xml")
+ .toString();
+
+ assertThatThrownBy(() -> {
+
+ new Dom4jTransformer(path);
+
+ }).isInstanceOf(DocumentException.class);
+ }
+
+}
diff --git a/xml-2/src/test/java/com/isharkfly/xml/attribute/JaxpProcessorUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/attribute/JaxpProcessorUnitTest.java
new file mode 100644
index 0000000000..04d6cb2b47
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xml/attribute/JaxpProcessorUnitTest.java
@@ -0,0 +1,48 @@
+package com.isharkfly.xml.attribute;
+
+import com.isharkfly.xml.attribute.JaxpTransformer;
+import org.junit.jupiter.api.Test;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.xpath.XPathExpressionException;
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.xmlunit.assertj.XmlAssert.assertThat;
+
+/**
+ * Unit test for {@link JaxpTransformer}.
+ */
+public class JaxpProcessorUnitTest {
+
+ @Test
+ public void givenXmlWithAttributes_whenModifyAttribute_thenGetXmlUpdated() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException, TransformerFactoryConfigurationError, TransformerException {
+ String path = getClass().getResource("/xml/attribute.xml")
+ .toString();
+ JaxpTransformer transformer = new JaxpTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+
+ String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+
+ assertThat(result).hasXPath("//*[contains(@customer, 'false')]");
+ }
+
+ @Test
+ public void givenXmlXee_whenInit_thenThrowException() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException, TransformerFactoryConfigurationError, TransformerException {
+ String path = getClass().getResource("/xml/xee_attribute.xml")
+ .toString();
+
+ assertThatThrownBy(() -> {
+
+ new JaxpTransformer(path);
+
+ }).isInstanceOf(SAXParseException.class);
+ }
+
+}
diff --git a/xml-2/src/test/java/com/isharkfly/xml/attribute/JooxProcessorUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/attribute/JooxProcessorUnitTest.java
new file mode 100644
index 0000000000..3dc5a13343
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xml/attribute/JooxProcessorUnitTest.java
@@ -0,0 +1,70 @@
+package com.isharkfly.xml.attribute;
+
+import com.isharkfly.xml.attribute.JooxTransformer;
+import org.junit.jupiter.api.Test;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.xpath.XPathExpressionException;
+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.assertThatThrownBy;
+import static org.xmlunit.assertj.XmlAssert.assertThat;
+
+/**
+ * Unit test for {@link JooxTransformer}.
+ */
+public class JooxProcessorUnitTest {
+
+ @Test
+ public void givenXmlWithAttributes_whenModifyAttribute_thenGetXmlUpdated() throws IOException, SAXException, TransformerFactoryConfigurationError {
+ String path = getClass().getResource("/xml/attribute.xml")
+ .toString();
+ JooxTransformer transformer = new JooxTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+
+ String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+
+ assertThat(result).hasXPath("//*[contains(@customer, 'false')]");
+ }
+
+ @Test
+ public void givenTwoXml_whenModifyAttribute_thenGetSimilarXml() throws IOException, TransformerFactoryConfigurationError, URISyntaxException, SAXException {
+ String path = getClass().getResource("/xml/attribute.xml")
+ .toString();
+ JooxTransformer transformer = new JooxTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+ String expectedXml = new String(Files.readAllBytes((Paths.get(getClass().getResource("/xml/attribute_expected.xml")
+ .toURI()))));
+
+ String result = transformer
+ .modifyAttribute(attribute, oldValue, newValue)
+ .replaceAll("(?m)^[ \t]*\r?\n", "");//Delete extra spaces added by Java 11
+
+ assertThat(result).and(expectedXml)
+ .areSimilar();
+ }
+
+ @Test
+ public void givenXmlXee_whenInit_thenThrowException() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException, TransformerFactoryConfigurationError, TransformerException {
+ String path = getClass().getResource("/xml/xee_attribute.xml")
+ .toString();
+
+ assertThatThrownBy(() -> {
+
+ new JooxTransformer(path);
+
+ }).isInstanceOf(SAXParseException.class);
+ }
+
+}
diff --git a/xml-2/src/test/java/com/baeldung/xml/invalidcharacters/InvalidCharactersUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/invalidcharacters/InvalidCharactersUnitTest.java
similarity index 98%
rename from xml-2/src/test/java/com/baeldung/xml/invalidcharacters/InvalidCharactersUnitTest.java
rename to xml-2/src/test/java/com/isharkfly/xml/invalidcharacters/InvalidCharactersUnitTest.java
index 7878e72f97..3ca4036855 100644
--- a/xml-2/src/test/java/com/baeldung/xml/invalidcharacters/InvalidCharactersUnitTest.java
+++ b/xml-2/src/test/java/com/isharkfly/xml/invalidcharacters/InvalidCharactersUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.xml.invalidcharacters;
+package com.isharkfly.xml.invalidcharacters;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
diff --git a/xml-2/src/test/java/com/isharkfly/xml/jibx/CustomerUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/jibx/CustomerUnitTest.java
new file mode 100644
index 0000000000..58af978645
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xml/jibx/CustomerUnitTest.java
@@ -0,0 +1,53 @@
+package com.isharkfly.xml.jibx;
+
+import com.isharkfly.xml.jibx.Customer;
+import org.jibx.runtime.BindingDirectory;
+import org.jibx.runtime.IBindingFactory;
+import org.jibx.runtime.IUnmarshallingContext;
+import org.jibx.runtime.JiBXException;
+import org.junit.Test;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import static junit.framework.Assert.assertEquals;
+
+public class CustomerUnitTest {
+
+ @Test
+ public void whenUnmarshalXML_ThenFieldsAreMapped() throws JiBXException, FileNotFoundException {
+ IBindingFactory bfact = BindingDirectory.getFactory(Customer.class);
+ IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
+ Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
+
+ assertEquals("Stefan Jaeger", customer.getPerson().getName());
+ assertEquals("Davos Dorf", customer.getCity());
+
+ }
+
+ @Test
+ public void WhenUnmarshal_ThenMappingInherited() throws JiBXException, FileNotFoundException {
+ IBindingFactory bfact = BindingDirectory.getFactory(Customer.class);
+ IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
+ Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
+
+ assertEquals(12345, customer.getPerson().getCustomerId());
+
+ }
+
+ @Test
+ public void WhenUnmarshal_ThenPhoneMappingRead() throws JiBXException, FileNotFoundException {
+ IBindingFactory bfact = BindingDirectory.getFactory(Customer.class);
+ IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
+ Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
+
+ assertEquals("234678", customer.getHomePhone().getNumber());
+
+ }
+}
diff --git a/xml-2/src/test/java/com/baeldung/xml/tohashmap/XmlToHashMapUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/tohashmap/XmlToHashMapUnitTest.java
similarity index 92%
rename from xml-2/src/test/java/com/baeldung/xml/tohashmap/XmlToHashMapUnitTest.java
rename to xml-2/src/test/java/com/isharkfly/xml/tohashmap/XmlToHashMapUnitTest.java
index 5e05dd3ccb..234a180f3f 100644
--- a/xml-2/src/test/java/com/baeldung/xml/tohashmap/XmlToHashMapUnitTest.java
+++ b/xml-2/src/test/java/com/isharkfly/xml/tohashmap/XmlToHashMapUnitTest.java
@@ -1,13 +1,13 @@
-package com.baeldung.xml.tohashmap;
+package com.isharkfly.xml.tohashmap;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-import java.util.ArrayList;
import java.util.Map;
-import javax.xml.bind.JAXBException;
-
+import com.isharkfly.xml.tohashmap.Employee;
+import com.isharkfly.xml.tohashmap.XmlToHashMap;
+import jakarta.xml.bind.JAXBException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/xml-2/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/xml2csv/Xml2CsvExampleUnitTest.java
similarity index 98%
rename from xml-2/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java
rename to xml-2/src/test/java/com/isharkfly/xml/xml2csv/Xml2CsvExampleUnitTest.java
index 181d284b2d..7bdfac403e 100644
--- a/xml-2/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java
+++ b/xml-2/src/test/java/com/isharkfly/xml/xml2csv/Xml2CsvExampleUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.xml.xml2csv;
+package com.isharkfly.xml.xml2csv;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -18,6 +18,7 @@ import java.util.concurrent.Executors;
import javax.xml.transform.TransformerException;
+import com.isharkfly.xml.xml2csv.Xml2CsvExample;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
diff --git a/xml-2/src/test/java/com/baeldung/xml/xml2document/XMLStringToDocumentObjectUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/xml2document/XMLStringToDocumentObjectUnitTest.java
similarity index 95%
rename from xml-2/src/test/java/com/baeldung/xml/xml2document/XMLStringToDocumentObjectUnitTest.java
rename to xml-2/src/test/java/com/isharkfly/xml/xml2document/XMLStringToDocumentObjectUnitTest.java
index f573e1c96d..2d1b6cce3c 100644
--- a/xml-2/src/test/java/com/baeldung/xml/xml2document/XMLStringToDocumentObjectUnitTest.java
+++ b/xml-2/src/test/java/com/isharkfly/xml/xml2document/XMLStringToDocumentObjectUnitTest.java
@@ -1,37 +1,37 @@
-package com.baeldung.xml2document;
-
-import org.junit.Test;
-import org.w3c.dom.*;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import java.io.IOException;
-import java.io.StringReader;
-
-import static org.junit.Assert.assertEquals;
-
-public class XMLStringToDocumentObjectUnitTest {
- @Test
- public void givenValidXMLString_whenParsing_thenDocumentIsCorrect() throws ParserConfigurationException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- String xmlString = "XML Parsing Example";
- InputSource is = new InputSource(new StringReader(xmlString));
- Document xmlDoc = null;
- try {
- xmlDoc = builder.parse(is);
- } catch (SAXException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- assertEquals("root", xmlDoc.getDocumentElement().getNodeName());
- assertEquals("element", xmlDoc.getDocumentElement().getElementsByTagName("element").item(0).getNodeName());
- assertEquals("XML Parsing Example", xmlDoc.getDocumentElement().getElementsByTagName("element").item(0).getTextContent());
- }
-}
+package com.isharkfly.xml.xml2document;
+
+import org.junit.Test;
+import org.w3c.dom.*;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import static org.junit.Assert.assertEquals;
+
+public class XMLStringToDocumentObjectUnitTest {
+ @Test
+ public void givenValidXMLString_whenParsing_thenDocumentIsCorrect() throws ParserConfigurationException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ String xmlString = "XML Parsing Example";
+ InputSource is = new InputSource(new StringReader(xmlString));
+ Document xmlDoc = null;
+ try {
+ xmlDoc = builder.parse(is);
+ } catch (SAXException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ assertEquals("root", xmlDoc.getDocumentElement().getNodeName());
+ assertEquals("element", xmlDoc.getDocumentElement().getElementsByTagName("element").item(0).getNodeName());
+ assertEquals("XML Parsing Example", xmlDoc.getDocumentElement().getElementsByTagName("element").item(0).getTextContent());
+ }
+}
diff --git a/xml-2/src/test/java/com/isharkfly/xml/xml2pdf/XmlToPdfConverterUnitTest.java b/xml-2/src/test/java/com/isharkfly/xml/xml2pdf/XmlToPdfConverterUnitTest.java
new file mode 100644
index 0000000000..cb77f43b3c
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xml/xml2pdf/XmlToPdfConverterUnitTest.java
@@ -0,0 +1,48 @@
+package com.isharkfly.xml.xml2pdf;
+
+import com.isharkfly.xml.xml2pdf.XmlToPdfConverter;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class XmlToPdfConverterUnitTest {
+
+ private static final String BASE_PATH = "src/main/resources/xmltopdf/";
+
+ private static final String STYLE_XSL = BASE_PATH + "style.xsl";
+ private static final String DATA_XML_INPUT = BASE_PATH + "data-input.xml";
+ private static final String DATA_PDF_OUTPUT = BASE_PATH + "data-output.pdf";
+
+ // Comment out this method if you need to keep the outputted PDF file.
+ @AfterEach
+ public void teardown() {
+ new File(DATA_PDF_OUTPUT).delete();
+ }
+
+ @Test
+ public void givenXmlFile_whenConvertToPdfUsingFop_thenPdfGenerated() throws Exception {
+ // Execute XML to PDF conversion
+ XmlToPdfConverter.convertXMLtoPDFUsingFop(DATA_XML_INPUT, STYLE_XSL, DATA_PDF_OUTPUT);
+ // Check if PDF file was created
+ File pdfFile = new File(DATA_PDF_OUTPUT);
+ assertTrue(pdfFile.exists());
+ assertTrue(pdfFile.isFile());
+ assertTrue(pdfFile.length() > 0);
+
+ }
+
+ @Test
+ public void givenXmlFile_whenConvertToPdfUsingIText_thenPdfGenerated() throws Exception {
+ // Execute XML to PDF conversion
+ XmlToPdfConverter.convertXMLtoPDFUsingIText(DATA_XML_INPUT, DATA_PDF_OUTPUT);
+ // Check if PDF file was created
+ File pdfFile = new File(DATA_PDF_OUTPUT);
+ assertTrue(pdfFile.exists());
+ assertTrue(pdfFile.isFile());
+ assertTrue(pdfFile.length() > 0);
+ }
+
+}
diff --git a/xml-2/src/test/java/com/isharkfly/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java b/xml-2/src/test/java/com/isharkfly/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java
new file mode 100644
index 0000000000..0e746bb447
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java
@@ -0,0 +1,61 @@
+package com.isharkfly.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/isharkfly/xmlhtml/freemarker/FreemarkerTransformerUnitTest.java b/xml-2/src/test/java/com/isharkfly/xmlhtml/freemarker/FreemarkerTransformerUnitTest.java
new file mode 100644
index 0000000000..a2e31bedfc
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xmlhtml/freemarker/FreemarkerTransformerUnitTest.java
@@ -0,0 +1,33 @@
+package com.isharkfly.xmlhtml.freemarker;
+
+import com.isharkfly.xmlhtml.freemarker.FreemarkerTransformer;
+import com.isharkfly.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/isharkfly/xmlhtml/jaxp/JaxpTransformerUnitTest.java b/xml-2/src/test/java/com/isharkfly/xmlhtml/jaxp/JaxpTransformerUnitTest.java
new file mode 100644
index 0000000000..517315f103
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xmlhtml/jaxp/JaxpTransformerUnitTest.java
@@ -0,0 +1,34 @@
+package com.isharkfly.xmlhtml.jaxp;
+
+import com.isharkfly.xmlhtml.jaxp.JaxpTransformer;
+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/isharkfly/xmlhtml/mustache/MustacheTransformerUnitTest.java b/xml-2/src/test/java/com/isharkfly/xmlhtml/mustache/MustacheTransformerUnitTest.java
new file mode 100644
index 0000000000..795bd14b98
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xmlhtml/mustache/MustacheTransformerUnitTest.java
@@ -0,0 +1,31 @@
+package com.isharkfly.xmlhtml.mustache;
+
+import com.isharkfly.xmlhtml.mustache.MustacheTransformer;
+import com.isharkfly.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/isharkfly/xmlhtml/stax/StaxTransformerUnitTest.java b/xml-2/src/test/java/com/isharkfly/xmlhtml/stax/StaxTransformerUnitTest.java
new file mode 100644
index 0000000000..8b8de029e8
--- /dev/null
+++ b/xml-2/src/test/java/com/isharkfly/xmlhtml/stax/StaxTransformerUnitTest.java
@@ -0,0 +1,31 @@
+package com.isharkfly.xmlhtml.stax;
+
+import com.isharkfly.xmlhtml.stax.StaxTransformer;
+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