Skip to content

Commit d6593fb

Browse files
author
Dave Syer
committedNov 22, 2013
Add extra test for partial overrides
1 parent bd26b28 commit d6593fb

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello: Bonjour
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2012-2013 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.boot.sample.profile.service;
18+
19+
import org.springframework.beans.factory.annotation.Value;
20+
import org.springframework.context.annotation.Profile;
21+
import org.springframework.stereotype.Component;
22+
23+
@Component
24+
@Profile({ "generic" })
25+
public class GenericService implements MessageService {
26+
27+
@Value("${hello:Hello}")
28+
private String hello;
29+
30+
@Value("${name:World}")
31+
private String name;
32+
33+
@Override
34+
public String getMessage() {
35+
return this.hello + " " + this.name;
36+
}
37+
38+
}

‎spring-boot-samples/spring-boot-sample-profile/src/test/java/org/springframework/boot/sample/profile/SampleProfileApplicationTests.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public void before() {
4040
public void after() {
4141
if (this.profiles != null) {
4242
System.setProperty("spring.profiles.active", this.profiles);
43-
}
44-
else {
43+
} else {
4544
System.clearProperty("spring.profiles.active");
4645
}
4746
}
@@ -61,6 +60,20 @@ public void testGoodbyeProfile() throws Exception {
6160
assertTrue("Wrong output: " + output, output.contains("Goodbye Everyone"));
6261
}
6362

63+
@Test
64+
public void testGenericProfile() throws Exception {
65+
/*
66+
* This is a profile that requires a new environment property, and one which is
67+
* only overridden in the current working directory. That file also only contains
68+
* partial overrides, and the default application.yml should still supply the
69+
* "name" property.
70+
*/
71+
System.setProperty("spring.profiles.active", "generic");
72+
SampleProfileApplication.main(new String[0]);
73+
String output = this.outputCapture.toString();
74+
assertTrue("Wrong output: " + output, output.contains("Bonjour Phil"));
75+
}
76+
6477
@Test
6578
public void testGoodbyeProfileFromCommandline() throws Exception {
6679
SampleProfileApplication

0 commit comments

Comments
 (0)
Please sign in to comment.