Skip to content

Commit 469164c

Browse files
Merge branch 'master' into pr/899-tim
2 parents 4997091 + 8442fc3 commit 469164c

18 files changed

Lines changed: 419 additions & 27 deletions

File tree

‎jaxb/book.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<book id="1">
3+
<title>Book1</title>
4+
<date>2016-12-16T17:28:49.718Z</date>
5+
</book>

‎jaxb/pom.xml‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
<dependency>
2424
<groupId>com.sun.istack</groupId>
2525
<artifactId>istack-commons-runtime</artifactId>
26-
<version>${istack.version}</version>
26+
<version>3.0.2</version>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>commons-io</groupId>
31+
<artifactId>commons-io</artifactId>
32+
<version>2.5</version>
2733
</dependency>
2834

2935
<dependency>
@@ -43,7 +49,18 @@
4349
<artifactId>logback-core</artifactId>
4450
<version>${logback.version}</version>
4551
</dependency>
46-
52+
53+
<dependency>
54+
<groupId>junit</groupId>
55+
<artifactId>junit</artifactId>
56+
<version>${junit.version}</version>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>org.apache.commons</groupId>
61+
<artifactId>commons-lang3</artifactId>
62+
<version>3.5</version>
63+
</dependency>
4764
</dependencies>
4865

4966
<build>
@@ -60,7 +77,7 @@
6077
<plugin>
6178
<groupId>org.eclipse.m2e</groupId>
6279
<artifactId>lifecycle-mapping</artifactId>
63-
<version>${lifecycle-mapping.version}</version>
80+
<version>1.0.0</version>
6481
<configuration>
6582
<lifecycleMappingMetadata>
6683
<pluginExecutions>
@@ -158,16 +175,14 @@
158175
<!-- jaxb -->
159176
<jaxb.version>2.2.11</jaxb.version>
160177

161-
<istack.version>3.0.2</istack.version>
162-
163178
<!-- logging -->
164179
<org.slf4j.version>1.7.21</org.slf4j.version>
165180
<logback.version>1.1.7</logback.version>
166181

167182
<!-- maven plugins -->
168-
<lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
169-
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
183+
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
170184
<jaxb2-maven-plugin.version>2.3</jaxb2-maven-plugin.version>
185+
<junit.version>4.12</junit.version>
171186
</properties>
172187

173-
</project>
188+
</project>

‎jaxb/sample_book.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<book id="1">
3+
<title>Book1</title>
4+
<date>2016-12-16T17:28:49.718Z</date>
5+
</book>

‎jaxb/src/main/java/com/baeldung/jaxb/Book.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import javax.xml.bind.annotation.XmlTransient;
99
import javax.xml.bind.annotation.XmlType;
1010

