Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	pom.xml
#	spring-cloud/spring-cloud-bootstrap/config/src/main/java/com/baeldung/spring/cloud/bootstrap/config/SecurityConfig.java
#	spring-cloud/spring-cloud-bootstrap/discovery/src/main/java/com/baeldung/spring/cloud/bootstrap/discovery/SecurityConfig.java
#	spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/SecurityConfig.java
#	spring-cloud/spring-cloud-bootstrap/resource/src/main/java/com/baeldung/spring/cloud/bootstrap/resource/SecurityConfig.java
This commit is contained in:
tschiman
2016-11-05 10:06:53 -06:00
685 changed files with 9025 additions and 3364 deletions
+3 -1
View File
@@ -11,6 +11,7 @@
</parent>
<properties>
<cxf.version>3.1.6</cxf.version>
<surefire.version>2.19.1</surefire.version>
</properties>
<build>
<plugins>
@@ -26,7 +27,7 @@
<version>2.19.1</version>
<configuration>
<excludes>
<exclude>**/StudentTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -44,4 +45,5 @@
<version>${cxf.version}</version>
</dependency>
</dependencies>
</project>
@@ -2,20 +2,16 @@ package com.baeldung.cxf.introduction;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;
import com.baeldung.cxf.introduction.Baeldung;
import com.baeldung.cxf.introduction.Student;
import com.baeldung.cxf.introduction.StudentImpl;
import org.junit.Before;
import org.junit.Test;
public class StudentTest {
public class StudentLiveTest {
private static QName SERVICE_NAME = new QName("http://introduction.cxf.baeldung.com/", "Baeldung");
private static QName PORT_NAME = new QName("http://introduction.cxf.baeldung.com/", "BaeldungPort");
@@ -25,7 +21,7 @@ public class StudentTest {
{
service = Service.create(SERVICE_NAME);
String endpointAddress = "http://localhost:8080/baeldung";
final String endpointAddress = "http://localhost:8080/baeldung";
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
}
@@ -37,28 +33,28 @@ public class StudentTest {
@Test
public void whenUsingHelloMethod_thenCorrect() {
String endpointResponse = baeldungProxy.hello("Baeldung");
String localResponse = baeldungImpl.hello("Baeldung");
final String endpointResponse = baeldungProxy.hello("Baeldung");
final String localResponse = baeldungImpl.hello("Baeldung");
assertEquals(localResponse, endpointResponse);
}
@Test
public void whenUsingHelloStudentMethod_thenCorrect() {
Student student = new StudentImpl("John Doe");
String endpointResponse = baeldungProxy.helloStudent(student);
String localResponse = baeldungImpl.helloStudent(student);
final Student student = new StudentImpl("John Doe");
final String endpointResponse = baeldungProxy.helloStudent(student);
final String localResponse = baeldungImpl.helloStudent(student);
assertEquals(localResponse, endpointResponse);
}
@Test
public void usingGetStudentsMethod_thenCorrect() {
Student student1 = new StudentImpl("Adam");
final Student student1 = new StudentImpl("Adam");
baeldungProxy.helloStudent(student1);
Student student2 = new StudentImpl("Eve");
final Student student2 = new StudentImpl("Eve");
baeldungProxy.helloStudent(student2);
Map<Integer, Student> students = baeldungProxy.getStudents();
final Map<Integer, Student> students = baeldungProxy.getStudents();
assertEquals("Adam", students.get(1).getName());
assertEquals("Eve", students.get(2).getName());
}
+2 -1
View File
@@ -13,6 +13,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cxf.version>3.1.7</cxf.version>
<httpclient.version>4.5.2</httpclient.version>
<surefire.version>2.19.1</surefire.version>
</properties>
<build>
<plugins>
@@ -28,7 +29,7 @@
<version>2.19.1</version>
<configuration>
<excludes>
<exclude>**/ServiceTest</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -3,6 +3,7 @@ package com.baeldung.cxf.jaxrs.implementation;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;
@@ -10,7 +11,7 @@ import java.util.List;
public class Course {
private int id;
private String name;
private List<Student> students;
private List<Student> students = new ArrayList<>();
public int getId() {
return id;
@@ -35,31 +36,51 @@ public class Course {
public void setStudents(List<Student> students) {
this.students = students;
}
@GET
@Path("{studentOrder}")
public Student getStudent(@PathParam("studentOrder")int studentOrder) {
return students.get(studentOrder);
@Path("{studentId}")
public Student getStudent(@PathParam("studentId") int studentId) {
return findById(studentId);
}
@POST
public Response postStudent(Student student) {
if (students == null) {
students = new ArrayList<>();
public Response createStudent(Student student) {
for (Student element : students) {
if (element.getId() == student.getId()) {
return Response.status(Response.Status.CONFLICT).build();
}
}
students.add(student);
return Response.ok(student).build();
}
@DELETE
@Path("{studentOrder}")
public Response deleteStudent(@PathParam("studentOrder") int studentOrder) {
Student student = students.get(studentOrder);
if (student != null) {
students.remove(studentOrder);
return Response.ok().build();
} else {
return Response.notModified().build();
@Path("{studentId}")
public Response deleteStudent(@PathParam("studentId") int studentId) {
Student student = findById(studentId);
if (student == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
students.remove(student);
return Response.ok().build();
}
private Student findById(int id) {
for (Student student : students) {
if (student.getId() == id) {
return student;
}
}
return null;
}
@Override
public int hashCode() {
return id + name.hashCode();
}
@Override
public boolean equals(Object obj) {
return (obj instanceof Course) && (id == ((Course) obj).getId()) && (name.equals(((Course) obj).getName()));
}
}
@@ -9,7 +9,7 @@ import java.util.Map;
@Path("baeldung")
@Produces("text/xml")
public class Baeldung {
public class CourseRepository {
private Map<Integer, Course> courses = new HashMap<>();
{
@@ -37,26 +37,36 @@ public class Baeldung {
}
@GET
@Path("courses/{courseOrder}")
public Course getCourse(@PathParam("courseOrder") int courseOrder) {
return courses.get(courseOrder);
@Path("courses/{courseId}")
public Course getCourse(@PathParam("courseId") int courseId) {
return findById(courseId);
}
@PUT
@Path("courses/{courseOrder}")
public Response putCourse(@PathParam("courseOrder") int courseOrder, Course course) {
Course existingCourse = courses.get(courseOrder);
if (existingCourse == null || existingCourse.getId() != course.getId() || !(existingCourse.getName().equals(course.getName()))) {
courses.put(courseOrder, course);
return Response.ok().build();
@Path("courses/{courseId}")
public Response updateCourse(@PathParam("courseId") int courseId, Course course) {
Course existingCourse = findById(courseId);
if (existingCourse == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
return Response.notModified().build();
if (existingCourse.equals(course)) {
return Response.notModified().build();
}
courses.put(courseId, course);
return Response.ok().build();
}
@Path("courses/{courseOrder}/students")
public Course pathToStudent(@PathParam("courseOrder") int courseOrder) {
return courses.get(courseOrder);
@Path("courses/{courseId}/students")
public Course pathToStudent(@PathParam("courseId") int courseId) {
return findById(courseId);
}
}
private Course findById(int id) {
for (Map.Entry<Integer, Course> course : courses.entrySet()) {
if (course.getKey() == id) {
return course.getValue();
}
}
return null;
}
}
@@ -7,8 +7,8 @@ import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
public class RestfulServer {
public static void main(String args[]) throws Exception {
JAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBean();
factoryBean.setResourceClasses(Baeldung.class);
factoryBean.setResourceProvider(new SingletonResourceProvider(new Baeldung()));
factoryBean.setResourceClasses(CourseRepository.class);
factoryBean.setResourceProvider(new SingletonResourceProvider(new CourseRepository()));
factoryBean.setAddress("http://localhost:8080/");
Server server = factoryBean.create();
@@ -18,4 +18,4 @@ public class RestfulServer {
server.destroy();
System.exit(0);
}
}
}
@@ -22,4 +22,14 @@ public class Student {
public void setName(String name) {
this.name = name;
}
@Override
public int hashCode() {
return id + name.hashCode();
}
@Override
public boolean equals(Object obj) {
return (obj instanceof Student) && (id == ((Student) obj).getId()) && (name.equals(((Student) obj).getName()));
}
}
@@ -0,0 +1,4 @@
<Course>
<id>2</id>
<name>Apache CXF Support for RESTful</name>
</Course>
@@ -0,0 +1,4 @@
<Student>
<id>2</id>
<name>Student B</name>
</Student>
@@ -0,0 +1,4 @@
<Course>
<id>1</id>
<name>REST with Spring</name>
</Course>
@@ -0,0 +1,130 @@
package com.baeldung.cxf.jaxrs.implementation;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.xml.bind.JAXB;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class ServiceLiveTest {
private static final String BASE_URL = "http://localhost:8080/baeldung/courses/";
private static CloseableHttpClient client;
@BeforeClass
public static void createClient() {
client = HttpClients.createDefault();
}
@AfterClass
public static void closeClient() throws IOException {
client.close();
}
@Test
public void whenUpdateNonExistentCourse_thenReceiveNotFoundResponse() throws IOException {
final HttpPut httpPut = new HttpPut(BASE_URL + "3");
final InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("non_existent_course.xml");
httpPut.setEntity(new InputStreamEntity(resourceStream));
httpPut.setHeader("Content-Type", "text/xml");
final HttpResponse response = client.execute(httpPut);
assertEquals(404, response.getStatusLine().getStatusCode());
}
@Test
public void whenUpdateUnchangedCourse_thenReceiveNotModifiedResponse() throws IOException {
final HttpPut httpPut = new HttpPut(BASE_URL + "1");
final InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("unchanged_course.xml");
httpPut.setEntity(new InputStreamEntity(resourceStream));
httpPut.setHeader("Content-Type", "text/xml");
final HttpResponse response = client.execute(httpPut);
assertEquals(304, response.getStatusLine().getStatusCode());
}
@Test
public void whenUpdateValidCourse_thenReceiveOKResponse() throws IOException {
final HttpPut httpPut = new HttpPut(BASE_URL + "2");
final InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("changed_course.xml");
httpPut.setEntity(new InputStreamEntity(resourceStream));
httpPut.setHeader("Content-Type", "text/xml");
final HttpResponse response = client.execute(httpPut);
assertEquals(200, response.getStatusLine().getStatusCode());
final Course course = getCourse(2);
assertEquals(2, course.getId());
assertEquals("Apache CXF Support for RESTful", course.getName());
}
@Test
public void whenCreateConflictStudent_thenReceiveConflictResponse() throws IOException {
final HttpPost httpPost = new HttpPost(BASE_URL + "1/students");
final InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("conflict_student.xml");
httpPost.setEntity(new InputStreamEntity(resourceStream));
httpPost.setHeader("Content-Type", "text/xml");
final HttpResponse response = client.execute(httpPost);
assertEquals(409, response.getStatusLine().getStatusCode());
}
@Test
public void whenCreateValidStudent_thenReceiveOKResponse() throws IOException {
final HttpPost httpPost = new HttpPost(BASE_URL + "2/students");
final InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("created_student.xml");
httpPost.setEntity(new InputStreamEntity(resourceStream));
httpPost.setHeader("Content-Type", "text/xml");
final HttpResponse response = client.execute(httpPost);
assertEquals(200, response.getStatusLine().getStatusCode());
final Student student = getStudent(2, 3);
assertEquals(3, student.getId());
assertEquals("Student C", student.getName());
}
@Test
public void whenDeleteInvalidStudent_thenReceiveNotFoundResponse() throws IOException {
final HttpDelete httpDelete = new HttpDelete(BASE_URL + "1/students/3");
final HttpResponse response = client.execute(httpDelete);
assertEquals(404, response.getStatusLine().getStatusCode());
}
@Test
public void whenDeleteValidStudent_thenReceiveOKResponse() throws IOException {
final HttpDelete httpDelete = new HttpDelete(BASE_URL + "1/students/1");
final HttpResponse response = client.execute(httpDelete);
assertEquals(200, response.getStatusLine().getStatusCode());
final Course course = getCourse(1);
assertEquals(1, course.getStudents().size());
assertEquals(2, course.getStudents().get(0).getId());
assertEquals("Student B", course.getStudents().get(0).getName());
}
private Course getCourse(int courseOrder) throws IOException {
final URL url = new URL(BASE_URL + courseOrder);
final InputStream input = url.openStream();
return JAXB.unmarshal(new InputStreamReader(input), Course.class);
}
private Student getStudent(int courseOrder, int studentOrder) throws IOException {
final URL url = new URL(BASE_URL + courseOrder + "/students/" + studentOrder);
final InputStream input = url.openStream();
return JAXB.unmarshal(new InputStreamReader(input), Student.class);
}
}
@@ -1,89 +0,0 @@
package com.baeldung.cxf.jaxrs.implementation;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import javax.xml.bind.JAXB;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import static org.junit.Assert.assertEquals;
public class ServiceTest {
private static final String BASE_URL = "http://localhost:8080/baeldung/courses/";
private static CloseableHttpClient client;
@BeforeClass
public static void createClient() {
client = HttpClients.createDefault();
}
@AfterClass
public static void closeClient() throws IOException {
client.close();
}
@Test
public void whenPutCourse_thenCorrect() throws IOException {
HttpPut httpPut = new HttpPut(BASE_URL + "3");
InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("course.xml");
httpPut.setEntity(new InputStreamEntity(resourceStream));
httpPut.setHeader("Content-Type", "text/xml");
HttpResponse response = client.execute(httpPut);
assertEquals(200, response.getStatusLine().getStatusCode());
Course course = getCourse(3);
assertEquals(3, course.getId());
assertEquals("Apache CXF Support for RESTful", course.getName());
}
@Test
public void whenPostStudent_thenCorrect() throws IOException {
HttpPost httpPost = new HttpPost(BASE_URL + "2/students");
InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("student.xml");
httpPost.setEntity(new InputStreamEntity(resourceStream));
httpPost.setHeader("Content-Type", "text/xml");
HttpResponse response = client.execute(httpPost);
assertEquals(200, response.getStatusLine().getStatusCode());
Student student = getStudent(2, 0);
assertEquals(3, student.getId());
assertEquals("Student C", student.getName());
}
@Test
public void whenDeleteStudent_thenCorrect() throws IOException {
HttpDelete httpDelete = new HttpDelete(BASE_URL + "1/students/0");
HttpResponse response = client.execute(httpDelete);
assertEquals(200, response.getStatusLine().getStatusCode());
Course course = getCourse(1);
assertEquals(1, course.getStudents().size());
assertEquals(2, course.getStudents().get(0).getId());
assertEquals("Student B", course.getStudents().get(0).getName());
}
private Course getCourse(int courseOrder) throws IOException {
URL url = new URL(BASE_URL + courseOrder);
InputStream input = url.openStream();
return JAXB.unmarshal(new InputStreamReader(input), Course.class);
}
private Student getStudent(int courseOrder, int studentOrder) throws IOException {
URL url = new URL(BASE_URL + courseOrder + "/students/" + studentOrder);
InputStream input = url.openStream();
return JAXB.unmarshal(new InputStreamReader(input), Student.class);
}
}
+2 -2
View File
@@ -51,7 +51,7 @@
<version>${surefire.version}</version>
<configuration>
<excludes>
<exclude>StudentTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -60,7 +60,7 @@
<profiles>
<profile>
<id>integration</id>
<id>live</id>
<build>
<plugins>
<plugin>
@@ -6,7 +6,7 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class StudentTest {
public class StudentLiveTest {
private ApplicationContext context = new AnnotationConfigApplicationContext(ClientConfiguration.class);
private Baeldung baeldungProxy = (Baeldung) context.getBean("client");
+46 -1
View File
@@ -97,6 +97,14 @@
<version>8.0.2</version>
</dependency>
<dependency>
<groupId>org.dbdoclet</groupId>
<artifactId>herold</artifactId>
<version>6.1.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/test/resources/jars/herold.jar</systemPath>
</dependency>
<dependency>
<groupId>net.sf.jtidy</groupId>
<artifactId>jtidy</artifactId>
@@ -132,7 +140,8 @@
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -141,6 +150,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>**/*ManualTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
<exclude>**/*LiveTest.java</exclude>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<!-- persistence -->
<hibernate.version>4.3.11.Final</hibernate.version>
@@ -25,7 +25,7 @@ import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.tidy.Tidy;
public class ApacheFOPConvertHTMLTest {
public class ApacheFOPConvertHTMLIntegrationTest {
private String inputFile = "src/test/resources/input.html";
private String style = "src/test/resources/xhtml2fo.xsl";
private String style1 = "src/test/resources/docbook-xsl/fo/docbook.xsl";
@@ -30,7 +30,7 @@ import org.dbdoclet.trafo.script.Script;
import org.junit.Test;
import org.w3c.dom.Document;
public class ApacheFOPHeroldTest {
public class ApacheFOPHeroldLiveTest {
private String[] inputUrls = {// @formatter:off
"http://www.baeldung.com/2011/10/20/bootstraping-a-web-application-with-spring-3-1-and-java-based-configuration-part-1/",
"http://www.baeldung.com/2011/10/25/building-a-restful-web-service-with-spring-3-1-and-java-based-configuration-part-2/",
+52
View File
@@ -45,8 +45,60 @@
</dependencies>
<build>
<plugins>
<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>
<spring.version>4.3.1.RELEASE</spring.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties>
</project>
@@ -10,7 +10,7 @@ import org.junit.Test;
import com.baeldung.interceptor.AuditedInterceptor;
import com.baeldung.service.SuperService;
public class TestInterceptor {
public class InterceptorIntegrationTest {
Weld weld;
WeldContainer container;
@@ -16,19 +16,23 @@ import com.baeldung.spring.service.SpringSuperService;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = { AppConfig.class })
public class TestSpringInterceptor {
public class SpringInterceptorIntegrationTest {
@Autowired
SpringSuperService springSuperService;
@Autowired
private List<String> accumulator;
//
@Test
public void givenService_whenServiceAndAspectExecuted_thenOk() {
String code = "123456";
String result = springSuperService.getInfoFromService(code);
Assert.assertThat(accumulator.size(), is(2));
Assert.assertThat(accumulator.get(0), is("Call to getInfoFromService"));
Assert.assertThat(accumulator.get(1), is("Method called successfully: getInfoFromService"));
}
}

Some files were not shown because too many files have changed in this diff Show More