Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit bb90399

Browse files
authored
Merge pull request #647 from hmcts/PAY-6427-Migrate-Swagger
PAY-6427: Update to add swagger test
2 parents 27a9c5c + 8ffe4e3 commit bb90399

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

api/src/main/java/uk/gov/hmcts/bar/api/auth/SiteValidationFilter.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,20 @@ public class SiteValidationFilter extends GenericFilterBean {
2323

2424
private final BarUserService barUserService;
2525

26-
private static final String[] excludeUrlPatterns = {"/swagger-ui.html", "/webjars/springfox-swagger-ui/**", "/swagger-resources/**",
27-
"/v2/**", "/health","/health/liveness", "/health/readiness", "/payment-types", "/info", "/sites/**"};
26+
private static final String[] excludeUrlPatterns = {
27+
"/v3/**",
28+
"/swagger-ui/**",
29+
"/swagger-ui.html",
30+
"/webjars/springfox-swagger-ui/**",
31+
"/swagger-resources/**",
32+
"/v2/**",
33+
"/health",
34+
"/health/liveness",
35+
"/health/readiness",
36+
"/payment-types",
37+
"/info",
38+
"/sites/**"
39+
};
2840

2941
private static AntPathMatcher pathMatcher = new AntPathMatcher();
3042

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)