类 ContentResultMatchers
java.lang.Object
cn.taketoday.test.web.servlet.result.ContentResultMatchers
Factory for response content assertions.
An instance of this class is typically accessed via
MockMvcResultMatchers.content().
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Sam Brannen
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明bytes(byte[] expectedContent) Assert the response body content as a byte array.contentType(cn.taketoday.http.MediaType contentType) Assert the ServletResponse content type after parsing it as a MediaType.contentType(String contentType) Assert the ServletResponse content type.contentTypeCompatibleWith(cn.taketoday.http.MediaType contentType) Assert the ServletResponse content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType).contentTypeCompatibleWith(String contentType) Assert the ServletResponse content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType).Assert the character encoding in the ServletResponse.Assert the character encoding in the ServletResponse.Parse the expected and actual strings as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting with a lenient checking (extensible, and non-strict array ordering).Parse the response content and the given string as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting.Parse the response content asNodeand apply the given HamcrestMatcher.Parse the response content asDOMSourceand apply the given HamcrestMatcher.Assert the response body content as a String.Assert the response body content with a HamcrestMatcher.Parse the response content and the given string as XML and assert the two are "similar" - i.e. they contain the same elements and attributes regardless of order.
-
字段详细资料
-
xmlHelper
-
jsonHelper
-
-
构造器详细资料
-
ContentResultMatchers
protected ContentResultMatchers()Protected constructor. UseMockMvcResultMatchers.content().
-
-
方法详细资料
-
contentType
Assert the ServletResponse content type. The given content type must fully match including type, subtype, and parameters. For checking only the type and subtype seecontentTypeCompatibleWith(String). -
contentType
Assert the ServletResponse content type after parsing it as a MediaType. The given content type must fully match including type, subtype, and parameters. For checking only the type and subtype seecontentTypeCompatibleWith(MediaType). -
contentTypeCompatibleWith
Assert the ServletResponse content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType). -
contentTypeCompatibleWith
Assert the ServletResponse content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType). -
encoding
Assert the character encoding in the ServletResponse. -
encoding
Assert the character encoding in the ServletResponse.- 另请参阅:
-
ServletResponse.getCharacterEncoding()
-
string
Assert the response body content with a HamcrestMatcher.mockMvc.perform(get("/path")) .andExpect(content().string(containsString("text"))); -
string
Assert the response body content as a String. -
bytes
Assert the response body content as a byte array. -
xml
Parse the response content and the given string as XML and assert the two are "similar" - i.e. they contain the same elements and attributes regardless of order.Use of this matcher requires the XMLUnit library.
- 参数:
xmlContent- the expected XML content- 另请参阅:
-
node
Parse the response content asNodeand apply the given HamcrestMatcher. -
source
Parse the response content asDOMSourceand apply the given HamcrestMatcher.- 另请参阅:
-
json
Parse the expected and actual strings as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting with a lenient checking (extensible, and non-strict array ordering).- 参数:
jsonContent- the expected JSON content
-
json
Parse the response content and the given string as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting.Can compare in two modes, depending on
strictparameter value:true: strict checking. Not extensible, and strict array ordering.false: lenient checking. Extensible, and non-strict array ordering.
Use of this matcher requires the JSONassert library.
- 参数:
jsonContent- the expected JSON contentstrict- enables strict checking
-