本文整理汇总了Java中org.springframework.restdocs.mockmvc.MockMvcRestDocumentation类的典型用法代码示例。如果您正苦于以下问题:Java MockMvcRestDocumentation类的具体用法?Java MockMvcRestDocumentation怎么用?Java MockMvcRestDocumentation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockMvcRestDocumentation类属于org.springframework.restdocs.mockmvc包,在下文中一共展示了MockMvcRestDocumentation类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: document
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
public static RestDocumentationResultHandler document(String identifier,
String description,
boolean privateResource,
OperationRequestPreprocessor requestPreprocessor,
OperationResponsePreprocessor responsePreprocessor,
Function<List<Snippet>, List<Snippet>> snippetFilter,
Snippet... snippets) {
Snippet[] enhancedSnippets = enhanceSnippetsWithRaml(description, privateResource, snippetFilter, snippets);
if (requestPreprocessor != null && responsePreprocessor != null) {
return MockMvcRestDocumentation.document(identifier, requestPreprocessor, responsePreprocessor, enhancedSnippets);
} else if (requestPreprocessor != null) {
return MockMvcRestDocumentation.document(identifier, requestPreprocessor, enhancedSnippets);
} else if (responsePreprocessor != null) {
return MockMvcRestDocumentation.document(identifier, responsePreprocessor, enhancedSnippets);
}
return MockMvcRestDocumentation.document(identifier, enhancedSnippets);
}
示例2: should_grant_a_beer_when_person_is_old_enough
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
@Test
public void should_grant_a_beer_when_person_is_old_enough() throws Exception {
PersonToCheck personToCheck = new PersonToCheck(34);
//remove::start[]
mockMvc.perform(MockMvcRequestBuilders.post("/check")
.contentType(MediaType.APPLICATION_JSON)
.content(json.write(personToCheck).getJson()))
.andExpect(jsonPath("$.status").value("OK"))
.andDo(WireMockRestDocs.verify()
.jsonPath("$[?(@.age >= 20)]")
.contentType(MediaType.valueOf("application/json"))
.stub("shouldGrantABeerIfOldEnough"))
.andDo(MockMvcRestDocumentation.document("shouldGrantABeerIfOldEnough",
SpringCloudContractRestDocs.dslContract()));
//remove::end[]
}
开发者ID:spring-cloud-samples,项目名称:spring-cloud-contract-samples,代码行数:17,代码来源:ProducerControllerTests.java
示例3: should_reject_a_beer_when_person_is_too_young
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
@Test
public void should_reject_a_beer_when_person_is_too_young() throws Exception {
PersonToCheck personToCheck = new PersonToCheck(10);
//remove::start[]
mockMvc.perform(MockMvcRequestBuilders.post("/check")
.contentType(MediaType.APPLICATION_JSON)
.content(json.write(personToCheck).getJson()))
.andExpect(jsonPath("$.status").value("NOT_OK"))
.andDo(WireMockRestDocs.verify()
.jsonPath("$[?(@.age < 20)]")
.contentType(MediaType.valueOf("application/json"))
.stub("shouldRejectABeerIfTooYoung"))
.andDo(MockMvcRestDocumentation.document("shouldRejectABeerIfTooYoung",
SpringCloudContractRestDocs.dslContract()));
//remove::end[]
}
开发者ID:spring-cloud-samples,项目名称:spring-cloud-contract-samples,代码行数:17,代码来源:ProducerControllerTests.java
示例4: getCustomerByIdShouldReturnCustomer
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
@Test
public void getCustomerByIdShouldReturnCustomer() throws Exception {
Mockito
.when(this.customerRepository.findOne(1L))
.thenReturn(c1);
mockMvc.perform(MockMvcRequestBuilders.get("/customers/1"))
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
.andExpect(MockMvcResultMatchers.jsonPath("@.id").value(1L))
.andDo(MockMvcRestDocumentation.document("customerById"));
}
开发者ID:applied-continuous-delivery-livelessons,项目名称:cdct,代码行数:14,代码来源:CustomerServiceRestdocsApplicationTests.java
示例5: customersShouldReturnAllCustomers
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
@Test
public void customersShouldReturnAllCustomers() throws Exception {
Mockito.when(this.customerRepository.findAll()).thenReturn(Arrays.asList(
new Customer(1L, "first", "last", "[email protected]"),
new Customer(2L, "first", "last", "[email protected]")));
this.mockMvc.perform(MockMvcRequestBuilders.get("/customers"))
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful())
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
.andExpect(MockMvcResultMatchers.jsonPath("@.[0].id").value(1L))
.andExpect(MockMvcResultMatchers.jsonPath("@.[0].firstName").value("first"))
.andExpect(MockMvcResultMatchers.jsonPath("@.[1].id").value(2L))
.andDo(MockMvcRestDocumentation.document("customers"));
}
开发者ID:applied-continuous-delivery-livelessons,项目名称:cdct,代码行数:16,代码来源:CustomerRestControllerTest.java
示例6: setup
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mvc =
MockMvcBuilders.webAppContextSetup(applicationContext)
.apply(MockMvcRestDocumentation.documentationConfiguration(this.restDocumentation))
.build();
}
示例7: restDocsMockMvcConfigurer
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(MockMvcRestDocumentationConfigurer.class)
public MockMvcRestDocumentationConfigurer restDocsMockMvcConfigurer(
ObjectProvider<RestDocsMockMvcConfigurationCustomizer> configurationCustomizerProvider,
RestDocumentationContextProvider contextProvider) {
MockMvcRestDocumentationConfigurer configurer = MockMvcRestDocumentation
.documentationConfiguration(contextProvider);
RestDocsMockMvcConfigurationCustomizer configurationCustomizer = configurationCustomizerProvider
.getIfAvailable();
if (configurationCustomizer != null) {
configurationCustomizer.customize(configurer);
}
return configurer;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:RestDocsAutoConfiguration.java
示例8: before
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
@Before
public void before() {
this.mockMvc = MockMvcBuilders
.webAppContextSetup(this.wac)
.apply(MockMvcRestDocumentation.documentationConfiguration(this.restDocumentation))
.build();
}
示例9: restDocumentation
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
@Bean
public RestDocumentationResultHandler restDocumentation() {
return MockMvcRestDocumentation.document("{method-name}/{step}",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()));
}
示例10: document
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
/**
* Wraps the static document() method of RestDocs and configures it to pretty print request and
* response JSON structures.
*/
protected RestDocumentationResultHandler document(String identifier, Snippet... snippets) {
return MockMvcRestDocumentation.document(
identifier, preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), snippets);
}
示例11: restDocumentation
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; //导入依赖的package包/类
@Bean
public RestDocumentationResultHandler restDocumentation() {
return MockMvcRestDocumentation.document("{method-name}");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:5,代码来源:RestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java