|
23 | 23 | import org.junit.jupiter.params.ParameterizedTest; |
24 | 24 | import org.junit.jupiter.params.provider.CsvSource; |
25 | 25 | import org.junit.jupiter.params.provider.EnumSource; |
| 26 | +import org.mockito.Mockito; |
26 | 27 | import org.slf4j.Logger; |
27 | 28 | import org.slf4j.LoggerFactory; |
28 | 29 | import org.springframework.boot.SpringApplication; |
|
31 | 32 | import org.springframework.boot.test.context.SpringBootTest; |
32 | 33 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; |
33 | 34 | import org.springframework.boot.test.web.server.LocalServerPort; |
| 35 | +import org.springframework.context.annotation.Bean; |
| 36 | +import org.springframework.context.annotation.Configuration; |
34 | 37 | import org.springframework.stereotype.Component; |
35 | 38 |
|
36 | 39 | import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmitAemProxyProcessor; |
37 | 40 | import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmitLocalProcessor; |
38 | 41 | import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmissionHandler; |
39 | 42 | import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmitProcessor; |
40 | 43 | import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmissionHandler.SubmitResponse; |
| 44 | +import com._4point.aem.fluentforms.spring.AemProxyAfSubmission.AfSubmitLocalProcessor.InternalAfSubmitAemProxyProcessor; |
| 45 | +import com._4point.aem.fluentforms.spring.AemProxyAfSubmissionTest.AemProxyAfSubmissionTestWithLocalAfSubmitProcessorTest.MockAemProxy; |
41 | 46 | import com.github.tomakehurst.wiremock.client.WireMock; |
42 | 47 | import com.github.tomakehurst.wiremock.junit5.WireMockTest; |
43 | 48 |
|
@@ -119,13 +124,13 @@ public static class JerseyConfig extends ResourceConfig { |
119 | 124 | * Tests the AemAfSubmitProcessor |
120 | 125 | * |
121 | 126 | */ |
122 | | - @WireMockTest(httpPort = 4502) |
| 127 | + @WireMockTest(httpPort = 8502) |
123 | 128 | @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, |
124 | 129 | classes = {TestApplication.class, JerseyConfig.class, AfSubmitAemProxyProcessor.class}, |
125 | 130 | properties = { |
126 | 131 | // "debug", |
127 | 132 | "fluentforms.aem.servername=" + "localhost", |
128 | | - "fluentforms.aem.port=" + "4502", |
| 133 | + "fluentforms.aem.port=" + "8502", |
129 | 134 | "fluentforms.aem.user=admin", |
130 | 135 | "fluentforms.aem.password=admin", |
131 | 136 | } |
@@ -170,7 +175,7 @@ void test() { |
170 | 175 | * |
171 | 176 | */ |
172 | 177 | @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, |
173 | | - classes = {TestApplication.class, JerseyConfig.class, AfSubmitLocalProcessor.class, |
| 178 | + classes = {TestApplication.class, JerseyConfig.class, AfSubmitLocalProcessor.class, MockAemProxy.class, |
174 | 179 | AemProxyAfSubmissionTestWithLocalAfSubmitProcessorTest.MockSubmissionProcessor.class, |
175 | 180 | AemProxyAfSubmissionTestWithLocalAfSubmitProcessorTest.MockSubmissionProcessor2.class} |
176 | 181 | ,properties={ |
@@ -220,6 +225,19 @@ void testRedirect() { |
220 | 225 | assertThat(response, allOf(isStatus(Response.Status.TEMPORARY_REDIRECT), doesNotHaveEntity())); |
221 | 226 | } |
222 | 227 |
|
| 228 | + @Test |
| 229 | + void testProxy() { |
| 230 | + final FormDataMultiPart getPdfForm = mockFormData("foo2", "bar"); |
| 231 | + |
| 232 | + Response response = jrc.target |
| 233 | + .path(SUBMIT_ADAPTIVE_FORM_SERVICE_PATH+"anythingElse") |
| 234 | + .request() |
| 235 | + .accept(MediaType.TEXT_PLAIN_TYPE) |
| 236 | + .post(Entity.entity(getPdfForm, getPdfForm.getMediaType())); |
| 237 | + |
| 238 | + assertThat(response, allOf(isStatus(Response.Status.OK), doesNotHaveEntity())); |
| 239 | + } |
| 240 | + |
223 | 241 | @Component |
224 | 242 | public static class MockSubmissionProcessor implements AfSubmissionHandler { |
225 | 243 |
|
@@ -267,6 +285,15 @@ public SubmitResponse processSubmission(Submission submission) { |
267 | 285 | } |
268 | 286 | } |
269 | 287 |
|
| 288 | + @Configuration |
| 289 | + public static class MockAemProxy { |
| 290 | + @Bean() |
| 291 | + public InternalAfSubmitAemProxyProcessor aemProxyProcessor() { |
| 292 | + AfSubmitAemProxyProcessor mock = Mockito.mock(AfSubmitAemProxyProcessor.class); |
| 293 | + Mockito.when(mock.processRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(Response.ok().build()); |
| 294 | + return ()->mock; |
| 295 | + } |
| 296 | + } |
270 | 297 | } |
271 | 298 |
|
272 | 299 | /** |
|
0 commit comments