Skip to content

Commit d9cbbeb

Browse files
added multi file example
1 parent 5b8797a commit d9cbbeb

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package guru.springframework.test.external.props;
2+
3+
import guru.springframework.test.jms.FakeJmsBroker;
4+
import guru.test.config.external.props.ExternalPropsMultiFileS4;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.test.context.ContextConfiguration;
9+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
/**
14+
* Created by jt on 5/7/16.
15+
*/
16+
@RunWith(SpringJUnit4ClassRunner.class)
17+
@ContextConfiguration(classes = ExternalPropsMultiFileS4.class)
18+
public class PropertySourceMultiFileS4Test {
19+
20+
@Autowired
21+
FakeJmsBroker fakeJmsBroker;
22+
23+
@Test
24+
public void testPropsSet() throws Exception {
25+
assertEquals("10.10.10.123", fakeJmsBroker.getUrl());
26+
assertEquals(3330, fakeJmsBroker.getPort().intValue());
27+
assertEquals("Ron", fakeJmsBroker.getUser());
28+
assertEquals("&%$)(*&#^!@!@#$", fakeJmsBroker.getPassword());
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package guru.springframework.test.external.props;
2+
3+
import guru.springframework.test.jms.FakeJmsBroker;
4+
import guru.test.config.external.props.ExternalPropsMultiFile;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.test.context.ContextConfiguration;
9+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
/**
14+
* Created by jt on 5/7/16.
15+
*/
16+
@RunWith(SpringJUnit4ClassRunner.class)
17+
@ContextConfiguration(classes = ExternalPropsMultiFile.class)
18+
public class PropertySourceMultiFileTest {
19+
20+
@Autowired
21+
FakeJmsBroker fakeJmsBroker;
22+
23+
@Test
24+
public void testPropsSet() throws Exception {
25+
assertEquals("10.10.10.123", fakeJmsBroker.getUrl());
26+
assertEquals(3330, fakeJmsBroker.getPort().intValue());
27+
assertEquals("Ron", fakeJmsBroker.getUser());
28+
assertEquals("&%$)(*&#^!@!@#$", fakeJmsBroker.getPassword());
29+
}
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package guru.test.config.external.props;
2+
3+
import guru.springframework.test.jms.FakeJmsBroker;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.context.annotation.PropertySource;
8+
import org.springframework.core.env.Environment;
9+
10+
/**
11+
* Created by jt on 5/7/16.
12+
*/
13+
@Configuration
14+
@PropertySource({"classpath:testing.properties", "classpath:encrypted-testing.properties"})
15+
public class ExternalPropsMultiFile {
16+
17+
@Autowired
18+
Environment env;
19+
20+
@Bean
21+
public FakeJmsBroker fakeJmsBrokerMulti(){
22+
FakeJmsBroker fakeJmsBroker = new FakeJmsBroker();
23+
fakeJmsBroker.setUrl(env.getProperty("guru.jms.server"));
24+
fakeJmsBroker.setPort(env.getRequiredProperty("guru.jms.port", Integer.class));
25+
fakeJmsBroker.setUser(env.getProperty("guru.jms.user"));
26+
fakeJmsBroker.setPassword(env.getProperty("guru.jms.encrypted.password"));
27+
return fakeJmsBroker;
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package guru.test.config.external.props;
2+
3+
import guru.springframework.test.jms.FakeJmsBroker;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.context.annotation.PropertySource;
8+
import org.springframework.context.annotation.PropertySources;
9+
import org.springframework.core.env.Environment;
10+
11+
/**
12+
* Created by jt on 5/7/16.
13+
*/
14+
@Configuration
15+
@PropertySources({
16+
@PropertySource("classpath:testing.properties"),
17+
@PropertySource("classpath:encrypted-testing.properties")
18+
})
19+
public class ExternalPropsMultiFileS4 {
20+
21+
@Autowired
22+
Environment env;
23+
24+
@Bean
25+
public FakeJmsBroker fakeJmsBrokerMultiS4(){
26+
FakeJmsBroker fakeJmsBroker = new FakeJmsBroker();
27+
fakeJmsBroker.setUrl(env.getProperty("guru.jms.server"));
28+
fakeJmsBroker.setPort(env.getRequiredProperty("guru.jms.port", Integer.class));
29+
fakeJmsBroker.setUser(env.getProperty("guru.jms.user"));
30+
fakeJmsBroker.setPassword(env.getProperty("guru.jms.encrypted.password"));
31+
return fakeJmsBroker;
32+
}
33+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
guru.jms.encrypted.password=&%$)(*&#^!@!@#$

0 commit comments

Comments
 (0)