|
23 | 23 | import java.util.Map; |
24 | 24 | import java.util.UUID; |
25 | 25 | import java.util.function.Predicate; |
| 26 | +import java.util.stream.Collectors; |
26 | 27 |
|
27 | 28 | import org.assertj.core.util.Maps; |
28 | 29 | import org.junit.jupiter.api.Assertions; |
@@ -193,6 +194,62 @@ public void testRefreshByGroup() { |
193 | 194 | }); |
194 | 195 | } |
195 | 196 |
|
| 197 | + @Test |
| 198 | + public void testOrderOfRefreshByGroup() { |
| 199 | + RouteDefinition testRouteDefinition = new RouteDefinition(); |
| 200 | + testRouteDefinition.setUri(URI.create("http://example.org")); |
| 201 | + testRouteDefinition.setOrder(1000); |
| 202 | + String group1 = "group-1_" + UUID.randomUUID(); |
| 203 | + testRouteDefinition.setMetadata(Map.of("groupBy", group1)); |
| 204 | + |
| 205 | + String routeId1 = "route-1_" + UUID.randomUUID(); |
| 206 | + testClient.post().uri("http://localhost:" + port + "/actuator/gateway/routes/" + routeId1) |
| 207 | + .accept(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(testRouteDefinition)).exchange() |
| 208 | + .expectStatus().isCreated(); |
| 209 | + |
| 210 | + RouteDefinition testRouteDefinition2 = new RouteDefinition(); |
| 211 | + testRouteDefinition2.setUri(URI.create("http://example.org")); |
| 212 | + testRouteDefinition2.setOrder(0); |
| 213 | + String group2 = "group-2_" + UUID.randomUUID(); |
| 214 | + testRouteDefinition2.setMetadata(Map.of("groupBy", group2)); |
| 215 | + String routeId2 = "route-2_" + UUID.randomUUID(); |
| 216 | + testClient.post().uri("http://localhost:" + port + "/actuator/gateway/routes/" + routeId2) |
| 217 | + .accept(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(testRouteDefinition2)).exchange() |
| 218 | + .expectStatus().isCreated(); |
| 219 | + |
| 220 | + testClient.post().uri("http://localhost:" + port + "/actuator/gateway/refresh?metadata=groupBy:" + group1) |
| 221 | + .exchange().expectStatus().isOk(); |
| 222 | + testClient.post().uri("http://localhost:" + port + "/actuator/gateway/refresh?metadata=groupBy:" + group2) |
| 223 | + .exchange().expectStatus().isOk(); |
| 224 | + |
| 225 | + testClient.get().uri("http://localhost:" + port + "/actuator/gateway/routes").exchange().expectStatus().isOk() |
| 226 | + .expectBodyList(Map.class).consumeWith(result -> { |
| 227 | + List<Map> responseBody = result.getResponseBody(); |
| 228 | + |
| 229 | + List ids = responseBody.stream() |
| 230 | + .map(route -> route.get("route_id")) |
| 231 | + .filter(id -> id.equals(routeId1) || id.equals(routeId2)) |
| 232 | + .collect(Collectors.toList()); |
| 233 | + assertThat(ids).containsExactly(routeId2, routeId1); |
| 234 | + }); |
| 235 | + |
| 236 | + testRouteDefinition2.setOrder(testRouteDefinition.getOrder() + 1); |
| 237 | + testClient.post().uri("http://localhost:" + port + "/actuator/gateway/routes/" + routeId2) |
| 238 | + .accept(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(testRouteDefinition2)).exchange() |
| 239 | + .expectStatus().isCreated(); |
| 240 | + testClient.post().uri("http://localhost:" + port + "/actuator/gateway/refresh?metadata=groupBy:" + group2) |
| 241 | + .exchange().expectStatus().isOk(); |
| 242 | + testClient.get().uri("http://localhost:" + port + "/actuator/gateway/routes").exchange().expectStatus().isOk() |
| 243 | + .expectBodyList(Map.class).consumeWith(result -> { |
| 244 | + List<Map> responseBody = result.getResponseBody(); |
| 245 | + List ids = responseBody.stream() |
| 246 | + .map(route -> route.get("route_id")) |
| 247 | + .filter(id -> id.equals(routeId1) || id.equals(routeId2)) |
| 248 | + .collect(Collectors.toList()); |
| 249 | + assertThat(ids).containsExactly(routeId1, routeId2); |
| 250 | + }); |
| 251 | + } |
| 252 | + |
196 | 253 | @Test |
197 | 254 | public void testRefreshByGroup_whenRouteDefinitionsAreDeleted() { |
198 | 255 | RouteDefinition testRouteDefinition = new RouteDefinition(); |
|
0 commit comments