Skip to content

Commit 83699f3

Browse files
Testing Active Profiles
1 parent ed001ff commit 83699f3

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package guru.springframework.test.config;
2+
3+
import org.springframework.context.annotation.ComponentScan;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
/**
7+
* Created by jt on 5/21/16.
8+
*/
9+
@Configuration
10+
@ComponentScan("guru.springframework.test.ds")
11+
public class DataSourceConfig {
12+
}

src/test/java/guru/springframework/test/ds/DevDataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Created by jt on 5/21/16.
88
*/
99
@Component
10-
@Profile("dev")
10+
@Profile({"dev", "default"})
1111
public class DevDataSource implements FakeDataSource {
1212
@Override
1313
public String getConnectionInfo() {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package guru.springframework.test.dstest;
2+
3+
/**
4+
* Created by jt on 5/21/16.
5+
*/
6+
7+
import guru.springframework.test.config.DataSourceConfig;
8+
import guru.springframework.test.ds.FakeDataSource;
9+
import org.junit.Test;
10+
import org.junit.runner.RunWith;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.boot.test.SpringApplicationConfiguration;
13+
import org.springframework.test.context.ActiveProfiles;
14+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15+
16+
@RunWith(SpringJUnit4ClassRunner.class)
17+
@SpringApplicationConfiguration(DataSourceConfig.class)
18+
@ActiveProfiles("guru")
19+
public class DataSourceTest {
20+
21+
private FakeDataSource fakeDataSource;
22+
23+
@Autowired
24+
public void setFakeDataSource(FakeDataSource fakeDataSource) {
25+
this.fakeDataSource = fakeDataSource;
26+
}
27+
28+
@Test
29+
public void TestDataSource() throws Exception {
30+
31+
System.out.println(fakeDataSource.getConnectionInfo());
32+
33+
}
34+
}

0 commit comments

Comments
 (0)