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
63896485
Commit
63896485
authored
Feb 01, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix broken zuul tests.
parent
01fc27cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
24 deletions
+31
-24
FormZuulServletProxyApplicationTests.java
...ud/netflix/zuul/FormZuulServletProxyApplicationTests.java
+24
-24
SampleZuulProxyAppTestsWithHttpClient.java
...d/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java
+7
-0
No files found.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulServletProxyApplicationTests.java
View file @
63896485
...
...
@@ -20,7 +20,12 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.util.Map
;
import
org.junit.Ignore
;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -28,9 +33,9 @@ import org.springframework.boot.actuate.trace.InMemoryTraceRepository;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.test.IntegrationTest
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.cloud.netflix.ribbon.RibbonClient
;
import
org.springframework.cloud.netflix.ribbon.RibbonClients
;
import
org.springframework.cloud.netflix.ribbon.StaticServerList
;
...
...
@@ -44,7 +49,6 @@ import org.springframework.http.MediaType;
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.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -53,83 +57,79 @@ import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
import
com.netflix.zuul.ZuulFilter
;
import
lombok.extern.slf4j.Slf4j
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
lombok.extern.slf4j.Slf4j
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
FormZuulServletProxyApplication
.
class
)
@WebAppConfiguration
@IntegrationTest
({
"server.port:0"
,
"zuul.routes.simple:/simple/**"
})
@WebIntegrationTest
(
value
=
"zuul.routes.simple:/simple/**"
,
randomPort
=
true
)
@DirtiesContext
@Ignore
public
class
FormZuulServletProxyApplicationTests
{
@Value
(
"${local.server.port}"
)
private
int
port
;
@Before
public
void
setTestRequestcontext
()
{
RequestContext
context
=
new
RequestContext
();
RequestContext
.
testSetCurrentContext
(
context
);
}
@Test
public
void
postWithForm
()
{
MultiValueMap
<
String
,
String
>
form
=
new
LinkedMultiValueMap
<
String
,
String
>();
MultiValueMap
<
String
,
String
>
form
=
new
LinkedMultiValueMap
<>();
form
.
set
(
"foo"
,
"bar"
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
);
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/zuul/simple/form"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
form
,
headers
),
String
.
class
);
new
HttpEntity
<>(
form
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Posted! {foo=[bar]}"
,
result
.
getBody
());
}
@Test
public
void
postWithMultipartForm
()
{
MultiValueMap
<
String
,
String
>
form
=
new
LinkedMultiValueMap
<
String
,
String
>();
MultiValueMap
<
String
,
String
>
form
=
new
LinkedMultiValueMap
<>();
form
.
set
(
"foo"
,
"bar"
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
MULTIPART_FORM_DATA
);
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/zuul/simple/form"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
form
,
headers
),
String
.
class
);
new
HttpEntity
<>(
form
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Posted! {foo=[bar]}"
,
result
.
getBody
());
}
@Test
public
void
postWithMultipartFile
()
{
MultiValueMap
<
String
,
Object
>
form
=
new
LinkedMultiValueMap
<
String
,
Object
>();
MultiValueMap
<
String
,
Object
>
form
=
new
LinkedMultiValueMap
<>();
HttpHeaders
part
=
new
HttpHeaders
();
part
.
setContentType
(
MediaType
.
TEXT_PLAIN
);
part
.
setContentDispositionFormData
(
"file"
,
"foo.txt"
);
form
.
set
(
"foo"
,
new
HttpEntity
<
byte
[]
>(
"bar"
.
getBytes
(),
part
));
form
.
set
(
"foo"
,
new
HttpEntity
<>(
"bar"
.
getBytes
(),
part
));
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
MULTIPART_FORM_DATA
);
headers
.
set
(
"Transfer-Encoding"
,
"chunked"
);
headers
.
setContentLength
(-
1
);
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/zuul/simple/file"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
Object
>>(
form
,
headers
),
String
.
class
);
new
HttpEntity
<>(
form
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Posted! bar"
,
result
.
getBody
());
}
@Test
public
void
postWithUTF8Form
()
{
MultiValueMap
<
String
,
String
>
form
=
new
LinkedMultiValueMap
<
String
,
String
>();
MultiValueMap
<
String
,
String
>
form
=
new
LinkedMultiValueMap
<>();
form
.
set
(
"foo"
,
"bar"
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
+
"; charset=UTF-8"
));
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/zuul/simple/form"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
form
,
headers
),
String
.
class
);
new
HttpEntity
<>(
form
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Posted! {foo=[bar]}"
,
result
.
getBody
());
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java
View file @
63896485
...
...
@@ -21,6 +21,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -82,6 +83,12 @@ public class SampleZuulProxyAppTestsWithHttpClient {
@Autowired
private
RibbonCommandFactory
<?>
ribbonCommandFactory
;
@Before
public
void
setTestRequestcontext
()
{
RequestContext
context
=
new
RequestContext
();
RequestContext
.
testSetCurrentContext
(
context
);
}
private
String
getRoute
(
String
path
)
{
for
(
Route
route
:
this
.
routes
.
getRoutes
())
{
if
(
path
.
equals
(
route
.
getFullPath
()))
{
...
...
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