Browse Source

Formatting

pull/2943/head
spencergibb 2 years ago
parent
commit
b35e8cc3ed
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 12
      spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/actuate/AbstractGatewayControllerEndpoint.java
  2. 25
      spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java

12
spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/actuate/AbstractGatewayControllerEndpoint.java

@ -174,15 +174,15 @@ public class AbstractGatewayControllerEndpoint implements ApplicationEventPublis @@ -174,15 +174,15 @@ public class AbstractGatewayControllerEndpoint implements ApplicationEventPublis
});
return Flux.fromIterable(routes)
.flatMap(routeDefinition -> this.routeDefinitionWriter.save(Mono.just(routeDefinition).map(r -> {
log.debug("Saving route: " + routeDefinition);
return r;
}))).then(Mono.defer(() -> Mono.just(ResponseEntity.ok().build())))
.switchIfEmpty(Mono.defer(() -> Mono.just(ResponseEntity.badRequest().build())));
.flatMap(routeDefinition -> this.routeDefinitionWriter.save(Mono.just(routeDefinition).map(r -> {
log.debug("Saving route: " + routeDefinition);
return r;
}))).then(Mono.defer(() -> Mono.just(ResponseEntity.ok().build())))
.switchIfEmpty(Mono.defer(() -> Mono.just(ResponseEntity.badRequest().build())));
}
private void validateRouteId(RouteDefinition routeDefinition) {
if(routeDefinition.getId() == null) {
if (routeDefinition.getId() == null) {
handleError("Saving multiple routes require specifying the ID for every route");
}
}

25
spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java

@ -339,19 +339,17 @@ public class GatewayControllerEndpointTests { @@ -339,19 +339,17 @@ public class GatewayControllerEndpointTests {
PredicateDefinition hostRoutePredicateDefinition2 = new PredicateDefinition("Host=myhost-2.org");
PredicateDefinition methodRoutePredicateDefinition2 = new PredicateDefinition("Method=GET");
PredicateDefinition testPredicateDefinition2 = new PredicateDefinition("Test=value-2");
testRouteDefinition2.setPredicates(
Arrays.asList(hostRoutePredicateDefinition2, methodRoutePredicateDefinition2, testPredicateDefinition2)
);
testRouteDefinition2.setPredicates(Arrays.asList(hostRoutePredicateDefinition2, methodRoutePredicateDefinition2,
testPredicateDefinition2));
List<RouteDefinition> multipleRouteDefs = List.of(testRouteDefinition, testRouteDefinition2);
testClient.post().uri("http://localhost:" + port + "/actuator/gateway/routes")
.accept(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(multipleRouteDefs)).exchange()
.expectStatus().isOk();
.accept(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(multipleRouteDefs)).exchange()
.expectStatus().isOk();
testClient.get().uri("http://localhost:" + port + "/actuator/gateway/routedefinitions")
.accept(MediaType.APPLICATION_JSON).exchange()
.expectBody()
.jsonPath("[?(@.id in ['%s','%s'])].id".formatted(routeId1, routeId2)).exists();
.accept(MediaType.APPLICATION_JSON).exchange().expectBody()
.jsonPath("[?(@.id in ['%s','%s'])].id".formatted(routeId1, routeId2)).exists();
}
@Test
@ -382,15 +380,14 @@ public class GatewayControllerEndpointTests { @@ -382,15 +380,14 @@ public class GatewayControllerEndpointTests {
List<RouteDefinition> multipleRouteDefs = List.of(testRouteDefinition, testRouteDefinition2);
testClient.post().uri("http://localhost:" + port + "/actuator/gateway/routes")
.accept(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(multipleRouteDefs)).exchange()
.expectStatus().is4xxClientError();
.accept(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(multipleRouteDefs)).exchange()
.expectStatus().is4xxClientError();
testClient.get().uri("http://localhost:" + port + "/actuator/gateway/routedefinitions")
.accept(MediaType.APPLICATION_JSON).exchange()
.expectBody()
.jsonPath("[?(@.id in ['%s','%s'])].id".formatted(routeId1, routeId2)).doesNotExist();
.accept(MediaType.APPLICATION_JSON).exchange().expectBody()
.jsonPath("[?(@.id in ['%s','%s'])].id".formatted(routeId1, routeId2)).doesNotExist();
}
@Test
public void testPostValidShortcutRouteDefinition() {
RouteDefinition testRouteDefinition = new RouteDefinition();

Loading…
Cancel
Save