11+
import org.apache.commons.lang3.builder.EqualsBuilder;
12+
import org.apache.commons.lang3.builder.HashCodeBuilder;
13+
import org.apache.commons.lang3.builder.ToStringBuilder;
14+
1115
@XmlRootElement(name = "book")
1216
@XmlType(propOrder = { "id", "name", "date" })
1317
public class Book {
@@ -53,6 +57,17 @@ public String getAuthor() {
5357

5458
@Override
5559
public String toString() {
56-
return "Book [id=" + id + ", name=" + name + ", author=" + author + ", date=" + date + "]";
60+
return ToStringBuilder.reflectionToString(this);
61+
}
62+
63+
@Override
64+
public boolean equals(Object obj) {
65+
return EqualsBuilder.reflectionEquals(this, obj);
5766
}
67+
68+
@Override
69+
public int hashCode() {
70+
return HashCodeBuilder.reflectionHashCode(this);
71+
}
72+
5873
}

‎jaxb/src/main/java/com/baeldung/jaxb/Main.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.FileReader;
55
import java.io.IOException;
66
import java.util.Date;
7+
import java.util.TimeZone;
78

89
import javax.xml.bind.JAXBContext;
910
import javax.xml.bind.JAXBException;
@@ -16,7 +17,8 @@ public static void marshal() throws JAXBException, IOException {
1617
book.setId(1L);
1718
book.setName("Book1");
1819
book.setAuthor("Author1");
19-
book.setDate(new Date());
20+
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
21+
book.setDate(new Date(1481909329718L));
2022

2123
JAXBContext context = JAXBContext.newInstance(Book.class);
2224
Marshaller marshaller = context.createMarshaller();
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.baeldung.jaxb.test;
2+
3+
import java.io.File;
4+
import java.io.FileReader;
5+
import java.io.IOException;
6+
import java.util.Date;
7+
import java.util.TimeZone;
8+
9+
import javax.xml.bind.JAXBContext;
10+
import javax.xml.bind.JAXBException;
11+
import javax.xml.bind.Marshaller;
12+
import javax.xml.bind.Unmarshaller;
13+
14+
import org.apache.commons.io.FileUtils;
15+
import org.junit.Assert;
16+
import org.junit.Before;
17+
import org.junit.FixMethodOrder;
18+
import org.junit.Test;
19+
import org.junit.runners.MethodSorters;
20+
21+
import com.baeldung.jaxb.Book;
22+
23+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
24+
public class JaxbTest {
25+
Book book;
26+
JAXBContext context;
27+
28+
@Before
29+
public void before() throws JAXBException {
30+
book = new Book();
31+
book.setId(1L);
32+
book.setName("Book1");
33+
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
34+
book.setDate(new Date(1481909329718L));
35+
context = JAXBContext.newInstance(Book.class);
36+
}
37+
38+
@Test
39+
public void marshal() throws JAXBException, IOException {
40+
Marshaller marshaller = context.createMarshaller();
41+
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
42+
marshaller.marshal(book, new File("./book.xml"));
43+
String sampleBookXML = FileUtils.readFileToString(new File("./sample_book.xml"), "UTF-8");
44+
String marshallerBookXML = FileUtils.readFileToString(new File("./book.xml"), "UTF-8");
45+
Assert.assertEquals(sampleBookXML, marshallerBookXML);
46+
}
47+
48+
@Test
49+
public void unMashal() throws JAXBException, IOException {
50+
Unmarshaller unmarshaller = context.createUnmarshaller();
51+
Book unMarshallerbook = (Book) unmarshaller.unmarshal(new FileReader("./book.xml"));
52+
Assert.assertEquals(book, unMarshallerbook);
53+
}
54+
}

‎pom.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<module>spring-rest-docs</module>
127127
<module>spring-rest</module>
128128
<module>spring-security-basic-auth</module>
129+
<module>spring-security-core</module>
129130
<module>spring-security-custom-permission</module>
130131
<module>spring-security-mvc-custom</module>
131132
<module>spring-security-mvc-digest-auth</module>
@@ -155,4 +156,4 @@
155156
<module>pdf</module>
156157
</modules>
157158

158-
</project>
159+
</project>

‎rest-assured/pom.xml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,57 @@
215215
<target>8</target>
216216
</configuration>
217217
</plugin>
218+
<plugin>
219+
<groupId>org.apache.maven.plugins</groupId>
220+
<artifactId>maven-surefire-plugin</artifactId>
221+
<version>${maven-surefire-plugin.version}</version>
222+
<configuration>
223+
<excludes>
224+
<exclude>**/*IntegrationTest.java</exclude>
225+
<exclude>**/*LiveTest.java</exclude>
226+
</excludes>
227+
</configuration>
228+
</plugin>
218229
</plugins>
219230
</build>
220231

232+
233+
<profiles>
234+
<profile>
235+
<id>integration</id>
236+
<build>
237+
<plugins>
238+
<plugin>
239+
<groupId>org.apache.maven.plugins</groupId>
240+
<artifactId>maven-surefire-plugin</artifactId>
241+
<executions>
242+
<execution>
243+
<phase>integration-test</phase>
244+
<goals>
245+
<goal>test</goal>
246+
</goals>
247+
<configuration>
248+
<excludes>
249+
<exclude>**/*LiveTest.java</exclude>
250+
</excludes>
251+
<includes>
252+
<include>**/*IntegrationTest.java</include>
253+
</includes>
254+
</configuration>
255+
</execution>
256+
</executions>
257+
<configuration>
258+
<systemPropertyVariables>
259+
<test.mime>json</test.mime>
260+
</systemPropertyVariables>
261+
</configuration>
262+
</plugin>
263+
</plugins>
264+
265+
</build>
266+
</profile>
267+
</profiles>
268+
221269
<properties>
222270
<jackson.version>2.8.5</jackson.version>
223271
<jackson-coreutils.version>1.8</jackson-coreutils.version>
@@ -255,6 +303,7 @@
255303
<junit.version>4.12</junit.version>
256304

257305
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
306+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
258307
</properties>
259308

260309
</project>

rest-assured/src/test/java/com/baeldung/restassured/RestAssured2Test.java renamed to rest-assured/src/test/java/com/baeldung/restassured/RestAssured2IntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import com.github.tomakehurst.wiremock.WireMockServer;
1717

18-
public class RestAssured2Test {
18+
public class RestAssured2IntegrationTest {
1919
private WireMockServer wireMockServer = new WireMockServer();
2020

2121
private static final String EVENTS_PATH = "/odds";
@@ -41,7 +41,7 @@ public void givenUrl_whenVerifiesOddPricesAccuratelyByStatus_thenCorrect() {
4141

4242
private static String getJson() {
4343

44-
return Util.inputStreamToString(new RestAssured2Test().getClass()
44+
return Util.inputStreamToString(new RestAssured2IntegrationTest().getClass()
4545
.getResourceAsStream("/odds.json"));
4646

4747
}

rest-assured/src/test/java/com/baeldung/restassured/RestAssuredTest.java renamed to rest-assured/src/test/java/com/baeldung/restassured/RestAssuredIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.github.fge.jsonschema.main.JsonSchemaFactory;
2121
import com.github.tomakehurst.wiremock.WireMockServer;
2222

23-
public class RestAssuredTest {
23+
public class RestAssuredIntegrationTest {
2424

2525
private WireMockServer wireMockServer = new WireMockServer();
2626
private static final String EVENTS_PATH = "/events?id=390";
@@ -99,7 +99,7 @@ public void after() throws Exception {
9999
}
100100

101101
private static String getEventJson() {
102-
return Util.inputStreamToString(RestAssuredTest.class
102+
return Util.inputStreamToString(RestAssuredIntegrationTest.class
103103
.getResourceAsStream("/event_0.json"));
104104
}
105105

0 commit comments

Comments
 (0)