Skip to content

Commit 5051949

Browse files
committed
⬆️ Upgrade to latest WireMock version, Use random ports in tests
Altered the tests to use the Spring/WireMock integration which allows for the use of random ports instead of fixed ports. New libraries surfaced an issue with the server code returning duplicate Transfer-Encoding headers in POST responses. This was corrected.
1 parent cdbbabb commit 5051949

8 files changed

Lines changed: 59 additions & 81 deletions

File tree

spring/fluentforms-jersey-spring-boot-autoconfigure/pom.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
<!-- Testing Dependencies -->
2222
<fp.hamcrest.matchers.version>0.0.4-SNAPSHOT</fp.hamcrest.matchers.version>
23-
<wiremock.version>4.0.0-beta.16</wiremock.version>
23+
<wiremock.version>4.0.0-beta.22</wiremock.version>
24+
<wiremock-spring-boot.version>4.0.8</wiremock-spring-boot.version>
2425
<pitest.maven.plugin.version>1.20.2</pitest.maven.plugin.version>
2526
<pitest.junit5.maven.plugin.version>1.2.3</pitest.junit5.maven.plugin.version>
2627
</properties>
@@ -105,10 +106,22 @@
105106
</dependency>
106107
<dependency>
107108
<groupId>org.wiremock</groupId>
108-
<artifactId>wiremock-standalone</artifactId>
109+
<artifactId>wiremock</artifactId>
109110
<version>${wiremock.version}</version>
110111
<scope>test</scope>
111112
</dependency>
113+
<dependency>
114+
<groupId>org.wiremock</groupId>
115+
<artifactId>wiremock-junit5</artifactId>
116+
<version>${wiremock.version}</version>
117+
<scope>test</scope>
118+
</dependency>
119+
<dependency>
120+
<groupId>org.wiremock.integrations</groupId>
121+
<artifactId>wiremock-spring-boot</artifactId>
122+
<version>${wiremock-spring-boot.version}</version>
123+
<scope>test</scope>
124+
</dependency>
112125
<dependency>
113126
<groupId>org.pitest</groupId>
114127
<artifactId>pitest-junit5-plugin</artifactId>

spring/fluentforms-jersey-spring-boot-autoconfigure/src/main/java/com/_4point/aem/fluentforms/spring/AemProxyJerseyEndpoint.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ public Response proxyPost(@PathParam("remainder") String remainder, @HeaderParam
204204
.log("Returning POST response from target '{}'.");
205205
}
206206

207-
return Response.fromResponse(result).build();
207+
return Response.fromResponse(result)
208+
.header("Transfer-Encoding", null) // Remove the Transfer-Encoding header
209+
.build();
208210
}
209211

