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
1b190a32
Commit
1b190a32
authored
Feb 09, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored zuul proxy tests
parent
57ebc634
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
134 additions
and
0 deletions
+134
-0
RibbonRoutingFilter.java
...cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
+4
-0
SampleZuulProxyApplicationTests.java
...k/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
+0
-0
SampleZuulProxyWithHttpClientTests.java
...loud/netflix/zuul/SampleZuulProxyWithHttpClientTests.java
+130
-0
ZuulProxyTestBase.java
...springframework/cloud/netflix/zuul/ZuulProxyTestBase.java
+0
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
View file @
1b190a32
...
@@ -77,6 +77,10 @@ public class RibbonRoutingFilter extends ZuulFilter {
...
@@ -77,6 +77,10 @@ public class RibbonRoutingFilter extends ZuulFilter {
setResponse
(
response
);
setResponse
(
response
);
return
response
;
return
response
;
}
}
catch
(
ZuulException
ex
)
{
context
.
set
(
"error.status_code"
,
ex
.
nStatusCode
);
context
.
set
(
"error.exception"
,
ex
);
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
context
.
set
(
"error.status_code"
,
context
.
set
(
"error.status_code"
,
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
View file @
1b190a32
This diff is collapsed.
Click to expand it.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyWithHttpClientTests.java
0 → 100644
View file @
1b190a32
/*
* Copyright 2013-2015 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
.
netflix
.
zuul
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.IntegrationTest
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.cloud.netflix.ribbon.RibbonClient
;
import
org.springframework.cloud.netflix.ribbon.RibbonClients
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.apache.HttpClientRibbonCommandFactory
;
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
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SampleHttpClientZuulProxyApplication
.
class
)
@WebAppConfiguration
@IntegrationTest
({
"server.port: 0"
,
"zuul.routes.other: /test/**=http://localhost:7777/local"
,
"zuul.routes.another: /another/twolevel/**"
,
"zuul.routes.simple: /simple/**"
})
@DirtiesContext
public
class
SampleZuulProxyWithHttpClientTests
extends
ZuulProxyTestBase
{
@Test
public
void
patchOnSelfViaRibbonRoutingFilter
()
{
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/simple/local/1"
,
HttpMethod
.
PATCH
,
new
HttpEntity
<>(
"TestPatch"
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Patched 1!"
,
result
.
getBody
());
}
@Test
public
void
postOnSelfViaRibbonRoutingFilter
()
{
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/simple/local/1"
,
HttpMethod
.
POST
,
new
HttpEntity
<>(
"TestPost"
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Posted 1!"
,
result
.
getBody
());
}
@Test
public
void
deleteOnSelfViaRibbonRoutingFilter
()
{
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/simple/local/1"
,
HttpMethod
.
DELETE
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Deleted 1!"
,
result
.
getBody
());
}
@Test
public
void
patchOnSelfViaSimpleHostRoutingFilter
()
{
this
.
routes
.
addRoute
(
"/self/**"
,
"http://localhost:"
+
this
.
port
+
"/local"
);
this
.
endpoint
.
reset
();
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/self/1"
,
HttpMethod
.
PATCH
,
new
HttpEntity
<>(
"TestPatch"
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Patched 1!"
,
result
.
getBody
());
}
@Test
public
void
ribbonCommandFactoryOverridden
()
{
assertTrue
(
"ribbonCommandFactory not a MyRibbonCommandFactory"
,
this
.
ribbonCommandFactory
instanceof
HttpClientRibbonCommandFactory
);
}
}
// Don't use @SpringBootApplication because we don't want to component scan
@Configuration
@EnableAutoConfiguration
@RestController
@EnableZuulProxy
@RibbonClients
({
@RibbonClient
(
name
=
"simple"
,
configuration
=
SimpleRibbonClientConfiguration
.
class
),
@RibbonClient
(
name
=
"another"
,
configuration
=
AnotherRibbonClientConfiguration
.
class
)
})
class
SampleHttpClientZuulProxyApplication
extends
ZuulProxyTestBase
.
AbstractZuulProxyApplication
{
public
static
void
main
(
final
String
[]
args
)
{
SpringApplication
.
run
(
SampleZuulProxyApplication
.
class
,
args
);
}
@RequestMapping
(
value
=
"/local/{id}"
,
method
=
RequestMethod
.
PATCH
)
public
String
patch
(
@PathVariable
final
String
id
,
@RequestBody
final
String
body
)
{
return
"Patched "
+
id
+
"!"
;
}
@Bean
public
RibbonCommandFactory
<?>
ribbonCommandFactory
(
final
SpringClientFactory
clientFactory
)
{
return
new
HttpClientRibbonCommandFactory
(
clientFactory
);
}
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/
SampleZuulProxyAppTestsWithHttpClient
.java
→
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/
ZuulProxyTestBase
.java
View file @
1b190a32
This diff is collapsed.
Click to expand it.
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