From bc9b170e89c1fa927eabc83fe268f35ddc88021e Mon Sep 17 00:00:00 2001 From: DOHA Date: Sun, 23 Oct 2016 12:19:55 +0200 Subject: [PATCH] configure test profiles --- apache-cxf/cxf-introduction/pom.xml | 65 ++++++++++- ...{StudentTest.java => StudentLiveTest.java} | 30 +++-- apache-cxf/cxf-jaxrs-implementation/pom.xml | 65 ++++++++++- ...{ServiceTest.java => ServiceLiveTest.java} | 107 +++++++++--------- apache-cxf/cxf-spring/pom.xml | 4 +- ...{StudentTest.java => StudentLiveTest.java} | 2 +- 6 files changed, 198 insertions(+), 75 deletions(-) rename apache-cxf/cxf-introduction/src/test/java/com/baeldung/cxf/introduction/{StudentTest.java => StudentLiveTest.java} (65%) rename apache-cxf/cxf-jaxrs-implementation/src/test/java/com/baeldung/cxf/jaxrs/implementation/{ServiceTest.java => ServiceLiveTest.java} (63%) rename apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/{StudentTest.java => StudentLiveTest.java} (97%) diff --git a/apache-cxf/cxf-introduction/pom.xml b/apache-cxf/cxf-introduction/pom.xml index 232a4f0089..9629dfda1b 100644 --- a/apache-cxf/cxf-introduction/pom.xml +++ b/apache-cxf/cxf-introduction/pom.xml @@ -11,6 +11,7 @@ 3.1.6 + 2.19.1 @@ -26,7 +27,7 @@ 2.19.1 - **/StudentTest.java + **/*LiveTest.java @@ -44,4 +45,66 @@ ${cxf.version} + + + + live + + + + org.codehaus.cargo + cargo-maven2-plugin + 1.4.19 + + + tomcat8x + embedded + + + + localhost + 8082 + + + + + + start-server + pre-integration-test + + start + + + + stop-server + post-integration-test + + stop + + + + + + + maven-surefire-plugin + ${surefire.version} + + + integration-test + + test + + + + none + + + + + + + + + + diff --git a/apache-cxf/cxf-introduction/src/test/java/com/baeldung/cxf/introduction/StudentTest.java b/apache-cxf/cxf-introduction/src/test/java/com/baeldung/cxf/introduction/StudentLiveTest.java similarity index 65% rename from apache-cxf/cxf-introduction/src/test/java/com/baeldung/cxf/introduction/StudentTest.java rename to apache-cxf/cxf-introduction/src/test/java/com/baeldung/cxf/introduction/StudentLiveTest.java index e1e5b60ec3..1c50fcb9b6 100644 --- a/apache-cxf/cxf-introduction/src/test/java/com/baeldung/cxf/introduction/StudentTest.java +++ b/apache-cxf/cxf-introduction/src/test/java/com/baeldung/cxf/introduction/StudentLiveTest.java @@ -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:8082/cxf-introduction/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 students = baeldungProxy.getStudents(); + + final Map students = baeldungProxy.getStudents(); assertEquals("Adam", students.get(1).getName()); assertEquals("Eve", students.get(2).getName()); } diff --git a/apache-cxf/cxf-jaxrs-implementation/pom.xml b/apache-cxf/cxf-jaxrs-implementation/pom.xml index 1f83ecf934..24dad05a0f 100644 --- a/apache-cxf/cxf-jaxrs-implementation/pom.xml +++ b/apache-cxf/cxf-jaxrs-implementation/pom.xml @@ -13,6 +13,7 @@ UTF-8 3.1.7 4.5.2 + 2.19.1 @@ -28,7 +29,7 @@ 2.19.1 - **/ServiceTest + **/*LiveTest.java @@ -51,4 +52,66 @@ ${httpclient.version} + + + + live + + + + org.codehaus.cargo + cargo-maven2-plugin + 1.4.19 + + + tomcat8x + embedded + + + + localhost + 8082 + + + + + + start-server + pre-integration-test + + start + + + + stop-server + post-integration-test + + stop + + + + + + + maven-surefire-plugin + ${surefire.version} + + + integration-test + + test + + + + none + + + + + + + + + + diff --git a/apache-cxf/cxf-jaxrs-implementation/src/test/java/com/baeldung/cxf/jaxrs/implementation/ServiceTest.java b/apache-cxf/cxf-jaxrs-implementation/src/test/java/com/baeldung/cxf/jaxrs/implementation/ServiceLiveTest.java similarity index 63% rename from apache-cxf/cxf-jaxrs-implementation/src/test/java/com/baeldung/cxf/jaxrs/implementation/ServiceTest.java rename to apache-cxf/cxf-jaxrs-implementation/src/test/java/com/baeldung/cxf/jaxrs/implementation/ServiceLiveTest.java index b8fc833194..692def81f5 100644 --- a/apache-cxf/cxf-jaxrs-implementation/src/test/java/com/baeldung/cxf/jaxrs/implementation/ServiceTest.java +++ b/apache-cxf/cxf-jaxrs-implementation/src/test/java/com/baeldung/cxf/jaxrs/implementation/ServiceLiveTest.java @@ -1,5 +1,14 @@ 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; @@ -11,119 +20,111 @@ 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/"; +public class ServiceLiveTest { + private static final String BASE_URL = "http://localhost:8082/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 { - HttpPut httpPut = new HttpPut(BASE_URL + "3"); - InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("non_existent_course.xml"); + 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"); - - HttpResponse response = client.execute(httpPut); + + final HttpResponse response = client.execute(httpPut); assertEquals(404, response.getStatusLine().getStatusCode()); } - + @Test public void whenUpdateUnchangedCourse_thenReceiveNotModifiedResponse() throws IOException { - HttpPut httpPut = new HttpPut(BASE_URL + "1"); - InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("unchanged_course.xml"); + 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"); - - HttpResponse response = client.execute(httpPut); + + final HttpResponse response = client.execute(httpPut); assertEquals(304, response.getStatusLine().getStatusCode()); } - + @Test public void whenUpdateValidCourse_thenReceiveOKResponse() throws IOException { - HttpPut httpPut = new HttpPut(BASE_URL + "2"); - InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("changed_course.xml"); + 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"); - - HttpResponse response = client.execute(httpPut); + + final HttpResponse response = client.execute(httpPut); assertEquals(200, response.getStatusLine().getStatusCode()); - - Course course = getCourse(2); + + final Course course = getCourse(2); assertEquals(2, course.getId()); assertEquals("Apache CXF Support for RESTful", course.getName()); } - + @Test public void whenCreateConflictStudent_thenReceiveConflictResponse() throws IOException { - HttpPost httpPost = new HttpPost(BASE_URL + "1/students"); - InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("conflict_student.xml"); + 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"); - - HttpResponse response = client.execute(httpPost); + + final HttpResponse response = client.execute(httpPost); assertEquals(409, response.getStatusLine().getStatusCode()); } @Test public void whenCreateValidStudent_thenReceiveOKResponse() throws IOException { - HttpPost httpPost = new HttpPost(BASE_URL + "2/students"); - InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("created_student.xml"); + 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"); - - HttpResponse response = client.execute(httpPost); + + final HttpResponse response = client.execute(httpPost); assertEquals(200, response.getStatusLine().getStatusCode()); - - Student student = getStudent(2, 3); + + final Student student = getStudent(2, 3); assertEquals(3, student.getId()); assertEquals("Student C", student.getName()); } - + @Test public void whenDeleteInvalidStudent_thenReceiveNotFoundResponse() throws IOException { - HttpDelete httpDelete = new HttpDelete(BASE_URL + "1/students/3"); - HttpResponse response = client.execute(httpDelete); + 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 { - HttpDelete httpDelete = new HttpDelete(BASE_URL + "1/students/1"); - HttpResponse response = client.execute(httpDelete); + final HttpDelete httpDelete = new HttpDelete(BASE_URL + "1/students/1"); + final HttpResponse response = client.execute(httpDelete); assertEquals(200, response.getStatusLine().getStatusCode()); - - Course course = getCourse(1); + + 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 { - URL url = new URL(BASE_URL + courseOrder); - InputStream input = url.openStream(); + 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 { - URL url = new URL(BASE_URL + courseOrder + "/students/" + studentOrder); - InputStream input = url.openStream(); + final URL url = new URL(BASE_URL + courseOrder + "/students/" + studentOrder); + final InputStream input = url.openStream(); return JAXB.unmarshal(new InputStreamReader(input), Student.class); } } \ No newline at end of file diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml index 85e68300f0..8f1dee965a 100644 --- a/apache-cxf/cxf-spring/pom.xml +++ b/apache-cxf/cxf-spring/pom.xml @@ -51,7 +51,7 @@ ${surefire.version} - StudentTest.java + **/*LiveTest.java @@ -60,7 +60,7 @@ - integration + live diff --git a/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java b/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentLiveTest.java similarity index 97% rename from apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java rename to apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentLiveTest.java index 7466944e04..80a8f6c3b8 100644 --- a/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java +++ b/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentLiveTest.java @@ -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");