-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checks for null list if there are no query parameters.
fixes gh-374
- Loading branch information
1 parent
6a4f608
commit 6ceb65b
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
.../org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactoryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2013-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.springframework.cloud.gateway.handler.predicate; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.SpringBootConfiguration; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.rule.OutputCapture; | ||
import org.springframework.cloud.gateway.route.RouteLocator; | ||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; | ||
import org.springframework.cloud.gateway.test.BaseWebClientTests; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
@DirtiesContext | ||
public class QueryRoutePredicateFactoryTests extends BaseWebClientTests { | ||
|
||
@Rule | ||
public OutputCapture output = new OutputCapture(); | ||
|
||
@Test | ||
public void noQueryParamWorks() { | ||
testClient.get().uri("/get") | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectHeader().valueEquals(ROUTE_ID_HEADER, "default_path_to_httpbin");; | ||
|
||
output.expect(not(containsString("Error applying predicate for route: foo_query_param"))); | ||
} | ||
|
||
@Test | ||
public void queryParamWorks() { | ||
testClient.get().uri("/get?foo=bar") | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectHeader().valueEquals(ROUTE_ID_HEADER, "foo_query_param");; | ||
} | ||
|
||
@EnableAutoConfiguration | ||
@SpringBootConfiguration | ||
@Import(DefaultTestConfig.class) | ||
public static class TestConfig { | ||
|
||
@Value("${test.uri}") | ||
private String uri; | ||
|
||
@Bean | ||
RouteLocator queryRouteLocator(RouteLocatorBuilder builder) { | ||
return builder.routes() | ||
.route("foo_query_param", r -> | ||
r.query("foo", "bar") | ||
.filters(f -> f.prefixPath("/httpbin")) | ||
.uri(uri)) | ||
.build(); | ||
} | ||
} | ||
|
||
} |