|
| 1 | +package org.codemental.samples.webflux.java.http.adapter.integration.test; |
| 2 | + |
| 3 | +import com.consol.citrus.annotations.CitrusTest; |
| 4 | +import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner; |
| 5 | +import com.consol.citrus.http.client.HttpClient; |
| 6 | +import com.consol.citrus.http.server.HttpServer; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import org.springframework.http.HttpStatus; |
| 9 | +import org.springframework.http.MediaType; |
| 10 | +import org.testng.annotations.Test; |
| 11 | + |
| 12 | +@Test |
| 13 | +public class InboundApiControllerIT extends TestNGCitrusTestRunner { |
| 14 | + |
| 15 | + @Autowired |
| 16 | + private HttpClient httpClient; |
| 17 | + @Autowired |
| 18 | + private HttpServer httpServer; |
| 19 | + |
| 20 | + @CitrusTest |
| 21 | + public void okTest() { |
| 22 | + http(action -> action.client(httpClient) |
| 23 | + .send() |
| 24 | + .post("inbound") |
| 25 | + .payload("{" + |
| 26 | + "\"userName\": \"Bruce.Wayne\"," + |
| 27 | + "\"operation\": \"call-a-pizza\"" + |
| 28 | + "}") |
| 29 | + .fork(true)); |
| 30 | + |
| 31 | + http(action -> action.server(httpServer) |
| 32 | + .receive() |
| 33 | + .post("/api") |
| 34 | + .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE) |
| 35 | + .payload("{" + |
| 36 | + "\"information\": \"User: Bruce.Wayne called operation: call-a-pizza\"," + |
| 37 | + "\"timestamp\": \"@ignore@\"" + |
| 38 | + "}")); |
| 39 | + |
| 40 | + http(action -> action.server(httpServer) |
| 41 | + .respond(HttpStatus.OK) |
| 42 | + .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE) |
| 43 | + .payload("{" + |
| 44 | + "\"allowed\": true" + |
| 45 | + "}")); |
| 46 | + |
| 47 | + http(action -> action.client(httpClient) |
| 48 | + .receive() |
| 49 | + .response(HttpStatus.OK) |
| 50 | + .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE) |
| 51 | + .payload("{" + |
| 52 | + "\"success\": true" + |
| 53 | + "}")); |
| 54 | + } |
| 55 | + |
| 56 | + @CitrusTest |
| 57 | + public void timeoutTest() { |
| 58 | + http(action -> action.client(httpClient) |
| 59 | + .send() |
| 60 | + .post("inbound") |
| 61 | + .payload("{" + |
| 62 | + "\"userName\": \"Bruce.Wayne\"," + |
| 63 | + "\"operation\": \"call-a-pizza\"" + |
| 64 | + "}") |
| 65 | + .fork(true)); |
| 66 | + |
| 67 | + http(action -> action.server(httpServer) |
| 68 | + .receive() |
| 69 | + .post("/api") |
| 70 | + .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE) |
| 71 | + .payload("{" + |
| 72 | + "\"information\": \"User: Bruce.Wayne called operation: call-a-pizza\"," + |
| 73 | + "\"timestamp\": \"@ignore@\"" + |
| 74 | + "}")); |
| 75 | + |
| 76 | + //we send no response here from the backend |
| 77 | + |
| 78 | + http(action -> action.client(httpClient) |
| 79 | + .receive() |
| 80 | + .response(HttpStatus.GATEWAY_TIMEOUT) |
| 81 | + .timeout(10000) |
| 82 | + .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); |
| 83 | + } |
| 84 | + |
| 85 | + @CitrusTest |
| 86 | + public void connectionRefusedTest() { |
| 87 | + httpServer.stop(); |
| 88 | + |
| 89 | + http(action -> action.client(httpClient) |
| 90 | + .send() |
| 91 | + .post("inbound") |
| 92 | + .payload("{" + |
| 93 | + "\"userName\": \"Bruce.Wayne\"," + |
| 94 | + "\"operation\": \"call-a-pizza\"" + |
| 95 | + "}") |
| 96 | + .fork(true)); |
| 97 | + |
| 98 | + http(action -> action.client(httpClient) |
| 99 | + .receive() |
| 100 | + .response(HttpStatus.GATEWAY_TIMEOUT) |
| 101 | + .timeout(2000) |
| 102 | + .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); |
| 103 | + |
| 104 | + httpServer.start(); |
| 105 | + } |
| 106 | +} |
0 commit comments