|
17 | 17 | package org.springframework.boot.actuate.autoconfigure;
|
18 | 18 |
|
19 | 19 | import org.junit.Test;
|
20 |
| -import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
21 |
| -import org.springframework.context.annotation.Bean; |
22 |
| -import org.springframework.context.annotation.Configuration; |
23 | 20 |
|
24 | 21 | import static org.hamcrest.Matchers.equalTo;
|
25 | 22 | import static org.hamcrest.Matchers.nullValue;
|
|
29 | 26 | * Tests for {@link ManagementServerPropertiesAutoConfiguration}.
|
30 | 27 | *
|
31 | 28 | * @author Phillip Webb
|
| 29 | + * @author Stephane Nicoll |
32 | 30 | */
|
33 | 31 | public class ManagementServerPropertiesAutoConfigurationTests {
|
34 | 32 |
|
35 | 33 | @Test
|
36 | 34 | public void defaultManagementServerProperties() {
|
37 |
| - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( |
38 |
| - ManagementServerPropertiesAutoConfiguration.class); |
39 |
| - assertThat(context.getBean(ManagementServerProperties.class).getPort(), |
40 |
| - nullValue()); |
41 |
| - context.close(); |
| 35 | + ManagementServerProperties properties = new ManagementServerProperties(); |
| 36 | + assertThat(properties.getPort(), nullValue()); |
| 37 | + assertThat(properties.getContextPath(), equalTo("")); |
42 | 38 | }
|
43 | 39 |
|
44 | 40 | @Test
|
45 |
| - public void definedManagementServerProperties() throws Exception { |
46 |
| - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( |
47 |
| - Config.class, ManagementServerPropertiesAutoConfiguration.class); |
48 |
| - assertThat(context.getBean(ManagementServerProperties.class).getPort(), |
49 |
| - equalTo(Integer.valueOf(123))); |
50 |
| - context.close(); |
| 41 | + public void definedManagementServerProperties() { |
| 42 | + ManagementServerProperties properties = new ManagementServerProperties(); |
| 43 | + properties.setPort(123); |
| 44 | + properties.setContextPath("/foo"); |
| 45 | + assertThat(properties.getPort(), equalTo(123)); |
| 46 | + assertThat(properties.getContextPath(), equalTo("/foo")); |
51 | 47 | }
|
52 | 48 |
|
53 |
| - @Configuration |
54 |
| - public static class Config { |
55 |
| - |
56 |
| - @Bean |
57 |
| - public ManagementServerProperties managementServerProperties() { |
58 |
| - ManagementServerProperties properties = new ManagementServerProperties(); |
59 |
| - properties.setPort(123); |
60 |
| - return properties; |
61 |
| - } |
| 49 | + @Test |
| 50 | + public void trailingSlashOfContextPathIsRemoved() { |
| 51 | + ManagementServerProperties properties = new ManagementServerProperties(); |
| 52 | + properties.setContextPath("/foo/"); |
| 53 | + assertThat(properties.getContextPath(), equalTo("/foo")); |
| 54 | + } |
62 | 55 |
|
| 56 | + @Test |
| 57 | + public void slashOfContextPathIsDefaultValue() { |
| 58 | + ManagementServerProperties properties = new ManagementServerProperties(); |
| 59 | + properties.setContextPath("/"); |
| 60 | + assertThat(properties.getContextPath(), equalTo("")); |
63 | 61 | }
|
64 | 62 |
|
65 | 63 | }
|
0 commit comments