@@ -121,8 +121,7 @@ public void setUp() {
121
121
Ports values = new Ports ();
122
122
ports .set (values );
123
123
TestPropertyValues
124
- .of ("management.context-path=" , "management.security.enabled=false" ,
125
- "server.servlet.context-path=" ,
124
+ .of ("management.security.enabled=false" , "server.servlet.context-path=" ,
126
125
"server.port=" + ports .get ().server )
127
126
.applyTo (this .applicationContext );
128
127
}
@@ -140,9 +139,9 @@ public void onSamePort() throws Exception {
140
139
BaseConfiguration .class , EndpointWebMvcAutoConfiguration .class );
141
140
this .applicationContext .refresh ();
142
141
assertContent ("/controller" , ports .get ().server , "controlleroutput" );
143
- assertContent ("/endpoint" , ports .get ().server , "endpointoutput" );
144
- assertThat (hasHeader ("/endpoint" , ports .get ().server , "X-Application-Context" ))
145
- .isFalse ();
142
+ assertContent ("/application/ endpoint" , ports .get ().server , "endpointoutput" );
143
+ assertThat (hasHeader ("/application/ endpoint" , ports .get ().server ,
144
+ "X-Application-Context" )) .isFalse ();
146
145
assertThat (this .applicationContext .containsBean ("applicationContextIdFilter" ))
147
146
.isFalse ();
148
147
}
@@ -171,6 +170,26 @@ public void onDifferentPort() throws Exception {
171
170
assertContent ("/controller" , ports .get ().server , "controlleroutput" );
172
171
assertContent ("/endpoint" , ports .get ().server , null );
173
172
assertContent ("/controller" , ports .get ().management , null );
173
+ assertContent ("/application/endpoint" , ports .get ().management , "endpointoutput" );
174
+ assertContent ("/error" , ports .get ().management , startsWith ("{" ));
175
+ ApplicationContext managementContext = this .applicationContext
176
+ .getBean (ManagementContextResolver .class ).getApplicationContext ();
177
+ List <?> interceptors = (List <?>) ReflectionTestUtils .getField (
178
+ managementContext .getBean (EndpointHandlerMapping .class ), "interceptors" );
179
+ assertThat (interceptors ).hasSize (2 );
180
+ }
181
+
182
+ @ Test
183
+ public void onDifferentPortAndRootContext () throws Exception {
184
+ TestPropertyValues .of ("management.port=" + ports .get ().management ,
185
+ "management.context-path=/" ).applyTo (this .applicationContext );
186
+ this .applicationContext .register (RootConfig .class , EndpointConfig .class ,
187
+ DifferentPortConfig .class , BaseConfiguration .class ,
188
+ EndpointWebMvcAutoConfiguration .class , ErrorMvcAutoConfiguration .class );
189
+ this .applicationContext .refresh ();
190
+ assertContent ("/controller" , ports .get ().server , "controlleroutput" );
191
+ assertContent ("/endpoint" , ports .get ().server , null );
192
+ assertContent ("/controller" , ports .get ().management , null );
174
193
assertContent ("/endpoint" , ports .get ().management , "endpointoutput" );
175
194
assertContent ("/error" , ports .get ().management , startsWith ("{" ));
176
195
ApplicationContext managementContext = this .applicationContext
@@ -191,7 +210,7 @@ public void onDifferentPortWithSpecificServer() throws Exception {
191
210
assertContent ("/controller" , ports .get ().server , "controlleroutput" );
192
211
assertContent ("/endpoint" , ports .get ().server , null );
193
212
assertContent ("/controller" , ports .get ().management , null );
194
- assertContent ("/endpoint" , ports .get ().management , "endpointoutput" );
213
+ assertContent ("/application/ endpoint" , ports .get ().management , "endpointoutput" );
195
214
assertContent ("/error" , ports .get ().management , startsWith ("{" ));
196
215
ApplicationContext managementContext = this .applicationContext
197
216
.getBean (ManagementContextResolver .class ).getApplicationContext ();
@@ -310,7 +329,7 @@ public void specificPortsViaProperties() throws Exception {
310
329
assertContent ("/controller" , ports .get ().server , "controlleroutput" );
311
330
assertContent ("/endpoint" , ports .get ().server , null );
312
331
assertContent ("/controller" , ports .get ().management , null );
313
- assertContent ("/endpoint" , ports .get ().management , "endpointoutput" );
332
+ assertContent ("/application/ endpoint" , ports .get ().management , "endpointoutput" );
314
333
}
315
334
316
335
@ Test
@@ -508,7 +527,8 @@ public void managementSpecificSslUsingDifferentPort() throws Exception {
508
527
assertContent ("/controller" , ports .get ().server , "controlleroutput" );
509
528
assertContent ("/endpoint" , ports .get ().server , null );
510
529
assertHttpsContent ("/controller" , ports .get ().management , null );
511
- assertHttpsContent ("/endpoint" , ports .get ().management , "endpointoutput" );
530
+ assertHttpsContent ("/application/endpoint" , ports .get ().management ,
531
+ "endpointoutput" );
512
532
assertHttpsContent ("/error" , ports .get ().management , startsWith ("{" ));
513
533
ApplicationContext managementContext = this .applicationContext
514
534
.getBean (ManagementContextResolver .class ).getApplicationContext ();
@@ -537,6 +557,19 @@ public void managementSpecificSslUsingSamePortFails() throws Exception {
537
557
this .applicationContext .refresh ();
538
558
}
539
559
560
+ @ Test
561
+ public void rootManagementContextPathUsingSamePortFails () throws Exception {
562
+ TestPropertyValues .of ("management.context-path=/" )
563
+ .applyTo (this .applicationContext );
564
+ this .applicationContext .register (RootConfig .class , EndpointConfig .class ,
565
+ BaseConfiguration .class , EndpointWebMvcAutoConfiguration .class ,
566
+ ErrorMvcAutoConfiguration .class );
567
+ this .thrown .expect (IllegalStateException .class );
568
+ this .thrown .expectMessage ("A management context path of '/' requires the"
569
+ + " management server to be listening on a separate port" );
570
+ this .applicationContext .refresh ();
571
+ }
572
+
540
573
@ Test
541
574
public void samePortCanBeUsedWhenManagementSslIsExplicitlyDisabled ()
542
575
throws Exception {
@@ -562,7 +595,7 @@ public void managementServerCanDisableSslWhenUsingADifferentPort() throws Except
562
595
assertHttpsContent ("/controller" , ports .get ().server , "controlleroutput" );
563
596
assertHttpsContent ("/endpoint" , ports .get ().server , null );
564
597
assertContent ("/controller" , ports .get ().management , null );
565
- assertContent ("/endpoint" , ports .get ().management , "endpointoutput" );
598
+ assertContent ("/application/ endpoint" , ports .get ().management , "endpointoutput" );
566
599
assertContent ("/error" , ports .get ().management , startsWith ("{" ));
567
600
ApplicationContext managementContext = this .applicationContext
568
601
.getBean (ManagementContextResolver .class ).getApplicationContext ();
0 commit comments