Skip to content

Commit 48f3f0b

Browse files
committed
add live test profile
1 parent 672b6fe commit 48f3f0b

2 files changed

Lines changed: 142 additions & 51 deletions

File tree

‎resteasy/pom.xml‎

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
<properties>
1212
<resteasy.version>3.0.14.Final</resteasy.version>
13+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
14+
<cargo-maven2-plugin.version>1.6.0</cargo-maven2-plugin.version>
1315
</properties>
1416

1517
<build>
@@ -23,6 +25,35 @@
2325
<target>1.8</target>
2426
</configuration>
2527
</plugin>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-surefire-plugin</artifactId>
31+
<version>${maven-surefire-plugin.version}</version>
32+
<configuration>
33+
<excludes>
34+
<exclude>**/*IntegrationTest.java</exclude>
35+
<exclude>**/*LiveTest.java</exclude>
36+
</excludes>
37+
</configuration>
38+
</plugin>
39+
40+
<plugin>
41+
<groupId>org.codehaus.cargo</groupId>
42+
<artifactId>cargo-maven2-plugin</artifactId>
43+
<version>${cargo-maven2-plugin.version}</version>
44+
<configuration>
45+
<wait>true</wait>
46+
<container>
47+
<containerId>jetty8x</containerId>
48+
<type>embedded</type>
49+
</container>
50+
<configuration>
51+
<properties>
52+
<cargo.servlet.port>8082</cargo.servlet.port>
53+
</properties>
54+
</configuration>
55+
</configuration>
56+
</plugin>
2657
</plugins>
2758
</build>
2859

@@ -73,5 +104,66 @@
73104

74105
</dependencies>
75106

76-
107+
<profiles>
108+
<profile>
109+
<id>live</id>
110+
<build>
111+
112+
<plugins>
113+
114+
<plugin>
115+
<groupId>org.apache.maven.plugins</groupId>
116+
<artifactId>maven-surefire-plugin</artifactId>
117+
<executions>
118+
<execution>
119+
<phase>integration-test</phase>
120+
<goals>
121+
<goal>test</goal>
122+
</goals>
123+
<configuration>
124+
<excludes>
125+
<exclude>**/*IntegrationTest.java</exclude>
126+
</excludes>
127+
<includes>
128+
<include>**/*LiveTest.java</include>
129+
</includes>
130+
</configuration>
131+
</execution>
132+
</executions>
133+
<configuration>
134+
<systemPropertyVariables>
135+
<test.mime>json</test.mime>
136+
</systemPropertyVariables>
137+
</configuration>
138+
</plugin>
139+
<plugin>
140+
<groupId>org.codehaus.cargo</groupId>
141+
<artifactId>cargo-maven2-plugin</artifactId>
142+
<version>${cargo-maven2-plugin.version}</version>
143+
<configuration>
144+
<wait>false</wait>
145+
</configuration>
146+
<executions>
147+
<execution>
148+
<id>start-server</id>
149+
<phase>pre-integration-test</phase>
150+
<goals>
151+
<goal>start</goal>
152+
</goals>
153+
</execution>
154+
<execution>
155+
<id>stop-server</id>
156+
<phase>post-integration-test</phase>
157+
<goals>
158+
<goal>stop</goal>
159+
</goals>
160+
</execution>
161+
</executions>
162+
</plugin>
163+
</plugins>
164+
165+
</build>
166+
</profile>
167+
</profiles>
168+
77169
</project>

resteasy/src/test/java/com/baeldung/server/RestEasyClientTest.java renamed to resteasy/src/test/java/com/baeldung/server/RestEasyClientLiveTest.java

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package com.baeldung.server;
22

3-
import com.baeldung.client.ServicesInterface;
4-
import com.baeldung.model.Movie;
3+
import java.io.InputStream;
4+
import java.nio.charset.StandardCharsets;
5+
import java.text.SimpleDateFormat;
6+
import java.util.List;
7+
import java.util.Locale;
8+
9+
import javax.naming.NamingException;
10+
import javax.ws.rs.core.Response;
11+
import javax.ws.rs.core.UriBuilder;
12+
513
import org.apache.commons.io.IOUtils;
614
import org.apache.http.impl.client.CloseableHttpClient;
715
import org.apache.http.impl.client.HttpClients;
@@ -14,18 +22,13 @@
1422
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine;
1523
import org.junit.Before;
1624
import org.junit.Test;
17-
import javax.naming.NamingException;
18-
import javax.ws.rs.core.Response;
19-
import javax.ws.rs.core.UriBuilder;
20-
import java.io.InputStream;
21-
import java.nio.charset.StandardCharsets;
22-
import java.text.SimpleDateFormat;
23-
import java.util.List;
24-
import java.util.Locale;
2525

26-
public class RestEasyClientTest {
26+
import com.baeldung.client.ServicesInterface;
27+
import com.baeldung.model.Movie;
28+
29+
public class RestEasyClientLiveTest {
2730

28-
public static final UriBuilder FULL_PATH = UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest");
31+
public static final UriBuilder FULL_PATH = UriBuilder.fromPath("http://127.0.0.1:8082/RestEasyTutorial/rest");
2932
Movie transformerMovie = null;
3033
Movie batmanMovie = null;
3134
ObjectMapper jsonMapper = null;
@@ -35,64 +38,64 @@ public void setup() throws ClassNotFoundException, IllegalAccessException, Insta
3538

3639
jsonMapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
3740
jsonMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
38-
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
41+
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
3942
jsonMapper.setDateFormat(sdf);
4043

41-
try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/transformer.json")) {
42-
String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
44+
try (InputStream inputStream = new RestEasyClientLiveTest().getClass().getResourceAsStream("./movies/transformer.json")) {
45+
final String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
4346
transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class);
44-
} catch (Exception e) {
47+
} catch (final Exception e) {
4548
e.printStackTrace();
4649
throw new RuntimeException("Test is going to die ...", e);
4750
}
4851

49-
try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/batman.json")) {
50-
String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
52+
try (InputStream inputStream = new RestEasyClientLiveTest().getClass().getResourceAsStream("./movies/batman.json")) {
53+
final String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
5154
batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class);
5255

53-
} catch (Exception e) {
56+
} catch (final Exception e) {
5457
throw new RuntimeException("Test is going to die ...", e);
5558
}
5659
}
5760

