Merge branch 'master' into pr/899-tim

This commit is contained in:
slavisa-baeldung 2016-12-21 07:30:11 +01:00
commit 469164caa2
18 changed files with 419 additions and 27 deletions

5
jaxb/book.xml Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<book id="1">
<title>Book1</title>
<date>2016-12-16T17:28:49.718Z</date>
</book>

View File

@ -23,7 +23,13 @@
<dependency>
<groupId>com.sun.istack</groupId>
<artifactId>istack-commons-runtime</artifactId>
<version>${istack.version}</version>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
@ -43,7 +49,18 @@
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
<build>
@ -60,7 +77,7 @@
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>${lifecycle-mapping.version}</version>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
@ -158,16 +175,14 @@
<!-- jaxb -->
<jaxb.version>2.2.11</jaxb.version>
<istack.version>3.0.2</istack.version>
<!-- logging -->
<org.slf4j.version>1.7.21</org.slf4j.version>
<logback.version>1.1.7</logback.version>
<!-- maven plugins -->
<lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<jaxb2-maven-plugin.version>2.3</jaxb2-maven-plugin.version>
<junit.version>4.12</junit.version>
</properties>
</project>
</project>

5
jaxb/sample_book.xml Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<book id="1">
<title>Book1</title>
<date>2016-12-16T17:28:49.718Z</date>
</book>

View File

