File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
springframework/test/external/props
test/config/external/props Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ package guru .springframework .test .external .props ;
2
+
3
+ import guru .springframework .test .jms .FakeJmsBroker ;
4
+ import guru .test .config .external .props .ExternalPropsEnvironment ;
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 = ExternalPropsEnvironment .class )
18
+ public class PropertySourceEnvTest {
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 ("Burgundy" , fakeJmsBroker .getPassword ());
29
+ }
30
+
31
+ }
Original file line number Diff line number Diff line change
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" )
15
+ public class ExternalPropsEnvironment {
16
+
17
+ @ Autowired
18
+ Environment env ; //also from Spring 3.1
19
+
20
+ @ Bean
21
+ public FakeJmsBroker fakeJmsBrokerEnv (){
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.password" ));
27
+ return fakeJmsBroker ;
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments