Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
0a689b50
Unverified
Commit
0a689b50
authored
Dec 20, 2017
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polish
parent
ac1ac4d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
52 deletions
+52
-52
PatternServiceRouteMapperIntegrationTests.java
.../discovery/PatternServiceRouteMapperIntegrationTests.java
+45
-52
LocationRewriteFilterTests.java
...netflix/zuul/filters/post/LocationRewriteFilterTests.java
+7
-0
No files found.
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/discovery/PatternServiceRouteMapperIntegrationTests.java
View file @
0a689b50
...
...
@@ -8,19 +8,17 @@ import org.junit.Before;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringBootConfiguration
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.web.server.LocalServerPort
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.netflix.ribbon.RibbonClient
;
import
org.springframework.cloud.netflix.ribbon.StaticServerList
;
import
org.springframework.cloud.netflix.zuul.EnableZuulProxy
;
import
org.springframework.cloud.netflix.zuul.RoutesEndpoint
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -39,21 +37,21 @@ import com.netflix.zuul.context.RequestContext;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
discovery
.
PatternServiceRouteMapperIntegrationTests
.
SERVICE_ID
;
import
static
org
.
springframework
.
boot
.
test
.
context
.
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
;
/**
* @author Stéphane Leroy
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
SampleCustomZuulProxyApplication
.
class
,
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
value
=
{
"spring.application.name=regex-test-application"
,
"spring.jmx.enabled=false"
,
@SpringBootTest
(
webEnvironment
=
RANDOM_PORT
,
properties
=
{
"spring.application.name=regex-test-application"
,
"spring.jmx.enabled=false"
,
"eureka.client.enabled=false"
})
@DirtiesContext
public
class
PatternServiceRouteMapperIntegrationTests
{
protected
static
final
String
SERVICE_ID
=
"domain-service-v1"
;
@
Value
(
"${local.server.port}"
)
@
LocalServerPort
private
int
port
;
@Autowired
...
...
@@ -94,49 +92,44 @@ public class PatternServiceRouteMapperIntegrationTests {
assertEquals
(
"Get 1"
,
result
.
getBody
());
}
}
@Configuration
@EnableAutoConfiguration
@RestController
@EnableZuulProxy
@RibbonClient
(
value
=
SERVICE_ID
,
configuration
=
SimpleRibbonClientConfiguration
.
class
)
class
SampleCustomZuulProxyApplication
{
@Bean
public
DiscoveryClient
discoveryClient
()
{
DiscoveryClient
discoveryClient
=
mock
(
DiscoveryClient
.
class
);
List
<
String
>
services
=
new
ArrayList
<>();
services
.
add
(
SERVICE_ID
);
when
(
discoveryClient
.
getServices
()).
thenReturn
(
services
);
return
discoveryClient
;
}
@RequestMapping
(
value
=
"/get/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
get
(
@PathVariable
String
id
)
{
return
"Get "
+
id
;
}
@Bean
public
PatternServiceRouteMapper
serviceRouteMapper
()
{
return
new
PatternServiceRouteMapper
(
"(?<domain>^.+)-(?<name>.+)-(?<version>v.+$)"
,
"${version}/${domain}/${name}"
);
}
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SampleCustomZuulProxyApplication
.
class
,
args
);
}
}
@Configuration
class
SimpleRibbonClientConfiguration
{
@Value
(
"${local.server.port}"
)
private
int
port
=
0
;
@Bean
public
ServerList
<
Server
>
ribbonServerList
()
{
return
new
StaticServerList
<>(
new
Server
(
"localhost"
,
this
.
port
));
@SpringBootConfiguration
@EnableAutoConfiguration
@RestController
@EnableZuulProxy
@RibbonClient
(
value
=
SERVICE_ID
,
configuration
=
SimpleRibbonClientConfiguration
.
class
)
protected
static
class
SampleCustomZuulProxyApplication
{
@Bean
public
DiscoveryClient
discoveryClient
()
{
DiscoveryClient
discoveryClient
=
mock
(
DiscoveryClient
.
class
);
List
<
String
>
services
=
new
ArrayList
<>();
services
.
add
(
SERVICE_ID
);
when
(
discoveryClient
.
getServices
()).
thenReturn
(
services
);
return
discoveryClient
;
}
@RequestMapping
(
value
=
"/get/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
get
(
@PathVariable
String
id
)
{
return
"Get "
+
id
;
}
@Bean
public
PatternServiceRouteMapper
serviceRouteMapper
()
{
return
new
PatternServiceRouteMapper
(
"(?<domain>^.+)-(?<name>.+)-(?<version>v.+$)"
,
"${version}/${domain}/${name}"
);
}
}
protected
static
class
SimpleRibbonClientConfiguration
{
@LocalServerPort
private
int
port
=
0
;
@Bean
public
ServerList
<
Server
>
ribbonServerList
()
{
return
new
StaticServerList
<>(
new
Server
(
"localhost"
,
this
.
port
));
}
}
}
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/post/LocationRewriteFilterTests.java
View file @
0a689b50
...
...
@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.zuul.filters.post;
import
com.netflix.util.Pair
;
import
com.netflix.zuul.context.RequestContext
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.cloud.netflix.zuul.filters.Route
;
...
...
@@ -57,6 +58,12 @@ public class LocationRewriteFilterTests {
RequestContext
.
testSetCurrentContext
(
context
);
}
@After
public
void
reset
()
{
RequestContext
.
getCurrentContext
().
clear
();
}
@Test
public
void
shouldRewriteLocationHeadersWithRoutePrefix
()
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment