69 lines
2.5 KiB
Java
69 lines
2.5 KiB
Java
/*
|
|
* Copyright 2014-2016 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
|
|
*
|
|
* https://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 com.example.testng;
|
|
|
|
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
|
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.SpringApplicationConfiguration;
|
|
import org.springframework.restdocs.ManualRestDocumentation;
|
|
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
|
import org.springframework.test.context.web.WebAppConfiguration;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
import org.springframework.web.context.WebApplicationContext;
|
|
import org.testng.annotations.AfterMethod;
|
|
import org.testng.annotations.BeforeMethod;
|
|
import org.testng.annotations.Test;
|
|
|
|
@SpringApplicationConfiguration(classes=SampleTestNgApplication.class)
|
|
@WebAppConfiguration
|
|
public class SampleTestNgApplicationTests extends AbstractTestNGSpringContextTests {
|
|
|
|
private final ManualRestDocumentation restDocumentation = new ManualRestDocumentation("build/generated-snippets");
|
|
|
|
@Autowired
|
|
private WebApplicationContext context;
|
|
|
|
private MockMvc mockMvc;
|
|
|
|
@BeforeMethod
|
|
public void setUp(Method method) {
|
|
this.mockMvc = MockMvcBuilders.webAppContextSetup(context)
|
|
.apply(documentationConfiguration(this.restDocumentation)).build();
|
|
this.restDocumentation.beforeTest(getClass(), method.getName());
|
|
}
|
|
|
|
@AfterMethod
|
|
public void tearDown() {
|
|
this.restDocumentation.afterTest();
|
|
}
|
|
|
|
@Test
|
|
public void sample() throws Exception {
|
|
this.mockMvc.perform(get("/"))
|
|
.andExpect(status().isOk())
|
|
.andDo(document("sample"));
|
|
}
|
|
|
|
}
|