|
| 1 | +package uk.gov.hmcts.bar.api.componenttests; |
| 2 | + |
| 3 | +import com.microsoft.applicationinsights.web.internal.WebRequestTrackingFilter; |
| 4 | +import org.junit.After; |
| 5 | +import org.junit.Before; |
| 6 | +import org.junit.Test; |
| 7 | +import org.junit.runner.RunWith; |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; |
| 9 | +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
| 10 | +import org.springframework.boot.test.context.SpringBootTest; |
| 11 | +import org.springframework.mock.web.MockFilterConfig; |
| 12 | +import org.springframework.test.annotation.DirtiesContext; |
| 13 | +import org.springframework.test.context.ActiveProfiles; |
| 14 | +import org.springframework.test.context.junit4.SpringRunner; |
| 15 | +import org.springframework.test.web.servlet.MockMvc; |
| 16 | +import org.springframework.web.context.WebApplicationContext; |
| 17 | + |
| 18 | +import java.io.OutputStream; |
| 19 | +import java.nio.file.Files; |
| 20 | +import java.nio.file.Paths; |
| 21 | + |
| 22 | +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.MOCK; |
| 23 | +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; |
| 24 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 25 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 26 | +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; |
| 27 | + |
| 28 | +public class SwaggerPublisher extends ComponentTestBase { |
| 29 | + |
| 30 | + WebRequestTrackingFilter filter; |
| 31 | + |
| 32 | + @Autowired |
| 33 | + private WebApplicationContext webAppContext; |
| 34 | + |
| 35 | + @Before |
| 36 | + public void setup() { |
| 37 | + filter = new WebRequestTrackingFilter(); |
| 38 | + filter.init(new MockFilterConfig()); // using a mock that you construct with init params and all |
| 39 | + } |
| 40 | + |
| 41 | + @After |
| 42 | + public void tearDown() { |
| 43 | + filter = null; |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") |
| 48 | + public void generateDocs() throws Exception { |
| 49 | + generateDocsForGroup("payment"); |
| 50 | + generateDocsForGroup("refdata"); |
| 51 | + } |
| 52 | + |
| 53 | + private void generateDocsForGroup(String groupName) throws Exception { |
| 54 | + byte[] specs = restActions |
| 55 | + .get("/v3/api-docs?group=" + groupName) |
| 56 | + .andExpect(status().isOk()).andReturn().getResponse().getContentAsByteArray(); |
| 57 | + |
| 58 | + try (OutputStream outputStream = Files.newOutputStream(Paths.get("/tmp/swagger-specs." + groupName + ".json"))) { |
| 59 | + outputStream.write(specs); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments