configure test profiles
This commit is contained in:
parent
8cdc680e6f
commit
bc9b170e89
|
@ -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,66 @@
|
|||
<version>${cxf.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>live</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.cargo</groupId>
|
||||
<artifactId>cargo-maven2-plugin</artifactId>
|
||||
<version>1.4.19</version>
|
||||
<configuration>
|
||||
<container>
|
||||
<containerId>tomcat8x</containerId>
|
||||
<type>embedded</type>
|
||||
</container>
|
||||
<configuration>
|
||||
<properties>
|
||||
<cargo.hostname>localhost</cargo.hostname>
|
||||
<cargo.servlet.port>8082</cargo.servlet.port>
|
||||
</properties>
|
||||
</configuration>
|
||||
</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>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>none</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
</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: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<Integer, Student> students = baeldungProxy.getStudents();
|
||||
|
||||
final Map<Integer, Student> students = baeldungProxy.getStudents();
|
||||
assertEquals("Adam", students.get(1).getName());
|
||||
assertEquals("Eve", students.get(2).getName());
|
||||
}
|
|
@ -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>
|
||||
|
@ -51,4 +52,66 @@
|
|||
<version>${httpclient.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>live</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.cargo</groupId>
|
||||
<artifactId>cargo-maven2-plugin</artifactId>
|
||||
<version>1.4.19</version>
|
||||
<configuration>
|
||||
<container>
|
||||
<containerId>tomcat8x</containerId>
|
||||
<type>embedded</type>
|
||||
</container>
|
||||
<configuration>
|
||||
<properties>
|
||||
<cargo.hostname>localhost</cargo.hostname>
|
||||
<cargo.servlet.port>8082</cargo.servlet.port>
|
||||
</properties>
|
||||
</configuration>
|
||||
</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>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>none</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
</project>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
|
Loading…
Reference in New Issue