Skip to content

Commit 7605ead

Browse files
committed
Add test to verify DynamicProperty Overrides Existing Properties
Closes gh-26
1 parent 0dfe277 commit 7605ead

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2012-2023 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.experimental.boot.test.context;
18+
19+
import example.authzserver.AuthServerMain;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.context.TestConfiguration;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.core.env.Environment;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
@SpringBootTest(classes = { AuthServerMain.class, DynamicPropertyOverridesTests.Configuration.class })
31+
class DynamicPropertyOverridesTests {
32+
33+
@Test
34+
void dynamicPropertyJavadoc(@Autowired Environment environment) {
35+
assertThat(environment.getProperty("shouldoverride")).isEqualTo("http://localhost:1234");
36+
}
37+
38+
@EnableDynamicProperty
39+
@TestConfiguration(proxyBeanMethods = false)
40+
static class Configuration {
41+
42+
@Bean
43+
@DynamicProperty(name = "shouldoverride", value = "'http://localhost:' + port")
44+
static WebServer messageService() {
45+
return new WebServer();
46+
}
47+
48+
}
49+
50+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shouldoverride: willbereplaced

0 commit comments

Comments
 (0)