Skip to content

Commit 43661ed

Browse files
committed
Verify inlined props override files in @TestPropertySource
This commit introduces a test to demonstrate that inlined properties override properties loaded from Properties files in @TestPropertySource. Issue: SPR-14068
1 parent 856da8e commit 43661ed

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2002-2016 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+
* http://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.test.context.env;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.beans.factory.annotation.Value;
24+
import org.springframework.context.annotation.Bean;
25+
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
27+
import org.springframework.core.env.Environment;
28+
import org.springframework.test.context.ContextConfiguration;
29+
import org.springframework.test.context.TestPropertySource;
30+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31+
32+
import static org.junit.Assert.*;
33+
34+
/**
35+
* Integration tests for {@link TestPropertySource @TestPropertySource} support with
36+
* inlined properties that overrides properties files.
37+
*
38+
* @author Sam Brannen
39+
* @since 4.3
40+
*/
41+
@RunWith(SpringJUnit4ClassRunner.class)
42+
@ContextConfiguration
43+
@TestPropertySource(locations = "explicit.properties", properties = "explicit = inlined")
44+
public class InlinedPropertiesOverridePropertiesFilesTestPropertySourceTests {
45+
46+
@Autowired
47+
Environment env;
48+
49+
@Value("${explicit}")
50+
String explicit;
51+
52+
53+
@Test
54+
public void inlinedPropertyOverridesValueFromPropertiesFile() {
55+
assertEquals("inlined", env.getProperty("explicit"));
56+
assertEquals("inlined", this.explicit);
57+
}
58+
59+
60+
@Configuration
61+
static class Config {
62+
63+
@Bean
64+
public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
65+
return new PropertySourcesPlaceholderConfigurer();
66+
}
67+
}
68+
69+
}

0 commit comments

Comments
 (0)