|
25 | 25 | import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
26 | 26 | import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration;
|
27 | 27 | import org.springframework.boot.test.EnvironmentTestUtils;
|
| 28 | +import org.springframework.context.ConfigurableApplicationContext; |
28 | 29 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
29 | 30 | import org.springframework.context.annotation.Bean;
|
30 | 31 | import org.springframework.context.annotation.Configuration;
|
|
38 | 39 |
|
39 | 40 | import static org.hamcrest.Matchers.equalTo;
|
40 | 41 | import static org.hamcrest.Matchers.hasItems;
|
| 42 | +import static org.hamcrest.Matchers.is; |
| 43 | +import static org.hamcrest.Matchers.notNullValue; |
41 | 44 | import static org.junit.Assert.assertThat;
|
42 | 45 |
|
43 | 46 | /**
|
@@ -93,6 +96,27 @@ public void randomlyAllocatedPortIsAvailableWhenCreatingMongoClient() {
|
93 | 96 | "local.mongo.port"))));
|
94 | 97 | }
|
95 | 98 |
|
| 99 | + @Test |
| 100 | + public void portIsAvailableInParentContext() { |
| 101 | + ConfigurableApplicationContext parent = new AnnotationConfigApplicationContext(); |
| 102 | + parent.refresh(); |
| 103 | + try { |
| 104 | + this.context = new AnnotationConfigApplicationContext(); |
| 105 | + this.context.setParent(parent); |
| 106 | + EnvironmentTestUtils.addEnvironment(this.context, |
| 107 | + "spring.data.mongodb.port=0"); |
| 108 | + this.context.register(EmbeddedMongoAutoConfiguration.class, |
| 109 | + MongoClientConfiguration.class, |
| 110 | + PropertyPlaceholderAutoConfiguration.class); |
| 111 | + this.context.refresh(); |
| 112 | + assertThat(parent.getEnvironment().getProperty("local.mongo.port"), |
| 113 | + is(notNullValue())); |
| 114 | + } |
| 115 | + finally { |
| 116 | + parent.close(); |
| 117 | + } |
| 118 | + } |
| 119 | + |
96 | 120 | private void assertVersionConfiguration(String configuredVersion,
|
97 | 121 | String expectedVersion) {
|
98 | 122 | this.context = new AnnotationConfigApplicationContext();
|
|
0 commit comments