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) {
|
||||
new SpringApplicationBuilder(WebFilterGatewayApplication.class)
|
||||
.profiles("webfilters")
|
||||
.run(args);
|
||||
.profiles("webfilters")
|
||||
.run(args);
|
||||
}
|
||||
|
||||
}
|
|
@ -14,19 +14,19 @@ public class ModifyBodyRouteConfig {
|
|||
@Bean
|
||||
public RouteLocator routes(RouteLocatorBuilder builder) {
|
||||
return builder.routes()
|
||||
.route("modify_request_body", r -> r.path("/post")
|
||||
.filters(f -> f.modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,
|
||||
(exchange, s) -> Mono.just(new Hello(s.toUpperCase())))).uri("https://httpbin.org"))
|
||||
.build();
|
||||
.route("modify_request_body", r -> r.path("/post")
|
||||
.filters(f -> f.modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,
|
||||
(exchange, s) -> Mono.just(new Hello(s.toUpperCase())))).uri("https://httpbin.org"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RouteLocator responseRoutes(RouteLocatorBuilder builder) {
|
||||
return builder.routes()
|
||||
.route("modify_response_body", r -> r.path("/put/**")
|
||||
.filters(f -> f.modifyResponseBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,
|
||||
(exchange, s) -> Mono.just(new Hello("New Body")))).uri("https://httpbin.org"))
|
||||
.build();
|
||||
.route("modify_response_body", r -> r.path("/put/**")
|
||||
.filters(f -> f.modifyResponseBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,
|
||||
(exchange, s) -> Mono.just(new Hello("New Body")))).uri("https://httpbin.org"))
|
||||
.build();
|
||||
}
|
||||
|
||||
static class Hello {
|
||||
|
|
|
@ -33,23 +33,23 @@ public class WebFilterFactoriesLiveTest {
|
|||
|
||||
@Autowired
|
||||
private WebTestClient client;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@BeforeEach
|
||||
public void configureClient() {
|
||||
client = WebTestClient.bindToServer()
|
||||
.baseUrl("http://localhost:" + port)
|
||||
.build();
|
||||
.baseUrl("http://localhost:" + port)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
|
||||
|
||||
JSONObject json = new JSONObject(response.getBody());
|
||||
JSONObject headers = json.getJSONObject("headers");
|
||||
assertThat(headers.getString("My-Header-Good")).isEqualTo("Good");
|
||||
|
@ -63,76 +63,73 @@ public class WebFilterFactoriesLiveTest {
|
|||
@Test
|
||||
public void whenCallHeaderPostThroughGateway_thenAllHTTPResponseHeadersAreSet() {
|
||||
ResponseSpec response = client.post()
|
||||
.uri("/header/post")
|
||||
.exchange();
|
||||
.uri("/header/post")
|
||||
.exchange();
|
||||
|
||||
response.expectStatus()
|
||||
.isOk()
|
||||
.expectHeader()
|
||||
.valueEquals("My-Header-Rewrite", "password=***")
|
||||
.expectHeader()
|
||||
.valueEquals("My-Header-Set", "Set")
|
||||
.expectHeader()
|
||||
.valueEquals("My-Header-Good", "Good")
|
||||
.expectHeader()
|
||||
.doesNotExist("My-Header-Remove");
|
||||
.isOk()
|
||||
.expectHeader()
|
||||
.valueEquals("My-Header-Rewrite", "password=***")
|
||||
.expectHeader()
|
||||
.valueEquals("My-Header-Set", "Set")
|
||||
.expectHeader()
|
||||
.valueEquals("My-Header-Good", "Good")
|
||||
.expectHeader()
|
||||
.doesNotExist("My-Header-Remove");
|
||||
}
|
||||
|
||||
@Test
|
||||
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());
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(url,
|
||||
HttpMethod.POST, entity, String.class);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
|
||||
|
||||
JSONObject json = new JSONObject(response.getBody());
|
||||
JSONObject data = json.getJSONObject("json");
|
||||
assertThat(data.getString("message")).isEqualTo("CONTENT");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
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());
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(url,
|
||||
HttpMethod.PUT, entity, String.class);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, entity, String.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
|
||||
|
||||
JSONObject json = new JSONObject(response.getBody());
|
||||
assertThat(json.getString("message")).isEqualTo("New Body");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenCallDeleteThroughGateway_thenIsUnauthorizedCodeIsSet() {
|
||||
ResponseSpec response = client.delete()
|
||||
.uri("/delete")
|
||||
.exchange();
|
||||
.uri("/delete")
|
||||
.exchange();
|
||||
|
||||
response.expectStatus()
|
||||
.isUnauthorized();
|
||||
.isUnauthorized();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallFakePostThroughGateway_thenIsUnauthorizedCodeIsSet() {
|
||||
ResponseSpec response = client.post()
|
||||
.uri("/fake/post")
|
||||
.exchange();
|
||||
.uri("/fake/post")
|
||||
.exchange();
|
||||
|
||||
response.expectStatus()
|
||||
.is3xxRedirection();
|
||||
.is3xxRedirection();
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
|
||||
|
||||
JSONObject json = new JSONObject(response.getBody());
|
||||
assertThat(json.getString("url")).contains("anything");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue