|
8 | 8 |
|
9 | 9 | import java.net.URI; |
10 | 10 | import java.net.URISyntaxException; |
| 11 | +import java.nio.charset.StandardCharsets; |
| 12 | +import java.util.function.Function; |
11 | 13 |
|
12 | 14 | import org.glassfish.jersey.client.ClientProperties; |
13 | 15 | import org.glassfish.jersey.media.multipart.FormDataMultiPart; |
14 | 16 | import org.glassfish.jersey.media.multipart.MultiPartFeature; |
15 | 17 | import org.glassfish.jersey.server.ResourceConfig; |
16 | 18 | import org.junit.jupiter.api.BeforeEach; |
17 | 19 | import org.junit.jupiter.api.Test; |
| 20 | +import org.junit.jupiter.params.ParameterizedTest; |
| 21 | +import org.junit.jupiter.params.provider.EnumSource; |
18 | 22 | import org.slf4j.Logger; |
19 | 23 | import org.slf4j.LoggerFactory; |
20 | 24 | import org.springframework.boot.SpringApplication; |
|
29 | 33 | import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmitLocalProcessor; |
30 | 34 | import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmissionHandler; |
31 | 35 | import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmitProcessor; |
| 36 | +import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmissionHandler.SubmitResponse; |
32 | 37 | import com.github.tomakehurst.wiremock.client.WireMock; |
33 | 38 | import com.github.tomakehurst.wiremock.junit5.WireMockTest; |
34 | 39 |
|
@@ -303,4 +308,33 @@ public Response processRequest(FormDataMultiPart inFormData, HttpHeaders headers |
303 | 308 | } |
304 | 309 | } |
305 | 310 |
|
| 311 | + public static class SubmitResponseResponseTests { |
| 312 | + private static final String SAMPLE_TEXT = "text"; |
| 313 | + private static final byte[] SAMPLE_TEXT_BYTES = SAMPLE_TEXT.getBytes(StandardCharsets.UTF_8); |
| 314 | + |
| 315 | + enum TestScenario { |
| 316 | + TEXT("text/plain", SubmitResponse.Response::text), |
| 317 | + HTML("text/html", SubmitResponse.Response::html), |
| 318 | + JSON("application/json", SubmitResponse.Response::json), |
| 319 | + XML("application/xml", SubmitResponse.Response::xml) |
| 320 | + ; |
| 321 | + final String expectedContentType; |
| 322 | + final Function<String, SubmitResponse.Response> methodUnderTest; |
| 323 | + |
| 324 | + private TestScenario(String expectedContentType, Function<String, SubmitResponse.Response> methodUnderTest) { |
| 325 | + this.expectedContentType = expectedContentType; |
| 326 | + this.methodUnderTest = methodUnderTest; |
| 327 | + } |
| 328 | + } |
| 329 | + |
| 330 | + @ParameterizedTest |
| 331 | + @EnumSource |
| 332 | + void testText(TestScenario scenario) { |
| 333 | + var result = scenario.methodUnderTest.apply(SAMPLE_TEXT); |
| 334 | + assertAll( |
| 335 | + ()->assertArrayEquals(SAMPLE_TEXT_BYTES, result.responseBytes()), |
| 336 | + ()->assertEquals(scenario.expectedContentType, result.mediaType()) |
| 337 | + ); |
| 338 | + } |
| 339 | + } |
306 | 340 | } |
0 commit comments