articles = result.getArticleList();
+
+ assertNotNull(articles);
+ assertEquals(3, articles.size());
+
+ SaxParserMain.BaeldungArticle articleOne = articles.get(0);
+ assertEquals("Parsing an XML File Using SAX Parser", articleOne.getTitle());
+ assertEquals("SAX Parser's Lorem ipsum...", articleOne.getContent());
+
+ SaxParserMain.BaeldungArticle articleTwo = articles.get(1);
+ assertEquals("Parsing an XML File Using DOM Parser", articleTwo.getTitle());
+ assertEquals("DOM Parser's Lorem ipsum...", articleTwo.getContent());
+
+ SaxParserMain.BaeldungArticle articleThree = articles.get(2);
+ assertEquals("Parsing an XML File Using StAX Parser", articleThree.getTitle());
+ assertEquals("StAX Parser's Lorem ipsum...", articleThree.getContent());
+ }
+}
diff --git a/xml/src/test/java/com/baeldung/xml/attribute/Dom4jProcessorUnitTest.java b/xml/src/test/java/com/baeldung/xml/attribute/Dom4jProcessorUnitTest.java
index 351b8bc437..6c4aa02700 100644
--- a/xml/src/test/java/com/baeldung/xml/attribute/Dom4jProcessorUnitTest.java
+++ b/xml/src/test/java/com/baeldung/xml/attribute/Dom4jProcessorUnitTest.java
@@ -47,7 +47,9 @@ public class Dom4jProcessorUnitTest {
String expectedXml = new String(Files.readAllBytes((Paths.get(getClass().getResource("/xml/attribute_expected.xml")
.toURI()))));
- String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+ String result = transformer
+ .modifyAttribute(attribute, oldValue, newValue)
+ .replaceAll("(?m)^[ \t]*\r?\n", "");//Delete extra spaces added by Java 11
assertThat(result).and(expectedXml)
.areSimilar();
diff --git a/xml/src/test/java/com/baeldung/xml/attribute/JooxProcessorUnitTest.java b/xml/src/test/java/com/baeldung/xml/attribute/JooxProcessorUnitTest.java
index 40d0c671e7..0fdfcfeb52 100644
--- a/xml/src/test/java/com/baeldung/xml/attribute/JooxProcessorUnitTest.java
+++ b/xml/src/test/java/com/baeldung/xml/attribute/JooxProcessorUnitTest.java
@@ -47,7 +47,9 @@ public class JooxProcessorUnitTest {
String expectedXml = new String(Files.readAllBytes((Paths.get(getClass().getResource("/xml/attribute_expected.xml")
.toURI()))));
- String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+ String result = transformer
+ .modifyAttribute(attribute, oldValue, newValue)
+ .replaceAll("(?m)^[ \t]*\r?\n", "");//Delete extra spaces added by Java 11
assertThat(result).and(expectedXml)
.areSimilar();
diff --git a/xml/src/test/java/com/baeldung/xml/jibx/CustomerIntegrationTest.java b/xml/src/test/java/com/baeldung/xml/jibx/CustomerUnitTest.java
similarity index 94%
rename from xml/src/test/java/com/baeldung/xml/jibx/CustomerIntegrationTest.java
rename to xml/src/test/java/com/baeldung/xml/jibx/CustomerUnitTest.java
index be28dfe00a..9a4b5bc14b 100644
--- a/xml/src/test/java/com/baeldung/xml/jibx/CustomerIntegrationTest.java
+++ b/xml/src/test/java/com/baeldung/xml/jibx/CustomerUnitTest.java
@@ -11,7 +11,7 @@ import java.io.InputStream;
import static junit.framework.Assert.assertEquals;
-public class CustomerIntegrationTest {
+public class CustomerUnitTest {
@Test
public void whenUnmarshalXML_ThenFieldsAreMapped() throws JiBXException, FileNotFoundException {
@@ -21,7 +21,7 @@ public class CustomerIntegrationTest {
InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
- assertEquals("Stefan Jaegar", customer.getPerson().getName());
+ assertEquals("Stefan Jaeger", customer.getPerson().getName());
assertEquals("Davos Dorf", customer.getCity());
}
diff --git a/xml/src/test/java/com/baeldung/xmlhtml/freemarker/FreemarkerTransformerUnitTest.java b/xml/src/test/java/com/baeldung/xmlhtml/freemarker/FreemarkerTransformerUnitTest.java
new file mode 100644
index 0000000000..c110f88e99
--- /dev/null
+++ b/xml/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/src/test/java/com/baeldung/xmlhtml/jaxp/JaxpTransformerUnitTest.java b/xml/src/test/java/com/baeldung/xmlhtml/jaxp/JaxpTransformerUnitTest.java
new file mode 100644
index 0000000000..02fc422ee9
--- /dev/null
+++ b/xml/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/src/test/java/com/baeldung/xmlhtml/mustache/MustacheTransformerUnitTest.java b/xml/src/test/java/com/baeldung/xmlhtml/mustache/MustacheTransformerUnitTest.java
new file mode 100644
index 0000000000..b53a23d4fb
--- /dev/null
+++ b/xml/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/src/test/java/com/baeldung/xmlhtml/stax/StaxTransformerUnitTest.java b/xml/src/test/java/com/baeldung/xmlhtml/stax/StaxTransformerUnitTest.java
new file mode 100644
index 0000000000..0c7329e899
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xmlhtml/stax/StaxTransformerUnitTest.java
@@ -0,0 +1,28 @@
+package com.baeldung.xmlhtml.stax;
+
+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 {
+
+ @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/src/test/resources/sax/baeldung.xml b/xml/src/test/resources/sax/baeldung.xml
new file mode 100644
index 0000000000..6736d5bdca
--- /dev/null
+++ b/xml/src/test/resources/sax/baeldung.xml
@@ -0,0 +1,16 @@
+
+
+
+ Parsing an XML File Using SAX Parser
+ SAX Parser's Lorem ipsum...
+
+
+ Parsing an XML File Using DOM Parser
+ DOM Parser's Lorem ipsum...
+
+
+ Parsing an XML File Using StAX Parser
+ StAX Parser's Lorem ipsum...
+
+
+
\ No newline at end of file
diff --git a/xml/src/test/resources/templates/freemarker.html b/xml/src/test/resources/templates/freemarker.html
new file mode 100644
index 0000000000..15ec7f9fff
--- /dev/null
+++ b/xml/src/test/resources/templates/freemarker.html
@@ -0,0 +1,11 @@
+
+
+
+
+${heading}
+
+
+${from}
+${content}
+
+
diff --git a/xml/src/test/resources/templates/template.mustache b/xml/src/test/resources/templates/template.mustache
new file mode 100644
index 0000000000..8c209843e1
--- /dev/null
+++ b/xml/src/test/resources/templates/template.mustache
@@ -0,0 +1,11 @@
+
+
+
+
+{{heading}}
+
+
+{{from}}
+{{content}}
+
+
diff --git a/xml/src/test/resources/xmlhtml/notification.html b/xml/src/test/resources/xmlhtml/notification.html
new file mode 100644
index 0000000000..4a0ef09c5d
--- /dev/null
+++ b/xml/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/src/test/resources/xmlhtml/notification.xml b/xml/src/test/resources/xmlhtml/notification.xml
new file mode 100644
index 0000000000..c3550d6f04
--- /dev/null
+++ b/xml/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
diff --git a/xstream/README.md b/xstream/README.md
index bf917e81fb..62996132c8 100644
--- a/xstream/README.md
+++ b/xstream/README.md
@@ -1,3 +1,7 @@
+## XStream
+
+This module contains articles about XStream
+
## Relevant Articles:
- [XStream User Guide: JSON](http://www.baeldung.com/xstream-json-processing)