diff --git a/core-java-8/pom.xml b/core-java-8/pom.xml
index f99d85f564..8c9bb36f7d 100644
--- a/core-java-8/pom.xml
+++ b/core-java-8/pom.xml
@@ -63,6 +63,12 @@
test
+
+ org.assertj
+ assertj-core
+ 3.4.1
+
+
org.mockito
mockito-core
diff --git a/core-java-8/src/main/java/com/baeldung/date_migration/NewApi.java b/core-java-8/src/main/java/com/baeldung/date_migration/NewApi.java
deleted file mode 100644
index 0abf7f7864..0000000000
--- a/core-java-8/src/main/java/com/baeldung/date_migration/NewApi.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.baeldung.date_migration;
-
-import java.text.ParseException;
-import java.time.*;
-import java.time.format.DateTimeFormatter;
-import java.time.temporal.ChronoUnit;
-
-public class NewApi {
- public void currentTime() {
- ZonedDateTime now = ZonedDateTime.now();
- }
-
- public void specificTime() {
- LocalDate birthDay = LocalDate.of(1990, Month.DECEMBER, 15);
- }
-
- public void extractMonth() {
- Month month = LocalDateTime.now().getMonth();
- }
-
- public void subtractTime() {
- LocalDateTime fiveHoursBefore = LocalDateTime.now().minusHours(5);
- }
-
- public void alterField() {
- LocalDateTime inJune = LocalDateTime.now().withMonth(Month.JUNE.getValue());
- }
-
- public void truncate() {
- LocalTime truncated = LocalTime.now().truncatedTo(ChronoUnit.HOURS);
- }
-
- public void convertTimeZone() {
- ZonedDateTime centralEastern = LocalDateTime.now().atZone(ZoneId.of("CET"));
- }
-
- public void getTimeSpan() {
- LocalDateTime now = LocalDateTime.now();
- LocalDateTime hourLater = LocalDateTime.now().plusHours(1);
- Duration span = Duration.between(now, hourLater);
- }
-
- public void formatAndParse() throws ParseException {
- LocalDate now = LocalDate.now();
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- String formattedDate = now.format(formatter);
- LocalDate parsedDate = LocalDate.parse(formattedDate, formatter);
- }
-
- public void daysInMonth() {
- int daysInMonth = YearMonth.of(1990, 2).lengthOfMonth();
- }
-
-}
diff --git a/core-java-8/src/main/java/com/baeldung/date_migration/OldApi.java b/core-java-8/src/main/java/com/baeldung/date_migration/OldApi.java
deleted file mode 100644
index de4edf99e9..0000000000
--- a/core-java-8/src/main/java/com/baeldung/date_migration/OldApi.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.baeldung.date_migration;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
-
-public class OldApi {
- public void currentTime() {
- Date now = new Date();
- }
-
- public void specificTime () {
- Date birthDay = new GregorianCalendar(1990, Calendar.DECEMBER, 15).getTime();
- }
-
- public void extractMonth() {
- int month = new GregorianCalendar().get(Calendar.MONTH);
- }
-
- public void subtractTime() {
- GregorianCalendar calendar = new GregorianCalendar();
- calendar.add(Calendar.HOUR_OF_DAY, -5);
- Date fiveHoursBefore = calendar.getTime();
- }
-
- public void alterField() {
- GregorianCalendar calendar = new GregorianCalendar();
- calendar.set(Calendar.MONTH, Calendar.JUNE);
- Date inJune = calendar.getTime();
- }
-
- public void truncate() {
- Calendar now = Calendar.getInstance();
- now.set(Calendar.MINUTE, 0);
- now.set(Calendar.SECOND, 0);
- now.set(Calendar.MILLISECOND, 0);
- Date truncated = now.getTime();
- }
-
- public void convertTimeZone() {
- GregorianCalendar calendar = new GregorianCalendar();
- calendar.setTimeZone(TimeZone.getTimeZone("CET"));
- Date centralEastern = calendar.getTime();
- }
-
- public void getTimeSpan() {
- GregorianCalendar calendar = new GregorianCalendar();
- Date now = new Date();
- calendar.add(Calendar.HOUR, 1);
- Date hourLater = calendar.getTime();
- long elapsed = hourLater.getTime() - now.getTime();
- }
-
- public void formatAndParse() throws ParseException {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Date now = new Date();
- String formattedDate = dateFormat.format(now);
- Date parsedDate = dateFormat.parse(formattedDate);
- }
-
- public void daysInMonth() {
- Calendar calendar = new GregorianCalendar(1990, Calendar.FEBRUARY, 20);
- int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
- }
-}
diff --git a/core-java-8/src/main/java/com/baeldung/date_migration/Conversion.java b/core-java-8/src/test/java/com/baeldung/dateapi/ConversionExample.java
similarity index 91%
rename from core-java-8/src/main/java/com/baeldung/date_migration/Conversion.java
rename to core-java-8/src/test/java/com/baeldung/dateapi/ConversionExample.java
index c672b7ee44..a543c80eaf 100644
--- a/core-java-8/src/main/java/com/baeldung/date_migration/Conversion.java
+++ b/core-java-8/src/test/java/com/baeldung/dateapi/ConversionExample.java
@@ -1,4 +1,4 @@
-package com.baeldung.date_migration;
+package com.baeldung.dateapi;
import java.time.Instant;
import java.time.ZoneId;
@@ -7,7 +7,7 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
-public class Conversion {
+public class ConversionExample {
public static void main(String[] args) {
Instant instantFromCalendar = GregorianCalendar.getInstance().toInstant();
ZonedDateTime zonedDateTimeFromCalendar = new GregorianCalendar().toZonedDateTime();
diff --git a/core-java-8/src/test/java/com/baeldung/dateapi/JavaUtilTimeTest.java b/core-java-8/src/test/java/com/baeldung/dateapi/JavaUtilTimeTest.java
new file mode 100644
index 0000000000..4bce40c2d9
--- /dev/null
+++ b/core-java-8/src/test/java/com/baeldung/dateapi/JavaUtilTimeTest.java
@@ -0,0 +1,89 @@
+package com.baeldung.dateapi;
+
+import org.junit.Test;
+
+import java.text.ParseException;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.Month;
+import java.time.YearMonth;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JavaUtilTimeTest {
+
+ @Test
+ public void currentTime() {
+ final LocalDate now = LocalDate.now();
+
+ System.out.println(now);
+ // there is not much to test here
+ }
+
+ @Test
+ public void specificTime() {
+ LocalDate birthDay = LocalDate.of(1990, Month.DECEMBER, 15);
+
+ System.out.println(birthDay);
+ // there is not much to test here
+ }
+
+ @Test
+ public void extractMonth() {
+ Month month = LocalDate.of(1990, Month.DECEMBER, 15).getMonth();
+
+ assertThat(month).isEqualTo(Month.DECEMBER);
+ }
+
+ @Test
+ public void subtractTime() {
+ LocalDateTime fiveHoursBefore = LocalDateTime.of(1990, Month.DECEMBER, 15, 15, 0).minusHours(5);
+
+ assertThat(fiveHoursBefore.getHour()).isEqualTo(10);
+ }
+
+ @Test
+ public void alterField() {
+ LocalDateTime inJune = LocalDateTime.of(1990, Month.DECEMBER, 15, 15, 0).with(Month.JUNE);
+
+ assertThat(inJune.getMonth()).isEqualTo(Month.JUNE);
+ }
+
+ @Test
+ public void truncate() {
+ LocalTime truncated = LocalTime.of(15, 12, 34).truncatedTo(ChronoUnit.HOURS);
+
+ assertThat(truncated).isEqualTo(LocalTime.of(15, 0, 0));
+ }
+
+ @Test
+ public void getTimeSpan() {
+ LocalDateTime now = LocalDateTime.now();
+ LocalDateTime hourLater = now.plusHours(1);
+ Duration span = Duration.between(now, hourLater);
+
+ assertThat(span).isEqualTo(Duration.ofHours(1));
+ }
+
+ @Test
+ public void formatAndParse() throws ParseException {
+ LocalDate someDate = LocalDate.of(2016, 12, 7);
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ String formattedDate = someDate.format(formatter);
+ LocalDate parsedDate = LocalDate.parse(formattedDate, formatter);
+
+ assertThat(formattedDate).isEqualTo("2016-12-07");
+ assertThat(parsedDate).isEqualTo(someDate);
+ }
+
+ @Test
+ public void daysInMonth() {
+ int daysInMonth = YearMonth.of(1990, 2).lengthOfMonth();
+
+ assertThat(daysInMonth).isEqualTo(28);
+ }
+}
diff --git a/httpclient/README.md b/httpclient/README.md
index e06c57da71..a848edfea6 100644
--- a/httpclient/README.md
+++ b/httpclient/README.md
@@ -1,7 +1,9 @@
=========
-
## HttpClient 4.x Cookbooks and Examples
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
### Relevant Articles:
diff --git a/jackson/README.md b/jackson/README.md
index 53b9c7c31d..68765de686 100644
--- a/jackson/README.md
+++ b/jackson/README.md
@@ -2,6 +2,9 @@
## Jackson Cookbooks and Examples
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
### Relevant Articles:
- [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array)
diff --git a/mock-comparisons/pom.xml b/mock-comparisons/pom.xml
index 97e24c61cd..c5424d262d 100644
--- a/mock-comparisons/pom.xml
+++ b/mock-comparisons/pom.xml
@@ -12,6 +12,8 @@
1.10.19
3.4
1.24
+
+ UTF-8
3.3
diff --git a/raml/README.MD b/raml/README.MD
new file mode 100644
index 0000000000..2a87b46021
--- /dev/null
+++ b/raml/README.MD
@@ -0,0 +1,2 @@
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
diff --git a/rest-testing/README.md b/rest-testing/README.md
index db7f0c8a86..54a2e98dda 100644
--- a/rest-testing/README.md
+++ b/rest-testing/README.md
@@ -2,6 +2,8 @@
## REST Testing and Examples
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
- [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/)
diff --git a/spring-all/README.md b/spring-all/README.md
index 977b8b7357..47c947a414 100644
--- a/spring-all/README.md
+++ b/spring-all/README.md
@@ -4,6 +4,8 @@
This project is used to replicate Spring Exceptions only.
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant articles:
- [Properties with Spring](http://www.baeldung.com/2012/02/06/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage
diff --git a/spring-boot/README.MD b/spring-boot/README.MD
new file mode 100644
index 0000000000..2a87b46021
--- /dev/null
+++ b/spring-boot/README.MD
@@ -0,0 +1,2 @@
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md
index d9be83113b..7dc439206b 100644
--- a/spring-data-rest/README.md
+++ b/spring-data-rest/README.md
@@ -1,3 +1,6 @@
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
# About this project
This project contains examples from the [Introduction to Spring Data REST](http://www.baeldung.com/spring-data-rest-intro) article from Baeldung.
diff --git a/spring-katharsis/README.md b/spring-katharsis/README.md
index ec0141f41a..cf2a001760 100644
--- a/spring-katharsis/README.md
+++ b/spring-katharsis/README.md
@@ -2,5 +2,8 @@
## Java Web Application
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
### Relevant Articles:
- [JSON API in a Java Web Application](http://www.baeldung.com/json-api-java-spring-web-app)
diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md
index e5264b0370..951d80033e 100644
--- a/spring-mvc-java/README.md
+++ b/spring-mvc-java/README.md
@@ -2,6 +2,8 @@
## Spring MVC with Java Configuration Example Project
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
- [Spring Bean Annotations](http://www.baeldung.com/spring-bean-annotations)
diff --git a/spring-mvc-no-xml/README.md b/spring-mvc-no-xml/README.md
index 5ffe2385b5..208cb35f78 100644
--- a/spring-mvc-no-xml/README.md
+++ b/spring-mvc-no-xml/README.md
@@ -2,6 +2,8 @@
## Spring MVC with NO XML Configuration Example Project
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
--
\ No newline at end of file
+-
diff --git a/spring-mvc-xml/README.md b/spring-mvc-xml/README.md
index 2409ec8174..ce823a9682 100644
--- a/spring-mvc-xml/README.md
+++ b/spring-mvc-xml/README.md
@@ -1,5 +1,8 @@
=========
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
## Spring MVC with XML Configuration Example Project
- access a sample jsp page at: `http://localhost:8080/spring-mvc-xml/sample.html`
diff --git a/spring-rest-docs/README.MD b/spring-rest-docs/README.MD
new file mode 100644
index 0000000000..2a87b46021
--- /dev/null
+++ b/spring-rest-docs/README.MD
@@ -0,0 +1,2 @@
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
diff --git a/spring-rest/README.md b/spring-rest/README.md
index 9d373962c4..7d993b38b8 100644
--- a/spring-rest/README.md
+++ b/spring-rest/README.md
@@ -2,6 +2,8 @@
## Spring REST Example Project
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
- [Spring @RequestMapping](http://www.baeldung.com/spring-requestmapping)
diff --git a/spring-scurity-custom-permission/README.MD b/spring-scurity-custom-permission/README.MD
new file mode 100644
index 0000000000..8fb14fa522
--- /dev/null
+++ b/spring-scurity-custom-permission/README.MD
@@ -0,0 +1,2 @@
+###The Course
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
diff --git a/spring-security-basic-auth/README.md b/spring-security-basic-auth/README.md
index 95e45ae519..f3c29e1777 100644
--- a/spring-security-basic-auth/README.md
+++ b/spring-security-basic-auth/README.md
@@ -2,6 +2,8 @@
## Spring Security with Basic Authentication Example Project
+###The Course
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Article:
- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
@@ -9,4 +11,4 @@
### Notes
-- the project includes both views as well as a REST layer
\ No newline at end of file
+- the project includes both views as well as a REST layer
diff --git a/spring-security-client/README.MD b/spring-security-client/README.MD
new file mode 100644
index 0000000000..2a87b46021
--- /dev/null
+++ b/spring-security-client/README.MD
@@ -0,0 +1,2 @@
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
diff --git a/spring-security-mvc-custom/README.md b/spring-security-mvc-custom/README.md
index 17f32e4a2f..cbf5fc6a97 100644
--- a/spring-security-mvc-custom/README.md
+++ b/spring-security-mvc-custom/README.md
@@ -2,6 +2,8 @@
## Spring Security Login Example Project
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
- [Spring Security Remember Me](http://www.baeldung.com/spring-security-remember-me)
diff --git a/spring-security-mvc-digest-auth/README.md b/spring-security-mvc-digest-auth/README.md
index 3b93a84505..21835266bf 100644
--- a/spring-security-mvc-digest-auth/README.md
+++ b/spring-security-mvc-digest-auth/README.md
@@ -2,6 +2,8 @@
## Spring Security with Digest Authentication Example Project
+###The Course
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Article:
- [Spring Security Digest Authentication](http://www.baeldung.com/spring-security-digest-authentication)
diff --git a/spring-security-mvc-ldap/README.md b/spring-security-mvc-ldap/README.md
index 686f611f99..1eb3b75405 100644
--- a/spring-security-mvc-ldap/README.md
+++ b/spring-security-mvc-ldap/README.md
@@ -1,6 +1,8 @@
## Spring Security with LDAP Example Project
+###The Course
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Article:
- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
diff --git a/spring-security-mvc-login/README.md b/spring-security-mvc-login/README.md
index 256078f4b6..448c25d27b 100644
--- a/spring-security-mvc-login/README.md
+++ b/spring-security-mvc-login/README.md
@@ -2,11 +2,13 @@
## Spring Security Login Example Project
+###The Course
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Articles:
- [Spring Security Form Login](http://www.baeldung.com/spring-security-login)
- [Spring Security Logout](http://www.baeldung.com/spring-security-logout)
-- [Spring Security Expressions – hasRole Example](http://www.baeldung.com/spring-security-expressions-basic)
+- [Spring Security Expressions – hasRole Example](http://www.baeldung.com/spring-security-expressions-basic)
### Build the Project
diff --git a/spring-security-mvc-persisted-remember-me/README.md b/spring-security-mvc-persisted-remember-me/README.md
index df83fd3d77..0d5f4f5f0e 100644
--- a/spring-security-mvc-persisted-remember-me/README.md
+++ b/spring-security-mvc-persisted-remember-me/README.md
@@ -2,6 +2,8 @@
## Spring Security Persisted Remember Me Example Project
+###The Course
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Articles:
- [Spring Security Persisted Remember Me](http://www.baeldung.com/spring-security-persistent-remember-me)
diff --git a/spring-security-mvc-session/README.md b/spring-security-mvc-session/README.md
index 0df728688a..28f216c130 100644
--- a/spring-security-mvc-session/README.md
+++ b/spring-security-mvc-session/README.md
@@ -2,9 +2,11 @@
## Spring Security Login Example Project
+###The Course
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Articles:
-- [HttpSessionListener Example – Monitoring](http://www.baeldung.com/httpsessionlistener_with_metrics)
+- [HttpSessionListener Example – Monitoring](http://www.baeldung.com/httpsessionlistener_with_metrics)
- [Spring Security Session Management](http://www.baeldung.com/spring-security-session)
diff --git a/spring-security-rest-basic-auth/README.md b/spring-security-rest-basic-auth/README.md
index 723bcebbdd..9621773d91 100644
--- a/spring-security-rest-basic-auth/README.md
+++ b/spring-security-rest-basic-auth/README.md
@@ -2,6 +2,8 @@
## REST API with Basic Authentication - Example Project
+###The Course
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Articles:
- [RestTemplate with Basic Authentication in Spring](http://www.baeldung.com/2012/04/16/how-to-use-resttemplate-with-basic-authentication-in-spring-3-1)
diff --git a/spring-security-rest-custom/README.md b/spring-security-rest-custom/README.md
index f19af32d41..38dc638e8d 100644
--- a/spring-security-rest-custom/README.md
+++ b/spring-security-rest-custom/README.md
@@ -2,6 +2,9 @@
## Spring Security for REST Example Project
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
### Relevant Articles:
- [Spring Security Authentication Provider](http://www.baeldung.com/spring-security-authentication-provider)
- [Retrieve User Information in Spring Security](http://www.baeldung.com/get-user-in-spring-security)
diff --git a/spring-security-rest-digest-auth/README.md b/spring-security-rest-digest-auth/README.md
index 06e847edad..4fdc934fe5 100644
--- a/spring-security-rest-digest-auth/README.md
+++ b/spring-security-rest-digest-auth/README.md
@@ -2,6 +2,8 @@
## REST API with Digest Authentication - Example Project
+###The Course
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Articles:
- [RestTemplate with Digest Authentication](http://www.baeldung.com/resttemplate-digest-authentication)
diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md
index 72e8636df1..947d32e87c 100644
--- a/spring-security-rest-full/README.md
+++ b/spring-security-rest-full/README.md
@@ -2,8 +2,10 @@
## REST Example Project with Spring Security
-### The Course
- The "REST With Spring" Classes: http://bit.ly/restwithspring
+### Courses
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Articles:
- [Spring Security Expressions - hasRole Example](http://www.baeldung.com/spring-security-expressions-basic)
diff --git a/spring-security-rest/README.md b/spring-security-rest/README.md
index 290cd491e0..87f14a9047 100644
--- a/spring-security-rest/README.md
+++ b/spring-security-rest/README.md
@@ -2,6 +2,10 @@
## Spring Security for REST Example Project
+### Courses
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
+The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
### Relevant Articles:
- [Spring REST Service Security](http://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/)
diff --git a/xml/pom.xml b/xml/pom.xml
index fc158901e6..9d88bd75eb 100644
--- a/xml/pom.xml
+++ b/xml/pom.xml
@@ -1,139 +1,117 @@
- 4.0.0
- com.baeldung
- xml
- 0.1-SNAPSHOT
+ 4.0.0
+ com.baeldung
+ xml
+ 0.1-SNAPSHOT
- xml
+ xml
-
-
+
+
+
+ dom4j
+ dom4j
+ 1.6.1
+
+
+ jaxen
+ jaxen
+ 1.1.6
+
-
- com.google.guava
- guava
- ${guava.version}
-
-
- commons-io
- commons-io
- 2.4
-
+
+ org.jdom
+ jdom2
+ 2.0.6
+
-
- org.apache.commons
- commons-collections4
- 4.0
-
+
+ xerces
+ xercesImpl
+ 2.9.1
+
-
- org.apache.commons
- commons-lang3
- ${commons-lang3.version}
-
-
-
-
+
+
+ commons-io
+ commons-io
+ 2.4
+
-
- junit
- junit
- ${junit.version}
- test
-
+
+ org.apache.commons
+ commons-collections4
+ 4.0
+
-
- org.hamcrest
- hamcrest-core
- ${org.hamcrest.version}
- test
-
-
- org.hamcrest
- hamcrest-library
- ${org.hamcrest.version}
- test
-
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
-
- org.mockito
- mockito-core
- ${mockito.version}
- test
-
-
+
-
- xml
-
-
- src/main/resources
- true
-
-
+
+ junit
+ junit
+ ${junit.version}
+ test
+
-
+
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
-
+
+ xml
+
+
+ src/main/resources
+ true
+
+
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
+
-
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ 1.8
+ 1.8
+
+
-
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
-
-
- 4.3.11.Final
- 5.1.38
+
-
- 2.7.2
+
-
- 1.7.13
- 1.1.3
+
-
- 5.1.3.Final
+
+ 19.0
+ 3.4
-
- 19.0
- 3.4
+
+ 4.12
-
- 1.3
- 4.12
- 1.10.19
+
+ 3.5.1
+ 2.6
+ 2.19.1
+ 2.7
+ 1.4.18
- 4.4.1
- 4.5
-
- 2.9.0
-
-
- 3.5.1
- 2.6
- 2.19.1
- 2.7
- 1.4.18
-
-
+
diff --git a/xml/src/main/java/com/baeldung/xml/DefaultParser.java b/xml/src/main/java/com/baeldung/xml/DefaultParser.java
index 89326f45c9..1f2a7418fb 100644
--- a/xml/src/main/java/com/baeldung/xml/DefaultParser.java
+++ b/xml/src/main/java/com/baeldung/xml/DefaultParser.java
@@ -39,7 +39,7 @@ public class DefaultParser {
XPath xPath = XPathFactory.newInstance().newXPath();
- String expression = "/Tutorials/Tutorial";
+ String expression = "/tutorials/tutorial";
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
@@ -60,7 +60,7 @@ public class DefaultParser {
XPath xPath = XPathFactory.newInstance().newXPath();
- String expression = "/Tutorials/Tutorial[@tutId=" + "'" + id + "'" + "]";
+ String expression = "/tutorials/tutorial[@tutId=" + "'" + id + "'" + "]";
node = (Node) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODE);
@@ -83,7 +83,7 @@ public class DefaultParser {
XPath xPath = XPathFactory.newInstance().newXPath();
- String expression = "//Tutorial[descendant::title[text()=" + "'" + name + "'" + "]]";
+ String expression = "//tutorial[descendant::title[text()=" + "'" + name + "'" + "]]";
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
@@ -107,7 +107,7 @@ public class DefaultParser {
XPath xPath = XPathFactory.newInstance().newXPath();
- String expression = "//Tutorial[number(translate(date, '/', '')) > " + date + "]";
+ String expression = "//tutorial[number(translate(date, '/', '')) > " + date + "]";
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
@@ -151,7 +151,7 @@ public class DefaultParser {
}
});
- String expression = "/bdn:Tutorials/bdn:Tutorial";
+ String expression = "/bdn:tutorials/bdn:tutorial";
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
diff --git a/xml/src/main/java/com/baeldung/xml/Dom4JParser.java b/xml/src/main/java/com/baeldung/xml/Dom4JParser.java
new file mode 100644
index 0000000000..d9058ba236
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/Dom4JParser.java
@@ -0,0 +1,131 @@
+package com.baeldung.xml;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Node;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+
+public class Dom4JParser {
+
+ private File file;
+
+ public Dom4JParser(File file) {
+ this.file = file;
+ }
+
+ public Element getRootElement() {
+ try {
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(file);
+ return document.getRootElement();
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public List getFirstElementList() {
+ try {
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(file);
+ return document.getRootElement().elements();
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public Node getNodeById(String id) {
+ try {
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(file);
+ List elements = document.selectNodes("//*[@tutId='" + id + "']");
+ return elements.get(0);
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public Node getElementsListByTitle(String name) {
+ try {
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(file);
+ List elements = document
+ .selectNodes("//tutorial[descendant::title[text()=" + "'" + name + "'" + "]]");
+ return elements.get(0);
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public void generateModifiedDocument() {
+ try {
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(file);
+ List nodes = document.selectNodes("/tutorials/tutorial");
+ for (Node node : nodes) {
+ Element element = (Element) node;
+ Iterator iterator = element.elementIterator("title");
+ while (iterator.hasNext()) {
+ Element title = (Element) iterator.next();
+ title.setText(title.getText() + " updated");
+ }
+ }
+ XMLWriter writer = new XMLWriter(new FileWriter(new File("src/test/resources/example_updated.xml")));
+ writer.write(document);
+ writer.close();
+ } catch (DocumentException e) {
+ e.printStackTrace();
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public void generateNewDocument() {
+ try {
+ Document document = DocumentHelper.createDocument();
+ Element root = document.addElement("XMLTutorials");
+ Element tutorialElement = root.addElement("tutorial").addAttribute("tutId", "01");
+ tutorialElement.addAttribute("type", "xml");
+
+ tutorialElement.addElement("title").addText("XML with Dom4J");
+
+ tutorialElement.addElement("description").addText("XML handling with Dom4J");
+
+ tutorialElement.addElement("date").addText("14/06/2016");
+
+ tutorialElement.addElement("author").addText("Dom4J tech writer");
+
+ OutputFormat format = OutputFormat.createPrettyPrint();
+ XMLWriter writer = new XMLWriter(new FileWriter(new File("src/test/resources/example_new.xml")), format);
+ writer.write(document);
+ writer.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+}
diff --git a/xml/src/main/java/com/baeldung/xml/JDomParser.java b/xml/src/main/java/com/baeldung/xml/JDomParser.java
new file mode 100644
index 0000000000..08676b44f8
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/JDomParser.java
@@ -0,0 +1,62 @@
+package com.baeldung.xml;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.JDOMException;
+import org.jdom2.filter.Filters;
+import org.jdom2.input.SAXBuilder;
+import org.jdom2.xpath.XPathExpression;
+import org.jdom2.xpath.XPathFactory;
+
+
+public class JDomParser {
+
+ private File file;
+
+ public JDomParser(File file) {
+ this.file = file;
+ }
+
+ public List getAllTitles() {
+ try {
+ SAXBuilder builder = new SAXBuilder();
+ Document doc = builder.build(this.getFile());
+ Element tutorials = doc.getRootElement();
+ List titles = tutorials.getChildren("tutorial");
+ return titles;
+ } catch (JDOMException | IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public Element getNodeById(String id) {
+ try {
+ SAXBuilder builder = new SAXBuilder();
+ Document document = (Document) builder.build(file);
+ String filter = "//*[@tutId='" + id + "']";
+ XPathFactory xFactory = XPathFactory.instance();
+ XPathExpression expr = xFactory.compile(filter, Filters.element());
+ List node = expr.evaluate(document);
+
+ return node.get(0);
+ } catch (JDOMException | IOException e ) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+}
diff --git a/xml/src/main/java/com/baeldung/xml/JaxbParser.java b/xml/src/main/java/com/baeldung/xml/JaxbParser.java
new file mode 100644
index 0000000000..9c06ec5fba
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/JaxbParser.java
@@ -0,0 +1,69 @@
+package com.baeldung.xml;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Date;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import com.baeldung.xml.binding.Tutorial;
+import com.baeldung.xml.binding.Tutorials;
+
+public class JaxbParser {
+
+ private File file;
+
+ public JaxbParser(File file) {
+ this.file = file;
+ }
+
+ public Tutorials getFullDocument() {
+ try {
+ JAXBContext jaxbContext = JAXBContext.newInstance(Tutorials.class);
+ Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
+ Tutorials tutorials = (Tutorials) jaxbUnmarshaller.unmarshal(this.getFile());
+ return tutorials;
+ } catch (JAXBException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public void createNewDocument() {
+ Tutorials tutorials = new Tutorials();
+ tutorials.setTutorial(new ArrayList());
+ Tutorial tut = new Tutorial();
+ tut.setTutId("01");
+ tut.setType("XML");
+ tut.setTitle("XML with Jaxb");
+ tut.setDescription("XML Binding with Jaxb");
+ tut.setDate(new Date());
+ tut.setAuthor("Jaxb author");
+ tutorials.getTutorial().add(tut);
+
+ try {
+ JAXBContext jaxbContext = JAXBContext.newInstance(Tutorials.class);
+ Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
+
+ jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+
+ jaxbMarshaller.marshal(tutorials, file);
+
+ } catch (JAXBException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+}
diff --git a/xml/src/main/java/com/baeldung/xml/JaxenDemo.java b/xml/src/main/java/com/baeldung/xml/JaxenDemo.java
new file mode 100644
index 0000000000..0c2dca0573
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/JaxenDemo.java
@@ -0,0 +1,57 @@
+package com.baeldung.xml;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jaxen.JaxenException;
+import org.jaxen.XPath;
+import org.jaxen.dom.DOMXPath;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+public class JaxenDemo {
+
+ private File file;
+
+ public JaxenDemo(File file) {
+ this.file = file;
+ }
+
+ public List getAllTutorial(){
+ try {
+ FileInputStream fileIS = new FileInputStream(this.getFile());
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+
+ DocumentBuilder builder = builderFactory.newDocumentBuilder();
+
+ Document xmlDocument = builder.parse(fileIS);
+
+ String expression = "/tutorials/tutorial";
+
+ XPath path = new DOMXPath(expression);
+ List result = path.selectNodes(xmlDocument);
+ return result;
+
+ } catch (SAXException | IOException | ParserConfigurationException | JaxenException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+
+}
diff --git a/xml/src/main/java/com/baeldung/xml/StaxParser.java b/xml/src/main/java/com/baeldung/xml/StaxParser.java
new file mode 100644
index 0000000000..6f83e022f8
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/StaxParser.java
@@ -0,0 +1,120 @@
+package com.baeldung.xml;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.Characters;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import com.baeldung.xml.model.Tutorial;
+
+public class StaxParser {
+
+ private File file;
+
+ public StaxParser(File file) {
+ this.file = file;
+ }
+
+ public List getAllTutorial() {
+ boolean bTitle = false;
+ boolean bDescription = false;
+ boolean bDate = false;
+ boolean bAuthor = false;
+ List tutorials = new ArrayList();
+ try {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ XMLEventReader eventReader = factory.createXMLEventReader(new FileReader(this.getFile()));
+ Tutorial current = null;
+ while (eventReader.hasNext()) {
+ XMLEvent event = eventReader.nextEvent();
+ switch (event.getEventType()) {
+ case XMLStreamConstants.START_ELEMENT:
+ StartElement startElement = event.asStartElement();
+ String qName = startElement.getName().getLocalPart();
+ if (qName.equalsIgnoreCase("tutorial")) {
+ current = new Tutorial();
+ Iterator attributes = startElement.getAttributes();
+ while (attributes.hasNext()) {
+ Attribute currentAt = attributes.next();
+ if (currentAt.getName().toString().equalsIgnoreCase("tutId")) {
+ current.setTutId(currentAt.getValue());
+ } else if (currentAt.getName().toString().equalsIgnoreCase("type")) {
+ current.setType(currentAt.getValue());
+ }
+ }
+ } else if (qName.equalsIgnoreCase("title")) {
+ bTitle = true;
+ } else if (qName.equalsIgnoreCase("description")) {
+ bDescription = true;
+ } else if (qName.equalsIgnoreCase("date")) {
+ bDate = true;
+ } else if (qName.equalsIgnoreCase("author")) {
+ bAuthor = true;
+ }
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ Characters characters = event.asCharacters();
+ if (bTitle) {
+ if (current != null) {
+ current.setTitle(characters.getData());
+ }
+ bTitle = false;
+ }
+ if (bDescription) {
+ if (current != null) {
+ current.setDescription(characters.getData());
+ }
+ bDescription = false;
+ }
+ if (bDate) {
+ if (current != null) {
+ current.setDate(characters.getData());
+ }
+ bDate = false;
+ }
+ if (bAuthor) {
+ if (current != null) {
+ current.setAuthor(characters.getData());
+ }
+ bAuthor = false;
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ EndElement endElement = event.asEndElement();
+ if (endElement.getName().getLocalPart().equalsIgnoreCase("tutorial")) {
+ if(current != null){
+ tutorials.add(current);
+ }
+ }
+ break;
+ }
+ }
+
+ } catch (FileNotFoundException | XMLStreamException e) {
+ e.printStackTrace();
+ }
+
+ return tutorials;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+}
diff --git a/xml/src/main/java/com/baeldung/xml/binding/Tutorial.java b/xml/src/main/java/com/baeldung/xml/binding/Tutorial.java
new file mode 100644
index 0000000000..c4668a9f77
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/binding/Tutorial.java
@@ -0,0 +1,61 @@
+package com.baeldung.xml.binding;
+
+import java.util.Date;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+
+public class Tutorial {
+
+ private String tutId;
+ private String type;
+ private String title;
+ private String description;
+ private Date date;
+ private String author;
+
+
+ public String getTutId() {
+ return tutId;
+ }
+
+ @XmlAttribute
+ public void setTutId(String tutId) {
+ this.tutId = tutId;
+ }
+ public String getType() {
+ return type;
+ }
+ @XmlAttribute
+ public void setType(String type) {
+ this.type = type;
+ }
+ public String getTitle() {
+ return title;
+ }
+ @XmlElement
+ public void setTitle(String title) {
+ this.title = title;
+ }
+ public String getDescription() {
+ return description;
+ }
+ @XmlElement
+ public void setDescription(String description) {
+ this.description = description;
+ }
+ public Date getDate() {
+ return date;
+ }
+ @XmlElement
+ public void setDate(Date date) {
+ this.date = date;
+ }
+ public String getAuthor() {
+ return author;
+ }
+ @XmlElement
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+}
diff --git a/xml/src/main/java/com/baeldung/xml/binding/Tutorials.java b/xml/src/main/java/com/baeldung/xml/binding/Tutorials.java
new file mode 100644
index 0000000000..ab6669c0ad
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/binding/Tutorials.java
@@ -0,0 +1,23 @@
+package com.baeldung.xml.binding;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class Tutorials {
+
+ private List tutorial;
+
+ public List getTutorial() {
+ return tutorial;
+ }
+
+ @XmlElement
+ public void setTutorial(List tutorial) {
+ this.tutorial = tutorial;
+ }
+
+
+}
diff --git a/xml/src/main/java/com/baeldung/xml/model/Tutorial.java b/xml/src/main/java/com/baeldung/xml/model/Tutorial.java
new file mode 100644
index 0000000000..40a3f858cf
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/model/Tutorial.java
@@ -0,0 +1,49 @@
+package com.baeldung.xml.model;
+
+public class Tutorial {
+
+ private String tutId;
+ private String type;
+ private String title;
+ private String description;
+ private String date;
+ private String author;
+
+
+ public String getTutId() {
+ return tutId;
+ }
+ public void setTutId(String tutId) {
+ this.tutId = tutId;
+ }
+ public String getType() {
+ return type;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+ public String getTitle() {
+ return title;
+ }
+ public void setTitle(String title) {
+ this.title = title;
+ }
+ public String getDescription() {
+ return description;
+ }
+ public void setDescription(String description) {
+ this.description = description;
+ }
+ public String getDate() {
+ return date;
+ }
+ public void setDate(String date) {
+ this.date = date;
+ }
+ public String getAuthor() {
+ return author;
+ }
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+}
diff --git a/xml/src/test/java/com/baeldung/xml/DefaultParserTest.java b/xml/src/test/java/com/baeldung/xml/DefaultParserTest.java
index 451917a5da..7408e41b92 100644
--- a/xml/src/test/java/com/baeldung/xml/DefaultParserTest.java
+++ b/xml/src/test/java/com/baeldung/xml/DefaultParserTest.java
@@ -1,23 +1,22 @@
package com.baeldung.xml;
-import static org.junit.Assert.*;
-
-import java.io.File;
-
import org.junit.Test;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-/**
- * Unit test for simple App.
- */
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
public class DefaultParserTest {
- final String fileName = "src/test/resources/example.xml";
+ private final String fileName = "src/test/resources/example.xml";
- final String fileNameSpace = "src/test/resources/example_namespace.xml";
+ private final String fileNameSpace = "src/test/resources/example_namespace.xml";
- DefaultParser parser;
+ private DefaultParser parser;
@Test
public void getFirstLevelNodeListTest() {
@@ -29,11 +28,11 @@ public class DefaultParserTest {
}
@Test
- public void getNodeListByTitle() {
+ public void getNodeListByTitleTest() {
parser = new DefaultParser(new File(fileName));
NodeList list = parser.getNodeListByTitle("XML");
- for (int i = 0; null != list && i < list.getLength(); i++) {
+ for (int i = 0; i < list.getLength(); i++) {
Node nod = list.item(i);
assertEquals("java", nod.getAttributes().getNamedItem("type").getTextContent());
assertEquals("02", nod.getAttributes().getNamedItem("tutId").getTextContent());
@@ -47,7 +46,7 @@ public class DefaultParserTest {
}
@Test
- public void getNodeById() {
+ public void getNodeByIdTest() {
parser = new DefaultParser(new File(fileName));
Node node = parser.getNodeById("03");
@@ -56,10 +55,10 @@ public class DefaultParserTest {
}
@Test
- public void getNodeListByDate(){
+ public void getNodeListByDateTest(){
parser = new DefaultParser(new File(fileName));
NodeList list = parser.getNodeListByTitle("04022016");
- for (int i = 0; null != list && i < list.getLength(); i++) {
+ for (int i = 0; i < list.getLength(); i++) {
Node nod = list.item(i);
assertEquals("java", nod.getAttributes().getNamedItem("type").getTextContent());
assertEquals("04", nod.getAttributes().getNamedItem("tutId").getTextContent());
@@ -73,7 +72,7 @@ public class DefaultParserTest {
}
@Test
- public void getNodeListWithNamespace(){
+ public void getNodeListWithNamespaceTest(){
parser = new DefaultParser(new File(fileNameSpace));
NodeList list = parser.getAllTutorials();
assertNotNull(list);
diff --git a/xml/src/test/java/com/baeldung/xml/Dom4JParserTest.java b/xml/src/test/java/com/baeldung/xml/Dom4JParserTest.java
new file mode 100644
index 0000000000..77e5fcdcda
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xml/Dom4JParserTest.java
@@ -0,0 +1,88 @@
+package com.baeldung.xml;
+
+import org.dom4j.Element;
+import org.dom4j.Node;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class Dom4JParserTest {
+
+ private static final String FILE_NAME = "src/test/resources/example.xml";
+
+ private Dom4JParser parser;
+
+ @Test
+ public void getRootElementTest() {
+ parser = new Dom4JParser(new File(FILE_NAME));
+ Element root = parser.getRootElement();
+
+ assertNotNull(root);
+ assertTrue(root.elements().size() == 4);
+ }
+
+ @Test
+ public void getFirstElementListTest() {
+ parser = new Dom4JParser(new File(FILE_NAME));
+ List firstList = parser.getFirstElementList();
+
+ assertNotNull(firstList);
+ assertTrue(firstList.size() == 4);
+ assertTrue(firstList.get(0).attributeValue("type").equals("java"));
+ }
+
+ @Test
+ public void getElementByIdTest() {
+ parser = new Dom4JParser(new File(FILE_NAME));
+ Node element = parser.getNodeById("03");
+
+ String type = element.valueOf("@type");
+ assertEquals("android", type);
+ }
+
+ @Test
+ public void getElementsListByTitleTest() {
+ parser = new Dom4JParser(new File(FILE_NAME));
+ Node element = parser.getElementsListByTitle("XML");
+
+ assertEquals("java", element.valueOf("@type"));
+ assertEquals("02", element.valueOf("@tutId"));
+ assertEquals("XML", element.selectSingleNode("title").getText());
+ assertEquals("title", element.selectSingleNode("title").getName());
+ }
+
+ @Test
+ public void generateModifiedDocumentTest() {
+ parser = new Dom4JParser(new File(FILE_NAME));
+ parser.generateModifiedDocument();
+
+ File generatedFile = new File("src/test/resources/example_updated.xml");
+ assertTrue(generatedFile.exists());
+
+ parser.setFile(generatedFile);
+ Node element = parser.getNodeById("02");
+
+ assertEquals("XML updated", element.selectSingleNode("title").getText());
+
+ }
+
+ @Test
+ public void generateNewDocumentTest() {
+ parser = new Dom4JParser(new File(FILE_NAME));
+ parser.generateNewDocument();
+
+ File newFile = new File("src/test/resources/example_new.xml");
+ assertTrue(newFile.exists());
+
+ parser.setFile(newFile);
+ Node element = parser.getNodeById("01");
+
+ assertEquals("XML with Dom4J", element.selectSingleNode("title").getText());
+
+ }
+}
diff --git a/xml/src/test/java/com/baeldung/xml/JDomParserTest.java b/xml/src/test/java/com/baeldung/xml/JDomParserTest.java
new file mode 100644
index 0000000000..e4034c48f0
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xml/JDomParserTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.xml;
+
+import org.jdom2.Element;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class JDomParserTest {
+
+ private final String fileName = "src/test/resources/example.xml";
+
+ private JDomParser parser;
+
+ @Test
+ public void getFirstElementListTest() {
+ parser = new JDomParser(new File(fileName));
+ List firstList = parser.getAllTitles();
+
+ assertNotNull(firstList);
+ assertTrue(firstList.size() == 4);
+ assertTrue(firstList.get(0).getAttributeValue("type").equals("java"));
+ }
+
+ @Test
+ public void getElementByIdTest() {
+ parser = new JDomParser(new File(fileName));
+ Element el = parser.getNodeById("03");
+
+ String type = el.getAttributeValue("type");
+ assertEquals("android", type);
+ }
+
+}
diff --git a/xml/src/test/java/com/baeldung/xml/JaxbParserTest.java b/xml/src/test/java/com/baeldung/xml/JaxbParserTest.java
new file mode 100644
index 0000000000..6e1a201b59
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xml/JaxbParserTest.java
@@ -0,0 +1,43 @@
+package com.baeldung.xml;
+
+import com.baeldung.xml.binding.Tutorials;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class JaxbParserTest {
+
+
+ private final String fileName = "src/test/resources/example.xml";
+
+ private JaxbParser parser;
+
+ @Test
+ public void getFullDocumentTest(){
+ parser = new JaxbParser(new File(fileName));
+ Tutorials tutorials = parser.getFullDocument();
+
+ assertNotNull(tutorials);
+ assertTrue(tutorials.getTutorial().size() == 4);
+ assertTrue(tutorials.getTutorial().get(0).getType().equalsIgnoreCase("java"));
+ }
+
+ @Test
+ public void createNewDocumentTest(){
+ File newFile = new File("src/test/resources/example_new.xml");
+ parser = new JaxbParser(newFile);
+ parser.createNewDocument();
+
+
+ assertTrue(newFile.exists());
+
+ Tutorials tutorials = parser.getFullDocument();
+
+ assertNotNull(tutorials);
+ assertTrue(tutorials.getTutorial().size() == 1);
+ assertTrue(tutorials.getTutorial().get(0).getTitle().equalsIgnoreCase("XML with Jaxb"));
+ }
+}
diff --git a/xml/src/test/java/com/baeldung/xml/JaxenDemoTest.java b/xml/src/test/java/com/baeldung/xml/JaxenDemoTest.java
new file mode 100644
index 0000000000..8a88484f11
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xml/JaxenDemoTest.java
@@ -0,0 +1,25 @@
+package com.baeldung.xml;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.util.List;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class JaxenDemoTest {
+
+ private final String fileName = "src/test/resources/example.xml";
+
+ private JaxenDemo jaxenDemo;
+
+ @Test
+ public void getFirstLevelNodeListTest() {
+ jaxenDemo = new JaxenDemo(new File(fileName));
+ List> list = jaxenDemo.getAllTutorial();
+
+ assertNotNull(list);
+ assertTrue(list.size() == 4);
+ }
+}
diff --git a/xml/src/test/java/com/baeldung/xml/StaxParserTest.java b/xml/src/test/java/com/baeldung/xml/StaxParserTest.java
new file mode 100644
index 0000000000..d1080c88ac
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xml/StaxParserTest.java
@@ -0,0 +1,27 @@
+package com.baeldung.xml;
+
+import com.baeldung.xml.model.Tutorial;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.List;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class StaxParserTest {
+
+ private final String fileName = "src/test/resources/example.xml";
+
+ private StaxParser parser;
+
+ @Test
+ public void getAllTutorialsTest(){
+ parser = new StaxParser(new File(fileName));
+ List tutorials = parser.getAllTutorial();
+
+ assertNotNull(tutorials);
+ assertTrue(tutorials.size() == 4);
+ assertTrue(tutorials.get(0).getType().equalsIgnoreCase("java"));
+ }
+}
diff --git a/xml/src/test/resources/example.xml b/xml/src/test/resources/example.xml
index d546dd137b..0993b6240a 100644
--- a/xml/src/test/resources/example.xml
+++ b/xml/src/test/resources/example.xml
@@ -1,24 +1,24 @@
-
-
+
+
Guava
Introduction to Guava
04/04/2016
GuavaAuthor
-
-
+
+
XML
Introduction to XPath
04/05/2016
XMLAuthor
-
-
+
+
Android
Introduction to Android
04/03/2016
AndroidAuthor
-
-
+
+
Spring
Introduction to Spring
04/02/2016
@@ -28,5 +28,5 @@
-
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/xml/src/test/resources/example_namespace.xml b/xml/src/test/resources/example_namespace.xml
index 26131302ea..f1a880951a 100644
--- a/xml/src/test/resources/example_namespace.xml
+++ b/xml/src/test/resources/example_namespace.xml
@@ -1,24 +1,24 @@
-
-
+
+
Guava
Introduction to Guava
04/04/2016
GuavaAuthor
-
-
+
+
XML
Introduction to XPath
04/05/2016
XMLAuthor
-
-
+
+
Android
Introduction to Android
04/03/2016
AndroidAuthor
-
-
+
+
Spring
Introduction to Spring
04/02/2016
@@ -28,5 +28,5 @@
-
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/xml/src/test/resources/example_new.xml b/xml/src/test/resources/example_new.xml
new file mode 100644
index 0000000000..020760fdd3
--- /dev/null
+++ b/xml/src/test/resources/example_new.xml
@@ -0,0 +1,10 @@
+
+
+
+
+ XML with Dom4J
+ XML handling with Dom4J
+ 14/06/2016
+ Dom4J tech writer
+
+
diff --git a/xml/src/test/resources/example_updated.xml b/xml/src/test/resources/example_updated.xml
new file mode 100644
index 0000000000..962ca0c889
--- /dev/null
+++ b/xml/src/test/resources/example_updated.xml
@@ -0,0 +1,32 @@
+
+
+
+ Guava updated
+ Introduction to Guava
+ 04/04/2016
+ GuavaAuthor
+
+
+ XML updated
+ Introduction to XPath
+ 04/05/2016
+ XMLAuthor
+
+
+ Android updated
+ Introduction to Android
+ 04/03/2016
+ AndroidAuthor
+
+
+ Spring updated
+ Introduction to Spring
+ 04/02/2016
+ SpringAuthor
+
+
+
+
+
+
+
\ No newline at end of file