Skip to content

Commit e0c1faf

Browse files
Sprring Boot Properties
1 parent d9cbbeb commit e0c1faf

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
spring.activemq.in-memory=true
2-
spring.activemq.pooled=false
2+
spring.activemq.pooled=false
3+
guru.jms.server=10.10.10.123
4+
guru.jms.port=3330
5+
guru.jms.user=Ron
6+
guru.jms.password=Burgundy
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package guru.springframework.test.config;
2+
3+
import guru.springframework.test.jms.FakeJmsBroker;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
/**
9+
* Created by jt on 5/7/16.
10+
*/
11+
@Configuration
12+
public class SpringBootJavaConfig {
13+
@Value("${guru.jms.server}")
14+
String jmsServer;
15+
16+
@Value("${guru.jms.port}")
17+
Integer jmsPort;
18+
19+
@Value("${guru.jms.user}")
20+
String jmsUser;
21+
22+
@Value("${guru.jms.password}")
23+
String jmsPassword;
24+
25+
@Bean
26+
public FakeJmsBroker fakeJmsBroker(){
27+
FakeJmsBroker fakeJmsBroker = new FakeJmsBroker();
28+
fakeJmsBroker.setUrl(jmsServer);
29+
fakeJmsBroker.setPort(jmsPort);
30+
fakeJmsBroker.setUser(jmsUser);
31+
fakeJmsBroker.setPassword(jmsPassword);
32+
return fakeJmsBroker;
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package guru.springframework.test.external.props;
2+
3+
import guru.springframework.SpringCoreDevOpsApplication;
4+
import guru.springframework.test.jms.FakeJmsBroker;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.SpringApplicationConfiguration;
9+
import org.springframework.boot.test.WebIntegrationTest;
10+
import org.springframework.test.context.TestPropertySource;
11+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12+
13+
import static org.junit.Assert.assertEquals;
14+
15+
/**
16+
* Created by jt on 5/7/16.
17+
*/
18+
@RunWith(SpringJUnit4ClassRunner.class)
19+
@SpringApplicationConfiguration(SpringCoreDevOpsApplication.class)
20+
@WebIntegrationTest
21+
@TestPropertySource("/application.properties")
22+
public class SpringBootPropertiesTest {
23+
@Autowired
24+
FakeJmsBroker fakeJmsBroker;
25+
26+
@Test
27+
public void testPropsSet() throws Exception {
28+
assertEquals("10.10.10.123", fakeJmsBroker.getUrl());
29+
assertEquals(3330, fakeJmsBroker.getPort().intValue());
30+
assertEquals("Ron", fakeJmsBroker.getUser());
31+
assertEquals("Burgundy", fakeJmsBroker.getPassword());
32+
}
33+
34+
}

0 commit comments

Comments
 (0)