add live test profile
This commit is contained in:
parent
672b6fe336
commit
48f3f0b834
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<resteasy.version>3.0.14.Final</resteasy.version>
|
<resteasy.version>3.0.14.Final</resteasy.version>
|
||||||
|
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||||
|
<cargo-maven2-plugin.version>1.6.0</cargo-maven2-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -23,6 +25,35 @@
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</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>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</container>
|
||||||
|
<configuration>
|
||||||
|
<properties>
|
||||||
|
<cargo.servlet.port>8082</cargo.servlet.port>
|
||||||
|
</properties>
|
||||||
|
</configuration>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
@ -73,5 +104,66 @@
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<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>
|
||||||
|
<version>${cargo-maven2-plugin.version}</version>
|
||||||
|
<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>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,7 +1,15 @@
|
||||||
package com.baeldung.server;
|
package com.baeldung.server;
|
||||||
|
|
||||||
import com.baeldung.client.ServicesInterface;
|
import java.io.InputStream;
|
||||||
import com.baeldung.model.Movie;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
@ -14,18 +22,13 @@ import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
|
||||||
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine;
|
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import javax.naming.NamingException;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class RestEasyClientTest {
|
import com.baeldung.client.ServicesInterface;
|
||||||
|
import com.baeldung.model.Movie;
|
||||||
|
|
||||||
public static final UriBuilder FULL_PATH = UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest");
|
public class RestEasyClientLiveTest {
|
||||||
|
|
||||||
|
public static final UriBuilder FULL_PATH = UriBuilder.fromPath("http://127.0.0.1:8082/RestEasyTutorial/rest");
|
||||||
Movie transformerMovie = null;
|
Movie transformerMovie = null;
|
||||||
Movie batmanMovie = null;
|
Movie batmanMovie = null;
|
||||||
ObjectMapper jsonMapper = null;
|
ObjectMapper jsonMapper = null;
|
||||||
|
@ -35,22 +38,22 @@ public class RestEasyClientTest {
|
||||||
|
|
||||||
jsonMapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
jsonMapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
jsonMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
jsonMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
|
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
|
||||||
jsonMapper.setDateFormat(sdf);
|
jsonMapper.setDateFormat(sdf);
|
||||||
|
|
||||||
try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/transformer.json")) {
|
try (InputStream inputStream = new RestEasyClientLiveTest().getClass().getResourceAsStream("./movies/transformer.json")) {
|
||||||
String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
|
final String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
|
||||||
transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class);
|
transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class);
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new RuntimeException("Test is going to die ...", e);
|
throw new RuntimeException("Test is going to die ...", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/batman.json")) {
|
try (InputStream inputStream = new RestEasyClientLiveTest().getClass().getResourceAsStream("./movies/batman.json")) {
|
||||||
String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
|
final String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
|
||||||
batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class);
|
batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
throw new RuntimeException("Test is going to die ...", e);
|
throw new RuntimeException("Test is going to die ...", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,41 +61,41 @@ public class RestEasyClientTest {
|
||||||
@Test
|
@Test
|
||||||
public void testListAllMovies() {
|
public void testListAllMovies() {
|
||||||
|
|
||||||
ResteasyClient client = new ResteasyClientBuilder().build();
|
final ResteasyClient client = new ResteasyClientBuilder().build();
|
||||||
ResteasyWebTarget target = client.target(FULL_PATH);
|
final ResteasyWebTarget target = client.target(FULL_PATH);
|
||||||
ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
||||||
|
|
||||||
Response moviesResponse = proxy.addMovie(transformerMovie);
|
Response moviesResponse = proxy.addMovie(transformerMovie);
|
||||||
moviesResponse.close();
|
moviesResponse.close();
|
||||||
moviesResponse = proxy.addMovie(batmanMovie);
|
moviesResponse = proxy.addMovie(batmanMovie);
|
||||||
moviesResponse.close();
|
moviesResponse.close();
|
||||||
|
|
||||||
List<Movie> movies = proxy.listMovies();
|
final List<Movie> movies = proxy.listMovies();
|
||||||
System.out.println(movies);
|
System.out.println(movies);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMovieByImdbId() {
|
public void testMovieByImdbId() {
|
||||||
|
|
||||||
String transformerImdbId = "tt0418279";
|
final String transformerImdbId = "tt0418279";
|
||||||
|
|
||||||
ResteasyClient client = new ResteasyClientBuilder().build();
|
final ResteasyClient client = new ResteasyClientBuilder().build();
|
||||||
ResteasyWebTarget target = client.target(FULL_PATH);
|
final ResteasyWebTarget target = client.target(FULL_PATH);
|
||||||
ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
||||||
|
|
||||||
Response moviesResponse = proxy.addMovie(transformerMovie);
|
final Response moviesResponse = proxy.addMovie(transformerMovie);
|
||||||
moviesResponse.close();
|
moviesResponse.close();
|
||||||
|
|
||||||
Movie movies = proxy.movieByImdbId(transformerImdbId);
|
final Movie movies = proxy.movieByImdbId(transformerImdbId);
|
||||||
System.out.println(movies);
|
System.out.println(movies);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddMovie() {
|
public void testAddMovie() {
|
||||||
|
|
||||||
ResteasyClient client = new ResteasyClientBuilder().build();
|
final ResteasyClient client = new ResteasyClientBuilder().build();
|
||||||
ResteasyWebTarget target = client.target(FULL_PATH);
|
final ResteasyWebTarget target = client.target(FULL_PATH);
|
||||||
ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
||||||
|
|
||||||
Response moviesResponse = proxy.addMovie(batmanMovie);
|
Response moviesResponse = proxy.addMovie(batmanMovie);
|
||||||
moviesResponse.close();
|
moviesResponse.close();
|
||||||
|
@ -109,17 +112,15 @@ public class RestEasyClientTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAddMovieMultiConnection() {
|
public void testAddMovieMultiConnection() {
|
||||||
|
|
||||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
||||||
CloseableHttpClient httpClient = HttpClients.custom()
|
final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
|
||||||
.setConnectionManager(cm)
|
final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
|
||||||
.build();
|
final ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
|
||||||
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
|
final ResteasyWebTarget target = client.target(FULL_PATH);
|
||||||
ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
|
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
||||||
ResteasyWebTarget target = client.target(FULL_PATH);
|
|
||||||
ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
|
||||||
|
|
||||||
Response batmanResponse = proxy.addMovie(batmanMovie);
|
final Response batmanResponse = proxy.addMovie(batmanMovie);
|
||||||
Response transformerResponse = proxy.addMovie(transformerMovie);
|
final Response transformerResponse = proxy.addMovie(transformerMovie);
|
||||||
|
|
||||||
if (batmanResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
|
if (batmanResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
|
||||||
System.out.println("Batman Movie creation Failed : HTTP error code : " + batmanResponse.getStatus());
|
System.out.println("Batman Movie creation Failed : HTTP error code : " + batmanResponse.getStatus());
|
||||||
|
@ -132,16 +133,14 @@ public class RestEasyClientTest {
|
||||||
transformerResponse.close();
|
transformerResponse.close();
|
||||||
cm.close();
|
cm.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteMovie() {
|
public void testDeleteMovie() {
|
||||||
|
|
||||||
ResteasyClient client = new ResteasyClientBuilder().build();
|
final ResteasyClient client = new ResteasyClientBuilder().build();
|
||||||
ResteasyWebTarget target = client.target(FULL_PATH);
|
final ResteasyWebTarget target = client.target(FULL_PATH);
|
||||||
ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
||||||
|
|
||||||
Response moviesResponse = proxy.addMovie(batmanMovie);
|
Response moviesResponse = proxy.addMovie(batmanMovie);
|
||||||
moviesResponse.close();
|
moviesResponse.close();
|
||||||
|
@ -159,9 +158,9 @@ public class RestEasyClientTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateMovie() {
|
public void testUpdateMovie() {
|
||||||
|
|
||||||
ResteasyClient client = new ResteasyClientBuilder().build();
|
final ResteasyClient client = new ResteasyClientBuilder().build();
|
||||||
ResteasyWebTarget target = client.target(FULL_PATH);
|
final ResteasyWebTarget target = client.target(FULL_PATH);
|
||||||
ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
|
||||||
|
|
||||||
Response moviesResponse = proxy.addMovie(batmanMovie);
|
Response moviesResponse = proxy.addMovie(batmanMovie);
|
||||||
moviesResponse.close();
|
moviesResponse.close();
|
Loading…
Reference in New Issue