Use a two-space indent when continuing a line
This commit is contained in:
parent
b25323afb2
commit
44485bcc48
|
@ -8,8 +8,8 @@ public class WebFilterGatewayApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new SpringApplicationBuilder(WebFilterGatewayApplication.class)
|
new SpringApplicationBuilder(WebFilterGatewayApplication.class)
|
||||||
.profiles("webfilters")
|
.profiles("webfilters")
|
||||||
.run(args);
|
.run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -14,19 +14,19 @@ public class ModifyBodyRouteConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public RouteLocator routes(RouteLocatorBuilder builder) {
|
public RouteLocator routes(RouteLocatorBuilder builder) {
|
||||||
return builder.routes()
|
return builder.routes()
|
||||||
.route("modify_request_body", r -> r.path("/post")
|
.route("modify_request_body", r -> r.path("/post")
|
||||||
.filters(f -> f.modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,
|
.filters(f -> f.modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,
|
||||||
(exchange, s) -> Mono.just(new Hello(s.toUpperCase())))).uri("https://httpbin.org"))
|
(exchange, s) -> Mono.just(new Hello(s.toUpperCase())))).uri("https://httpbin.org"))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RouteLocator responseRoutes(RouteLocatorBuilder builder) {
|
public RouteLocator responseRoutes(RouteLocatorBuilder builder) {
|
||||||
return builder.routes()
|
return builder.routes()
|
||||||
.route("modify_response_body", r -> r.path("/put/**")
|
.route("modify_response_body", r -> r.path("/put/**")
|
||||||
.filters(f -> f.modifyResponseBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,
|
.filters(f -> f.modifyResponseBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,
|
||||||
(exchange, s) -> Mono.just(new Hello("New Body")))).uri("https://httpbin.org"))
|
(exchange, s) -> Mono.just(new Hello("New Body")))).uri("https://httpbin.org"))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Hello {
|
static class Hello {
|
||||||
|
|
|
@ -33,23 +33,23 @@ public class WebFilterFactoriesLiveTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private WebTestClient client;
|
private WebTestClient client;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TestRestTemplate restTemplate;
|
private TestRestTemplate restTemplate;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void configureClient() {
|
public void configureClient() {
|
||||||
client = WebTestClient.bindToServer()
|
client = WebTestClient.bindToServer()
|
||||||
.baseUrl("http://localhost:" + port)
|
.baseUrl("http://localhost:" + port)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCallGetThroughGateway_thenAllHTTPRequestHeadersParametersAreSet() throws JSONException {
|
public void whenCallGetThroughGateway_thenAllHTTPRequestHeadersParametersAreSet() throws JSONException {
|
||||||
String url = "http://localhost:" + port + "/get";
|
String url = "http://localhost:" + port + "/get";
|
||||||
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
||||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
|
||||||
JSONObject json = new JSONObject(response.getBody());
|
JSONObject json = new JSONObject(response.getBody());
|
||||||
JSONObject headers = json.getJSONObject("headers");
|
JSONObject headers = json.getJSONObject("headers");
|
||||||
assertThat(headers.getString("My-Header-Good")).isEqualTo("Good");
|
assertThat(headers.getString("My-Header-Good")).isEqualTo("Good");
|
||||||
|
@ -63,76 +63,73 @@ public class WebFilterFactoriesLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenCallHeaderPostThroughGateway_thenAllHTTPResponseHeadersAreSet() {
|
public void whenCallHeaderPostThroughGateway_thenAllHTTPResponseHeadersAreSet() {
|
||||||
ResponseSpec response = client.post()
|
ResponseSpec response = client.post()
|
||||||
.uri("/header/post")
|
.uri("/header/post")
|
||||||
.exchange();
|
.exchange();
|
||||||
|
|
||||||
response.expectStatus()
|
response.expectStatus()
|
||||||
.isOk()
|
.isOk()
|
||||||
.expectHeader()
|
.expectHeader()
|
||||||
.valueEquals("My-Header-Rewrite", "password=***")
|
.valueEquals("My-Header-Rewrite", "password=***")
|
||||||
.expectHeader()
|
.expectHeader()
|
||||||
.valueEquals("My-Header-Set", "Set")
|
.valueEquals("My-Header-Set", "Set")
|
||||||
.expectHeader()
|
.expectHeader()
|
||||||
.valueEquals("My-Header-Good", "Good")
|
.valueEquals("My-Header-Good", "Good")
|
||||||
.expectHeader()
|
.expectHeader()
|
||||||
.doesNotExist("My-Header-Remove");
|
.doesNotExist("My-Header-Remove");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCallPostThroughGateway_thenBodyIsRetrieved() throws JSONException {
|
public void whenCallPostThroughGateway_thenBodyIsRetrieved() throws JSONException {
|
||||||
String url = "http://localhost:" + port + "/post";
|
String url = "http://localhost:" + port + "/post";
|
||||||
|
|
||||||
HttpEntity<String> entity = new HttpEntity<>("content", new HttpHeaders());
|
HttpEntity<String> entity = new HttpEntity<>("content", new HttpHeaders());
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.exchange(url,
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
|
||||||
HttpMethod.POST, entity, String.class);
|
|
||||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
|
||||||
JSONObject json = new JSONObject(response.getBody());
|
JSONObject json = new JSONObject(response.getBody());
|
||||||
JSONObject data = json.getJSONObject("json");
|
JSONObject data = json.getJSONObject("json");
|
||||||
assertThat(data.getString("message")).isEqualTo("CONTENT");
|
assertThat(data.getString("message")).isEqualTo("CONTENT");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCallPutThroughGateway_thenBodyIsRetrieved() throws JSONException {
|
public void whenCallPutThroughGateway_thenBodyIsRetrieved() throws JSONException {
|
||||||
String url = "http://localhost:" + port + "/put";
|
String url = "http://localhost:" + port + "/put";
|
||||||
|
|
||||||
HttpEntity<String> entity = new HttpEntity<>("CONTENT", new HttpHeaders());
|
HttpEntity<String> entity = new HttpEntity<>("CONTENT", new HttpHeaders());
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.exchange(url,
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, entity, String.class);
|
||||||
HttpMethod.PUT, entity, String.class);
|
|
||||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
|
||||||
JSONObject json = new JSONObject(response.getBody());
|
JSONObject json = new JSONObject(response.getBody());
|
||||||
assertThat(json.getString("message")).isEqualTo("New Body");
|
assertThat(json.getString("message")).isEqualTo("New Body");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCallDeleteThroughGateway_thenIsUnauthorizedCodeIsSet() {
|
public void whenCallDeleteThroughGateway_thenIsUnauthorizedCodeIsSet() {
|
||||||
ResponseSpec response = client.delete()
|
ResponseSpec response = client.delete()
|
||||||
.uri("/delete")
|
.uri("/delete")
|
||||||
.exchange();
|
.exchange();
|
||||||
|
|
||||||
response.expectStatus()
|
response.expectStatus()
|
||||||
.isUnauthorized();
|
.isUnauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCallFakePostThroughGateway_thenIsUnauthorizedCodeIsSet() {
|
public void whenCallFakePostThroughGateway_thenIsUnauthorizedCodeIsSet() {
|
||||||
ResponseSpec response = client.post()
|
ResponseSpec response = client.post()
|
||||||
.uri("/fake/post")
|
.uri("/fake/post")
|
||||||
.exchange();
|
.exchange();
|
||||||
|
|
||||||
response.expectStatus()
|
response.expectStatus()
|
||||||
.is3xxRedirection();
|
.is3xxRedirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCallStatus504ThroughGateway_thenCircuitBreakerIsExecuted() throws JSONException {
|
public void whenCallStatus504ThroughGateway_thenCircuitBreakerIsExecuted() throws JSONException {
|
||||||
String url = "http://localhost:" + port + "/status/504";
|
String url = "http://localhost:" + port + "/status/504";
|
||||||
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
||||||
|
|
||||||
JSONObject json = new JSONObject(response.getBody());
|
JSONObject json = new JSONObject(response.getBody());
|
||||||
assertThat(json.getString("url")).contains("anything");
|
assertThat(json.getString("url")).contains("anything");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue