1
+ /*
2
+ *
3
+ * *
4
+ * * * Copyright 2019-2020 the original author or authors.
5
+ * * *
6
+ * * * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * * * you may not use this file except in compliance with the License.
8
+ * * * You may obtain a copy of the License at
9
+ * * *
10
+ * * * https://www.apache.org/licenses/LICENSE-2.0
11
+ * * *
12
+ * * * Unless required by applicable law or agreed to in writing, software
13
+ * * * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * * * See the License for the specific language governing permissions and
16
+ * * * limitations under the License.
17
+ * *
18
+ *
19
+ */
20
+
21
+ package test .org .springdoc .api .app186 ;
22
+
23
+ import static org .springdoc .core .Constants .ALL_PATTERN ;
24
+
25
+ import org .json .JSONException ;
26
+ import org .junit .jupiter .api .Test ;
27
+ import org .skyscreamer .jsonassert .Customization ;
28
+ import org .skyscreamer .jsonassert .JSONAssert ;
29
+ import org .skyscreamer .jsonassert .JSONCompareMode ;
30
+ import org .skyscreamer .jsonassert .ValueMatcher ;
31
+ import org .skyscreamer .jsonassert .comparator .CustomComparator ;
32
+ import org .skyscreamer .jsonassert .comparator .JSONComparator ;
33
+ import org .springdoc .core .Constants ;
34
+ import org .springdoc .core .GroupedOpenApi ;
35
+ import org .springdoc .core .customizers .OpenApiCustomiser ;
36
+ import org .springdoc .core .customizers .OperationCustomizer ;
37
+ import org .springframework .boot .actuate .autoconfigure .endpoint .web .WebEndpointProperties ;
38
+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
39
+ import org .springframework .boot .test .context .SpringBootTest ;
40
+ import org .springframework .context .annotation .Bean ;
41
+ import org .springframework .context .annotation .ComponentScan ;
42
+ import org .springframework .test .context .TestPropertySource ;
43
+
44
+ import test .org .springdoc .api .AbstractCommonTest ;
45
+
46
+ @ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
47
+ @ TestPropertySource (properties ={ "springdoc.show-actuator=true" ,
48
+ "springdoc.group-configs[0].group=group-actuator-as-properties" ,
49
+ "springdoc.group-configs[0].paths-to-match=${management.endpoints.web.base-path:/actuator}/**" ,
50
+ "management.endpoints.enabled-by-default=true" ,
51
+ "management.endpoints.web.exposure.include=*" ,
52
+ "management.endpoints.web.exposure.exclude=functions, shutdown" })
53
+ public class SpringDocApp186Test extends AbstractCommonTest {
54
+
55
+ private static final JSONComparator STRICT_IGNORING_OPERATION_ID = new CustomComparator (JSONCompareMode .STRICT ,
56
+ Customization .customization (
57
+ "paths.*.*.operationId"
58
+ , new ValueMatcher <Object >() {
59
+ @ Override
60
+ public boolean equal (Object o1 , Object o2 ) {
61
+ return true ;
62
+ }
63
+ }));
64
+
65
+ @ SpringBootApplication
66
+ @ ComponentScan (basePackages = { "org.springdoc" , "test.org.springdoc.api.app186" })
67
+ static class SpringDocTestApp {
68
+
69
+ @ Bean
70
+ public GroupedOpenApi asCodeCheckBackwardsCompatibility (OpenApiCustomiser actuatorOpenApiCustomiser ,
71
+ OperationCustomizer actuatorCustomizer , WebEndpointProperties endpointProperties ) {
72
+ return GroupedOpenApi .builder ()
73
+ .group ("group-actuator-as-code-check-backwards-compatibility" )
74
+ .pathsToMatch (endpointProperties .getBasePath ()+ ALL_PATTERN )
75
+ .addOpenApiCustomiser (actuatorOpenApiCustomiser )
76
+ .addOperationCustomizer (actuatorCustomizer )
77
+ .build ();
78
+ }
79
+
80
+ @ Bean
81
+ public GroupedOpenApi asCode (WebEndpointProperties endpointProperties ) {
82
+ return GroupedOpenApi .builder ()
83
+ .group ("group-actuator-as-code" )
84
+ .pathsToMatch (endpointProperties .getBasePath ()+ ALL_PATTERN )
85
+ .build ();
86
+ }
87
+ }
88
+
89
+ private void assertBodyApp186 (String content ) {
90
+ try {
91
+ JSONAssert .assertEquals (getContent ("results/app186.json" ), content , STRICT_IGNORING_OPERATION_ID );
92
+ } catch (JSONException e ) {
93
+ throw new RuntimeException (e );
94
+ }
95
+ }
96
+
97
+ @ Test
98
+ public void testApp () throws Exception {
99
+ webTestClient .get ().uri (Constants .DEFAULT_API_DOCS_URL ).exchange ()
100
+ .expectStatus ().isOk ()
101
+ .expectBody (String .class ).value (this ::assertBodyApp186 );
102
+ }
103
+
104
+ @ Test
105
+ public void testGroupActuatorAsCodeCheckBackwardsCompatibility () throws Exception {
106
+ webTestClient .get ().uri (Constants .DEFAULT_API_DOCS_URL + "/group-actuator-as-code-check-backwards-compatibility" ).exchange ()
107
+ .expectStatus ().isOk ()
108
+ .expectBody (String .class ).value (this ::assertBodyApp186 );
109
+ }
110
+
111
+ @ Test
112
+ public void testGroupActuatorAsCode () throws Exception {
113
+ webTestClient .get ().uri (Constants .DEFAULT_API_DOCS_URL + "/group-actuator-as-code" ).exchange ()
114
+ .expectStatus ().isOk ()
115
+ .expectBody (String .class ).value (this ::assertBodyApp186 );
116
+ }
117
+
118
+ @ Test
119
+ public void testGroupActuatorAsProperties () throws Exception {
120
+ webTestClient .get ().uri (Constants .DEFAULT_API_DOCS_URL + "/group-actuator-as-properties" ).exchange ()
121
+ .expectStatus ().isOk ()
122
+ .expectBody (String .class ).value (this ::assertBodyApp186 );
123
+ }
124
+
125
+ }
0 commit comments