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
7237275f
Unverified
Commit
7237275f
authored
Feb 10, 2017
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polish
parent
3e7b1969
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
32 deletions
+32
-32
SendResponseFilterTests.java
...ud/netflix/zuul/filters/post/SendResponseFilterTests.java
+32
-32
No files found.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilterTests.java
View file @
7237275f
...
...
@@ -16,18 +16,6 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
post
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Matchers
.
anyInt
;
import
static
org
.
mockito
.
Matchers
.
isA
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
support
.
FilterConstants
.
X_ZUUL_DEBUG_HEADER
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
java.io.ByteArrayInputStream
;
import
java.io.Closeable
;
import
java.io.IOException
;
...
...
@@ -51,6 +39,18 @@ import com.netflix.zuul.constants.ZuulConstants;
import
com.netflix.zuul.context.Debug
;
import
com.netflix.zuul.context.RequestContext
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Matchers
.
anyInt
;
import
static
org
.
mockito
.
Matchers
.
isA
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
support
.
FilterConstants
.
X_ZUUL_DEBUG_HEADER
;
/**
* @author Spencer Gibb
*/
...
...
@@ -108,33 +108,33 @@ public class SendResponseFilterTests {
assertThat
(
"wrong origin content length"
,
contentLength
,
equalTo
(
"6"
));
}
@Test
@Test
public
void
closeResponseOutpusStreamError
()
throws
Exception
{
HttpServletResponse
response
=
mock
(
HttpServletResponse
.
class
);
HttpServletResponse
response
=
mock
(
HttpServletResponse
.
class
);
RequestContext
context
=
new
RequestContext
();
context
.
setRequest
(
new
MockHttpServletRequest
());
context
.
setResponse
(
response
);
context
.
setResponseDataStream
(
new
ByteArrayInputStream
(
"Hello\n"
.
getBytes
(
"UTF-8"
)));
Closeable
zuulResponse
=
mock
(
Closeable
.
class
);
context
.
set
(
"zuulResponse"
,
zuulResponse
);
RequestContext
.
testSetCurrentContext
(
context
);
RequestContext
context
=
new
RequestContext
();
context
.
setRequest
(
new
MockHttpServletRequest
());
context
.
setResponse
(
response
);
context
.
setResponseDataStream
(
new
ByteArrayInputStream
(
"Hello\n"
.
getBytes
(
"UTF-8"
)));
Closeable
zuulResponse
=
mock
(
Closeable
.
class
);
context
.
set
(
"zuulResponse"
,
zuulResponse
);
RequestContext
.
testSetCurrentContext
(
context
);
SendResponseFilter
filter
=
new
SendResponseFilter
();
SendResponseFilter
filter
=
new
SendResponseFilter
();
ServletOutputStream
zuuloutputstream
=
mock
(
ServletOutputStream
.
class
);
doThrow
(
new
IOException
(
"Response to client closed"
)).
when
(
zuuloutputstream
).
write
(
isA
(
byte
[].
class
),
anyInt
(),
anyInt
());
ServletOutputStream
zuuloutputstream
=
mock
(
ServletOutputStream
.
class
);
doThrow
(
new
IOException
(
"Response to client closed"
)).
when
(
zuuloutputstream
).
write
(
isA
(
byte
[].
class
),
anyInt
(),
anyInt
());
when
(
response
.
getOutputStream
()).
thenReturn
(
zuuloutputstream
);
when
(
response
.
getOutputStream
()).
thenReturn
(
zuuloutputstream
);
try
{
filter
.
run
();
}
catch
(
UndeclaredThrowableException
ex
)
{
assertThat
(
ex
.
getUndeclaredThrowable
().
getMessage
(),
is
(
"Response to client closed"
));
}
try
{
filter
.
run
();
}
catch
(
UndeclaredThrowableException
ex
)
{
assertThat
(
ex
.
getUndeclaredThrowable
().
getMessage
(),
is
(
"Response to client closed"
));
}
verify
(
zuulResponse
).
close
();
}
verify
(
zuulResponse
).
close
();
}
private
void
runFilter
(
String
characterEncoding
,
String
content
,
boolean
streamContent
)
throws
Exception
{
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
...
...
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