1
+ /*
2
+ * Copyright 2012-present the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package org .springframework .boot .actuate .autoconfigure .web .server ;
18
+
19
+ import org .junit .jupiter .api .Test ;
20
+ import org .springframework .boot .WebApplicationType ;
21
+ import org .springframework .context .ApplicationContext ;
22
+ import org .springframework .context .ConfigurableApplicationContext ;
23
+ import org .springframework .core .env .ConfigurableEnvironment ;
24
+ import org .springframework .core .env .MutablePropertySources ;
25
+ import org .springframework .core .env .PropertySource ;
26
+
27
+ import static org .assertj .core .api .Assertions .assertThat ;
28
+ import static org .mockito .Mockito .mock ;
29
+ import static org .mockito .Mockito .when ;
30
+
31
+ /**
32
+ * Test for {@link ManagementContextFactory}.
33
+ *
34
+ * author Yongjun Hong
35
+ */
36
+ class ManagementContextFactoryTest {
37
+
38
+ @ Test
39
+ void createManagementContextCopiesManagementPropertySources () {
40
+ ApplicationContext parentContext = mock (ApplicationContext .class );
41
+ ConfigurableEnvironment parentEnvironment = mock (ConfigurableEnvironment .class );
42
+ MutablePropertySources parentPropertySources = new MutablePropertySources ();
43
+ PropertySource <?> managementPropertySource = new PropertySource <>("managementProperty" ) {
44
+ @ Override
45
+ public Object getProperty (String name ) {
46
+ return null ;
47
+ }
48
+ };
49
+ parentPropertySources .addLast (managementPropertySource );
50
+ when (parentEnvironment .getPropertySources ()).thenReturn (parentPropertySources );
51
+ when (parentContext .getEnvironment ()).thenReturn (parentEnvironment );
52
+
53
+ ManagementContextFactory factory = new ManagementContextFactory (WebApplicationType .SERVLET , null );
54
+
55
+ ConfigurableApplicationContext managementContext = factory .createManagementContext (parentContext );
56
+
57
+ ConfigurableEnvironment childEnvironment = managementContext .getEnvironment ();
58
+ assertThat (childEnvironment .getPropertySources ().contains ("managementProperty" )).isTrue ();
59
+ }
60
+ }
0 commit comments