210212
private InputStream debugInput(InputStream in, String target) {

spring/fluentforms-jersey-spring-boot-autoconfigure/src/test/java/com/_4point/aem/fluentforms/spring/AemProxyJerseyEndpointTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
2424
import org.springframework.boot.test.web.server.LocalServerPort;
2525
import org.springframework.web.client.RestClient;
26+
import org.wiremock.spring.ConfigureWireMock;
27+
import org.wiremock.spring.EnableWireMock;
2628

2729
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
2830
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
2931

30-
@WireMockTest(httpPort = AemProxyJerseyEndpointTest.WIREMOCK_PORT)
32+
@WireMockTest()
3133
@SpringBootTest(classes = {com._4point.aem.fluentforms.spring.AemProxyJerseyEndpointTest.TestApplication.class},
3234
webEnvironment = WebEnvironment.RANDOM_PORT,
3335
properties = {
3436
"fluentforms.aem.servername=localhost",
35-
"fluentforms.aem.port=" + AemProxyJerseyEndpointTest.WIREMOCK_PORT,
3637
"fluentforms.aem.user=ENC(7FgD3ZsSExfUGRYlXNc++6C1upPBURNKq6HouzagnNZW4FsBwFs5+crawv+djhw6)",
3738
"fluentforms.aem.password=ENC(QmQ6iTm/+TOO8U3dDuBzJWH129vReWgYNdgqQwWhjWaQy6j8sMnk2/Auhehmlh3v)",
3839
//"fluentforms.aem.useSsl=true",
@@ -41,13 +42,18 @@
4142
"jasypt.encryptor.password=4Point",
4243
"jasypt.encryptor.iv-generator-classname=org.jasypt.iv.RandomIvGenerator",
4344
"jasypt.encryptor.salt-generator-classname=org.jasypt.salt.RandomSaltGenerator",
44-
"logging.level.com._4point.aem.fluentforms.spring.AemProxyEndpoint=DEBUG"
45+
"logging.level.com._4point.aem.fluentforms.spring.AemProxyEndpoint=DEBUG",
46+
// Wiremock produces a lot of output, the following entries reduce that output. They can be removed for debugging.
47+
"logging.level.org.wiremock.spring=WARN", "logging.level.WireMock.wiremock=WARN",
4548
})
46-
@Timeout(value = 5, unit = TimeUnit.MINUTES) // Fail tests that take longer than this to prevent hanging.
49+
@EnableWireMock(@ConfigureWireMock(
50+
portProperties = "fluentforms.aem.port"
51+
)
52+
)
53+
@Timeout(value = 30, unit = TimeUnit.SECONDS) // Fail tests that take longer than this to prevent hanging.
4754
class AemProxyJerseyEndpointTest {
4855
private final static Logger logger = LoggerFactory.getLogger(AemProxyJerseyEndpointTest.class);
4956

50-
static final int WIREMOCK_PORT = 5504;
5157
static final String AF_BASE_LOCATION = "/aem";
5258

5359
// The following is a string that contains all possible values that may be modified by the AemProxyEndpoint.

spring/fluentforms-sample-web-jersey-app/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
<properties>
1818
<java.version>17</java.version>
19-
<wiremock.version>3.13.1</wiremock.version>
20-
<wiremock-spring-boot.version>3.10.6</wiremock-spring-boot.version>
19+
<wiremock.version>4.0.0-beta.22</wiremock.version>
20+
<wiremock-spring-boot.version>4.0.8</wiremock-spring-boot.version>
2121
<fluentforms.jersey.spring.boot.starter.version>0.0.5-SNAPSHOT</fluentforms.jersey.spring.boot.starter.version>
2222
<fp.hamcrest.matchers.version>0.0.4-SNAPSHOT</fp.hamcrest.matchers.version>
2323
</properties>

spring/fluentforms-sample-webmvc-app/pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
<properties>
1818
<java.version>17</java.version>
19-
<wiremock.version>3.13.2</wiremock.version>
20-
<wiremock-spring-boot.version>3.10.6</wiremock-spring-boot.version>
19+
<wiremock.version>4.0.0-beta.22</wiremock.version>
20+
<wiremock-spring-boot.version>4.0.8</wiremock-spring-boot.version>
2121
<fluentforms.spring.boot.starter.version>0.0.5-SNAPSHOT</fluentforms.spring.boot.starter.version>
2222
<fp.hamcrest.matchers.version>0.0.4-SNAPSHOT</fp.hamcrest.matchers.version>
2323
</properties>
@@ -84,7 +84,13 @@
8484
</dependency>
8585
<dependency>
8686
<groupId>org.wiremock</groupId>
87-
<artifactId>wiremock-standalone</artifactId>
87+
<artifactId>wiremock</artifactId>
88+
<version>${wiremock.version}</version>
89+
<scope>test</scope>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.wiremock</groupId>
93+
<artifactId>wiremock-junit5</artifactId>
8894
<version>${wiremock.version}</version>
8995
<scope>test</scope>
9096
</dependency>

spring/fluentforms-spring-boot-autoconfigure/pom.xml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<jasypt.maven.plugin.version>3.0.5</jasypt.maven.plugin.version>
2020
<fluentforms.version>0.0.5-SNAPSHOT</fluentforms.version>
2121
<fp.hamcrest.matchers.version>0.0.4-SNAPSHOT</fp.hamcrest.matchers.version>
22-
<wiremock.version>4.0.0-beta.21</wiremock.version>
22+
<wiremock.version>4.0.0-beta.22</wiremock.version>
2323
<wiremock-spring-boot.version>4.0.8</wiremock-spring-boot.version>
2424
<pitest.maven.plugin.version>1.20.2</pitest.maven.plugin.version>
2525
<pitest.junit5.maven.plugin.version>1.2.3</pitest.junit5.maven.plugin.version>
@@ -102,30 +102,22 @@
102102
</dependency>
103103
<dependency>
104104
<groupId>org.wiremock</groupId>
105-
<artifactId>wiremock-standalone</artifactId>
105+
<artifactId>wiremock</artifactId>
106106
<version>${wiremock.version}</version>
107107
<scope>test</scope>
108108
</dependency>
109109
<dependency>
110-
<groupId>org.wiremock.integrations</groupId>
111-
<artifactId>wiremock-spring-boot</artifactId>
112-
<version>${wiremock-spring-boot.version}</version>
113-
<scope>test</scope>
114-
</dependency>
115-
<!-- Explicit HttpComponents (override transitive versions that may not support chunked correctly) -->
116-
<!-- <dependency>
117-
<groupId>org.apache.hc.client5</groupId>
118-
<artifactId>httpclient5</artifactId>
119-
<version>5.2.3</version>
110+
<groupId>org.wiremock</groupId>
111+
<artifactId>wiremock-junit5</artifactId>
112+
<version>${wiremock.version}</version>
120113
<scope>test</scope>
121114
</dependency>
122115
<dependency>
123-
<groupId>org.apache.hc.core5</groupId>
124-
<artifactId>httpcore5</artifactId>
125-
<version>5.2.3</version>
116+
<groupId>org.wiremock.integrations</groupId>
117+
<artifactId>wiremock-spring-boot</artifactId>
118+
<version>${wiremock-spring-boot.version}</version>
126119
<scope>test</scope>
127120
</dependency>
128-
-->
129121
<dependency>
130122
<groupId>org.pitest</groupId>
131123
<artifactId>pitest-junit5-plugin</artifactId>

spring/fluentforms-spring-boot-autoconfigure/src/test/java/com/_4point/aem/fluentforms/spring/AemProxyAfSubmissionTest.java

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.net.URI;
99
import java.net.URISyntaxException;
10+
import java.net.http.HttpClient;
1011
import java.nio.charset.StandardCharsets;
1112
import java.util.List;
1213
import java.util.function.Function;
@@ -39,6 +40,7 @@
3940
import org.springframework.http.HttpStatusCode;
4041
import org.springframework.http.MediaType;
4142
import org.springframework.http.ResponseEntity;
43+
import org.springframework.http.client.JdkClientHttpRequestFactory;
4244
import org.springframework.stereotype.Component;
4345
import org.springframework.util.LinkedMultiValueMap;
4446
import org.springframework.util.MultiValueMap;
@@ -69,19 +71,14 @@ class AemProxyAfSubmissionTest {
6971
private static final String AEM_SUBMIT_ADAPTIVE_FORM_SERVICE_PATH = SUBMIT_ADAPTIVE_FORM_SERVICE_PATH.substring(4); // Same as above minus "/aem"
7072
private static final String SAMPLE_RESPONSE_BODY = "body";
7173

72-
// record JakartaRestClient(WebTarget target, URI uri) {};
73-
//
74-
// public static JakartaRestClient setUpRestClient(int port) {
75-
// var uri = getBaseUri(port);
76-
// var target = ClientBuilder.newClient() //newClient(clientConfig)
77-
// .property(ClientProperties.FOLLOW_REDIRECTS, Boolean.FALSE) // Disable re-directs so that we can test for "thank you page" redirection.
78-
// .register(MultiPartFeature.class)
79-
// .target(uri);
80-
// return new JakartaRestClient(target, uri);
81-
// }
82-
8374
private static RestClient createRestClient(int port) {
75+
// Configure the underlying HttpClient to not follow redirects
76+
HttpClient httpClient = HttpClient.newBuilder()
77+
.followRedirects(HttpClient.Redirect.NEVER) // Use NEVER to prevent all redirects
78+
.build();
79+
8480
return RestClient.builder()
81+
.requestFactory(new JdkClientHttpRequestFactory(httpClient))
8582
.baseUrl(getBaseUri(port))
8683
.build();
8784
}
@@ -181,12 +178,10 @@ public static class AemProxyAfSubmissionTestWithAemAfSubmitProcessorTest {
181178
@LocalServerPort
182179
private int port;
183180

184-
// private JakartaRestClient jrc;
185181
private RestClient restClient;
186182

187183
@BeforeEach
188184
public void setUp() throws Exception {
189-
// jrc = setUpRestClient(port);
190185
restClient = createRestClient(port);
191186
}
192187

@@ -203,16 +198,12 @@ void test() {
203198
MultiValueMap<String, HttpEntity<?>> parts = getPdfForm.parts();
204199
ResponseEntity<byte[]> response = restClient.post()
205200
.uri(SUBMIT_ADAPTIVE_FORM_SERVICE_PATH)
206-
// .contentType(MediaType.MULTIPART_FORM_DATA)
207201
.body(parts)
208202
.accept(MediaType.APPLICATION_PDF)
209203
.retrieve()
210204
.toEntity(byte[].class)
211205
;
212206

213-
// .target.path().request().accept(APPLICATION_PDF)
214-
// .post(Entity.entity(getPdfForm, getPdfForm.getMediaType()));
215-
216207
// then
217208
assertThat(response, allOf(hasStatus(HttpStatus.OK), hasEntityMatching(equalTo(expectedResponseString.getBytes()))));
218209
WireMock.verify(
@@ -255,12 +246,10 @@ public static class AemProxyAfSubmissionTestWithLocalAfSubmitProcessorTest {
255246
@LocalServerPort
256247
private int port;
257248

258-
// private JakartaRestClient jrc;
259249
private RestClient restClient;
260250

261251
@BeforeEach
262252
public void setUp() throws Exception {
263-
// jrc = setUpRestClient(port);
264253
restClient = createRestClient(port);
265254
}
266255

@@ -278,12 +267,6 @@ void testResponse() {
278267
.toEntity(byte[].class)
279268
;
280269

281-
// Response response = jrc.target
282-
// .path(SUBMIT_ADAPTIVE_FORM_SERVICE_PATH)
283-
// .request()
284-
// .accept(MediaType.TEXT_PLAIN_TYPE)
285-
// .post(Entity.entity(getPdfForm, getPdfForm.getMediaType()));
286-
287270
assertThat(response, allOf(hasStatus(HttpStatus.OK),hasEntityMatching(equalTo(AF_SUBMIT_LOCAL_PROCESSOR_RESPONSE.getBytes()))));
288271
}
289272

@@ -299,11 +282,6 @@ void testRedirect() {
299282
.retrieve()
300283
.toBodilessEntity()
301284
;
302-
// Response response = jrc.target
303-
// .path(SUBMIT_ADAPTIVE_FORM_SERVICE_PATH)
304-
// .request()
305-
// .accept(MediaType.TEXT_PLAIN_TYPE)
306-
// .post(Entity.entity(getPdfForm, getPdfForm.getMediaType()));
307285

308286
assertThat(response, allOf(hasStatus(HttpStatus.TEMPORARY_REDIRECT), doesNotHaveEntity()));
309287
}
@@ -314,17 +292,11 @@ void testSeeOther() {
314292

315293
ResponseEntity<Void> response = restClient.post()
316294
.uri(SUBMIT_ADAPTIVE_FORM_SERVICE_PATH)
317-
// .contentType(MediaType.MULTIPART_FORM_DATA)
318295
.body(getPdfForm.parts())
319296
.accept(MediaType.TEXT_PLAIN)
320297
.retrieve()
321298
.toBodilessEntity()
322299
;
323-
// Response response = jrc.target
324-
// .path(SUBMIT_ADAPTIVE_FORM_SERVICE_PATH)
325-
// .request()
326-
// .accept(MediaType.TEXT_PLAIN_TYPE)
327-
// .post(Entity.entity(getPdfForm, getPdfForm.getMediaType()));
328300

329301
assertThat(response, allOf(hasStatus(HttpStatus.SEE_OTHER), doesNotHaveEntity()));
330302
}
@@ -342,12 +314,6 @@ void testProxy() {
342314
.toBodilessEntity()
343315
;
344316

345-
// Response response = jrc.target
346-
// .path(SUBMIT_ADAPTIVE_FORM_SERVICE_PATH+"anythingElse")
347-
// .request()
348-
// .accept(MediaType.TEXT_PLAIN_TYPE)
349-
// .post(Entity.entity(getPdfForm, getPdfForm.getMediaType()));
350-
351317
assertThat(response, allOf(hasStatus(HttpStatus.OK), doesNotHaveEntity()));
352318
}
353319

@@ -432,12 +398,10 @@ public static class AemProxyAfSubmissionTestWithCustomAfSubmitProcessorTest {
432398
@LocalServerPort
433399
private int port;
434400

435-
// private JakartaRestClient jrc;
436401
private RestClient restClient;
437402

438403
@BeforeEach
439404
public void setUp() throws Exception {
440-
// jrc = setUpRestClient(port);
441405
restClient = createRestClient(port);
442406
}
443407

@@ -448,17 +412,11 @@ void test() {
448412
MultiValueMap<String, HttpEntity<?>> parts = getPdfForm.parts();
449413
ResponseEntity<byte[]> response = restClient.post()
450414
.uri(SUBMIT_ADAPTIVE_FORM_SERVICE_PATH)
451-
// .contentType(MediaType.MULTIPART_FORM_DATA)
452415
.body(parts)
453416
.accept(MediaType.APPLICATION_PDF)
454417
.retrieve()
455418
.toEntity(byte[].class)
456419
;
457-
// Response response = jrc.target
458-
// .path(SUBMIT_ADAPTIVE_FORM_SERVICE_PATH)
459-
// .request()
460-
// .accept(APPLICATION_PDF)
461-
// .post(Entity.entity(getPdfForm, getPdfForm.getMediaType()));
462420

463421
assertThat(response, allOf(hasStatus(HttpStatus.OK), hasEntityMatching(equalTo(SAMPLE_RESPONSE_BODY.getBytes()))));
464422
}

spring/fluentforms-spring-boot-autoconfigure/src/test/java/com/_4point/aem/fluentforms/spring/AemProxyEndpointTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"jasypt.encryptor.password=4Point",
4343
"jasypt.encryptor.iv-generator-classname=org.jasypt.iv.RandomIvGenerator",
4444
"jasypt.encryptor.salt-generator-classname=org.jasypt.salt.RandomSaltGenerator",
45-
"logging.level.com._4point.aem.fluentforms.spring.AemProxyEndpoint=DEBUG"
45+
"logging.level.com._4point.aem.fluentforms.spring.AemProxyEndpoint=DEBUG",
46+
//Wiremock produces a lot of output, the following entries reduce that output. They can be removed for debugging.
47+
"logging.level.org.wiremock.spring=WARN", "logging.level.WireMock.wiremock=WARN",
4648
})
4749
@EnableWireMock(@ConfigureWireMock(
4850
portProperties = "fluentforms.aem.port"
@@ -52,7 +54,6 @@
5254
class AemProxyEndpointTest {
5355
private final static Logger logger = LoggerFactory.getLogger(AemProxyEndpointTest.class);
5456

55-
static final int WIREMOCK_PORT = 5504;
5657
static final String AF_BASE_LOCATION = "/aem";
5758

5859
// The following is a string that contains all possible values that may be modified by the AemProxyEndpoint.

0 commit comments

Comments
 (0)