@ -8,6 +8,10 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
@XmlRootElement(name = "book")
@XmlType(propOrder = { "id", "name", "date" })
public class Book {
@ -53,6 +57,17 @@ public class Book {
@Override
public String toString() {
return "Book [id=" + id + ", name=" + name + ", author=" + author + ", date=" + date + "]";
return ToStringBuilder.reflectionToString(this);
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import java.util.TimeZone;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@ -16,7 +17,8 @@ public class Main {
book.setId(1L);
book.setName("Book1");
book.setAuthor("Author1");
book.setDate(new Date());
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
book.setDate(new Date(1481909329718L));
JAXBContext context = JAXBContext.newInstance(Book.class);
Marshaller marshaller = context.createMarshaller();

View File

@ -0,0 +1,54 @@
package com.baeldung.jaxb.test;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import java.util.TimeZone;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import com.baeldung.jaxb.Book;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class JaxbTest {
Book book;
JAXBContext context;
@Before
public void before() throws JAXBException {
book = new Book();
book.setId(1L);
book.setName("Book1");
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
book.setDate(new Date(1481909329718L));
context = JAXBContext.newInstance(Book.class);
}
@Test
public void marshal() throws JAXBException, IOException {
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(book, new File("./book.xml"));
String sampleBookXML = FileUtils.readFileToString(new File("./sample_book.xml"), "UTF-8");
String marshallerBookXML = FileUtils.readFileToString(new File("./book.xml"), "UTF-8");
Assert.assertEquals(sampleBookXML, marshallerBookXML);
}
@Test
public void unMashal() throws JAXBException, IOException {
Unmarshaller unmarshaller = context.createUnmarshaller();
Book unMarshallerbook = (Book) unmarshaller.unmarshal(new FileReader("./book.xml"));
Assert.assertEquals(book, unMarshallerbook);
}
}

View File

@ -126,6 +126,7 @@
<module>spring-rest-docs</module>
<module>spring-rest</module>
<module>spring-security-basic-auth</module>
<module>spring-security-core</module>
<module>spring-security-custom-permission</module>
<module>spring-security-mvc-custom</module>
<module>spring-security-mvc-digest-auth</module>
@ -155,4 +156,4 @@
<module>pdf</module>
</modules>
</project>
</project>

View File

@ -215,9 +215,57 @@
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<jackson.version>2.8.5</jackson.version>
<jackson-coreutils.version>1.8</jackson-coreutils.version>
@ -255,6 +303,7 @@
<junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties>
</project>

View File

@ -15,7 +15,7 @@ import static io.restassured.RestAssured.get;
import com.github.tomakehurst.wiremock.WireMockServer;
public class RestAssured2Test {
public class RestAssured2IntegrationTest {
private WireMockServer wireMockServer = new WireMockServer();
private static final String EVENTS_PATH = "/odds";
@ -41,7 +41,7 @@ public class RestAssured2Test {
private static String getJson() {
return Util.inputStreamToString(new RestAssured2Test().getClass()
return Util.inputStreamToString(new RestAssured2IntegrationTest().getClass()
.getResourceAsStream("/odds.json"));
}

View File

@ -20,7 +20,7 @@ import com.github.fge.jsonschema.cfg.ValidationConfiguration;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import com.github.tomakehurst.wiremock.WireMockServer;
public class RestAssuredTest {
public class RestAssuredIntegrationTest {
private WireMockServer wireMockServer = new WireMockServer();
private static final String EVENTS_PATH = "/events?id=390";
@ -99,7 +99,7 @@ public class RestAssuredTest {
}
private static String getEventJson() {
return Util.inputStreamToString(RestAssuredTest.class
return Util.inputStreamToString(RestAssuredIntegrationTest.class
.getResourceAsStream("/event_0.json"));
}

View File

@ -15,7 +15,7 @@ import static io.restassured.RestAssured.get;
import com.github.tomakehurst.wiremock.WireMockServer;
public class RestAssuredXML2Test {
public class RestAssuredXML2IntegrationTest {
private WireMockServer wireMockServer = new WireMockServer();
private static final String EVENTS_PATH = "/teachers";
@ -42,7 +42,7 @@ public class RestAssuredXML2Test {
private static String getXml() {
return Util
.inputStreamToString(new RestAssuredXML2Test().getClass().getResourceAsStream("/teachers.xml"));
.inputStreamToString(new RestAssuredXML2IntegrationTest().getClass().getResourceAsStream("/teachers.xml"));
}
@After

View File

@ -25,7 +25,7 @@ import com.github.fge.jsonschema.SchemaVersion;
import com.github.fge.jsonschema.cfg.ValidationConfiguration;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import com.github.tomakehurst.wiremock.WireMockServer;
public class RestAssuredXMLTest {
public class RestAssuredXMLIntegrationTest {
private WireMockServer wireMockServer = new WireMockServer();
private static final String EVENTS_PATH = "/employees";
private static final String APPLICATION_XML = "application/xml";
@ -88,7 +88,7 @@ public class RestAssuredXMLTest {
private static String getXml() {
return Util
.inputStreamToString(new RestAssuredXMLTest().getClass().getResourceAsStream("/employees.xml"));
.inputStreamToString(new RestAssuredXMLIntegrationTest().getClass().getResourceAsStream("/employees.xml"));
}
@After

View File

@ -56,6 +56,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
@ -77,4 +87,42 @@
</snapshots>
</repository>
</repositories>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -22,6 +22,7 @@
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties>
<repositories>
@ -68,6 +69,17 @@
<mainClass>com.baeldung.samples.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
@ -128,5 +140,40 @@
<version>${spring.integration.version}</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -202,6 +202,7 @@
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<testFailureIgnore>true</testFailureIgnore>
<systemPropertyVariables>
@ -209,6 +210,27 @@
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>${cargo-maven2-plugin.version}</version>
<configuration>
<wait>true</wait>
<container>
<containerId>jetty8x</containerId>
<type>embedded</type>
<systemProperties>
<!-- <provPersistenceTarget>cargo</provPersistenceTarget> -->
</systemProperties>
</container>
<configuration>
<properties>
<cargo.servlet.port>8082</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
@ -245,6 +267,63 @@
</plugins>
</build>
</profile>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
<includes>
<include>**/*LiveTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>false</wait>
</configuration>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>

View File

@ -65,9 +65,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
@ -96,5 +97,41 @@
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -30,7 +30,7 @@ public class RegistrationController {
private static final Logger logger = LoggerFactory.getLogger(RegistrationController.class);
@Autowired
AuthenticationManager authenticationManager;
private AuthenticationManager authenticationManager;
/**
* For demo purposes this need only be a GET request method
@ -49,8 +49,6 @@ public class RegistrationController {
String username = "user";
String password = "password";
String view = "registrationSuccess";
if (requestQualifiesForManualAuthentication()) {
try {
authenticate(username, password, request, response);
@ -58,12 +56,12 @@ public class RegistrationController {
} catch (BadCredentialsException bce) {
logger.debug("Authentication failure: bad credentials");
bce.printStackTrace();
view = "systemError"; // assume a low-level error, since the registration
return "systemError"; // assume a low-level error, since the registration
// form would have been successfully validated
}
}
return view;
return "registrationSuccess";
}
private boolean requestQualifiesForManualAuthentication() {

View File

@ -150,6 +150,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<systemPropertyVariables>
@ -184,6 +185,42 @@
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>live</id>
<build>