Search in sources :

Example 1 with RouteLocator

use of org.springframework.cloud.gateway.route.RouteLocator in project spring-cloud-gateway by spring-cloud.

the class RouteBuilderTests method testASetOfRoutes.

@Test
public void testASetOfRoutes() {
    RouteLocator routeLocator = this.routeLocatorBuilder.routes().route("test1", r -> r.host("*.somehost.org").and().path("/somepath").filters(f -> f.addRequestHeader("header1", "header-value-1")).uri("http://someuri")).route("test2", r -> r.host("*.somehost2.org").filters(f -> f.addResponseHeader("header-response-1", "header-response-1")).uri("https://httpbin.org:9090")).build();
    StepVerifier.create(routeLocator.getRoutes()).expectNextMatches(r -> r.getId().equals("test1") && r.getFilters().size() == 1 && r.getUri().equals(URI.create("http://someuri:80"))).expectNextMatches(r -> r.getId().equals("test2") && r.getFilters().size() == 1 && r.getUri().equals(URI.create("https://httpbin.org:9090"))).expectComplete().verify();
}
Also used : Configuration(org.springframework.context.annotation.Configuration) StepVerifier(reactor.test.StepVerifier) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) RouteLocator(org.springframework.cloud.gateway.route.RouteLocator) SpringRunner(org.springframework.test.context.junit4.SpringRunner) URI(java.net.URI) RouteLocator(org.springframework.cloud.gateway.route.RouteLocator) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

URI (java.net.URI)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 EnableAutoConfiguration (org.springframework.boot.autoconfigure.EnableAutoConfiguration)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 RouteLocator (org.springframework.cloud.gateway.route.RouteLocator)1 Configuration (org.springframework.context.annotation.Configuration)1 SpringRunner (org.springframework.test.context.junit4.SpringRunner)1 StepVerifier (reactor.test.StepVerifier)1