5861
@Test
5962
public void testListAllMovies() {
6063

61-
ResteasyClient client = new ResteasyClientBuilder().build();
62-
ResteasyWebTarget target = client.target(FULL_PATH);
63-
ServicesInterface proxy = target.proxy(ServicesInterface.class);
64+
final ResteasyClient client = new ResteasyClientBuilder().build();
65+
final ResteasyWebTarget target = client.target(FULL_PATH);
66+
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
6467

6568
Response moviesResponse = proxy.addMovie(transformerMovie);
6669
moviesResponse.close();
6770
moviesResponse = proxy.addMovie(batmanMovie);
6871
moviesResponse.close();
6972

70-
List<Movie> movies = proxy.listMovies();
73+
final List<Movie> movies = proxy.listMovies();
7174
System.out.println(movies);
7275
}
7376

7477
@Test
7578
public void testMovieByImdbId() {
7679

77-
String transformerImdbId = "tt0418279";
80+
final String transformerImdbId = "tt0418279";
7881

79-
ResteasyClient client = new ResteasyClientBuilder().build();
80-
ResteasyWebTarget target = client.target(FULL_PATH);
81-
ServicesInterface proxy = target.proxy(ServicesInterface.class);
82+
final ResteasyClient client = new ResteasyClientBuilder().build();
83+
final ResteasyWebTarget target = client.target(FULL_PATH);
84+
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
8285

83-
Response moviesResponse = proxy.addMovie(transformerMovie);
86+
final Response moviesResponse = proxy.addMovie(transformerMovie);
8487
moviesResponse.close();
8588

86-
Movie movies = proxy.movieByImdbId(transformerImdbId);
89+
final Movie movies = proxy.movieByImdbId(transformerImdbId);
8790
System.out.println(movies);
8891
}
8992

9093
@Test
9194
public void testAddMovie() {
9295

93-
ResteasyClient client = new ResteasyClientBuilder().build();
94-
ResteasyWebTarget target = client.target(FULL_PATH);
95-
ServicesInterface proxy = target.proxy(ServicesInterface.class);
96+
final ResteasyClient client = new ResteasyClientBuilder().build();
97+
final ResteasyWebTarget target = client.target(FULL_PATH);
98+
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
9699

97100
Response moviesResponse = proxy.addMovie(batmanMovie);
98101
moviesResponse.close();
@@ -109,17 +112,15 @@ public void testAddMovie() {
109112
@Test
110113
public void testAddMovieMultiConnection() {
111114

112-
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
113-
CloseableHttpClient httpClient = HttpClients.custom()
114-
.setConnectionManager(cm)
115-
.build();
116-
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
117-
ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
118-
ResteasyWebTarget target = client.target(FULL_PATH);
119-
ServicesInterface proxy = target.proxy(ServicesInterface.class);
115+
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
116+
final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
117+
final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
118+
final ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
119+
final ResteasyWebTarget target = client.target(FULL_PATH);
120+
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
120121

121-
Response batmanResponse = proxy.addMovie(batmanMovie);
122-
Response transformerResponse = proxy.addMovie(transformerMovie);
122+
final Response batmanResponse = proxy.addMovie(batmanMovie);
123+
final Response transformerResponse = proxy.addMovie(transformerMovie);
123124

124125
if (batmanResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
125126
System.out.println("Batman Movie creation Failed : HTTP error code : " + batmanResponse.getStatus());
@@ -132,16 +133,14 @@ public void testAddMovieMultiConnection() {
132133
transformerResponse.close();
133134
cm.close();
134135

135-
136-
137136
}
138137

139138
@Test
140139
public void testDeleteMovie() {
141140

142-
ResteasyClient client = new ResteasyClientBuilder().build();
143-
ResteasyWebTarget target = client.target(FULL_PATH);
144-
ServicesInterface proxy = target.proxy(ServicesInterface.class);
141+
final ResteasyClient client = new ResteasyClientBuilder().build();
142+
final ResteasyWebTarget target = client.target(FULL_PATH);
143+
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
145144

146145
Response moviesResponse = proxy.addMovie(batmanMovie);
147146
moviesResponse.close();
@@ -159,9 +158,9 @@ public void testDeleteMovie() {
159158
@Test
160159
public void testUpdateMovie() {
161160

162-
ResteasyClient client = new ResteasyClientBuilder().build();
163-
ResteasyWebTarget target = client.target(FULL_PATH);
164-
ServicesInterface proxy = target.proxy(ServicesInterface.class);
161+
final ResteasyClient client = new ResteasyClientBuilder().build();
162+
final ResteasyWebTarget target = client.target(FULL_PATH);
163+
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
165164

166165
Response moviesResponse = proxy.addMovie(batmanMovie);
167166
moviesResponse.close();

0 commit comments

Comments
 (0)