Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!--MySQL Dep-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package guru.springframework.bootstrap.profilesysout;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Created by jt on 5/21/16.
*/
@Component
@Profile("default")
public class DefaultProfileSysOut {

@Autowired
public DefaultProfileSysOut(@Value("${guru.springframework.profile.message}") String msg) {
System.out.println("##################################");
System.out.println("##################################");
System.out.println("## DEFAULT ##");
System.out.println(msg);
System.out.println("##################################");
System.out.println("##################################");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package guru.springframework.bootstrap.profilesysout;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Created by jt on 5/21/16.
*/
@Component
@Profile("dev")
public class DevProfileSysOut {

@Autowired
public DevProfileSysOut(@Value("${guru.springframework.profile.message}") String msg) {
System.out.println("##################################");
System.out.println("##################################");
System.out.println("## DEV ##");
System.out.println(msg);
System.out.println("##################################");
System.out.println("##################################");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package guru.springframework.bootstrap.profilesysout;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
* Created by jt on 5/21/16.
*/
@Component
public class NonProfileBean {

@Autowired
public NonProfileBean(@Value("${guru.springframework.profile.message}") String msg) {
System.out.println("**********" + msg + "************");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package guru.springframework.bootstrap.profilesysout;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Created by jt on 5/21/16.
*/
@Component
@Profile("prod")
public class ProdProfileSysOut {

@Autowired
public ProdProfileSysOut(@Value("${guru.springframework.profile.message}") String msg) {
System.out.println("##################################");
System.out.println("##################################");
System.out.println("## PROD ##");
System.out.println(msg);
System.out.println("##################################");
System.out.println("##################################");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package guru.springframework.bootstrap.profilesysout;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Created by jt on 5/21/16.
*/
@Component
@Profile("qa")
public class QAProfileSysOut {

@Autowired
public QAProfileSysOut(@Value("${guru.springframework.profile.message}") String msg) {
System.out.println("##################################");
System.out.println("##################################");
System.out.println("## QA ##");
System.out.println(msg);
System.out.println("##################################");
System.out.println("##################################");
}
}
1 change: 1 addition & 0 deletions src/main/resources/application-default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
guru.springframework.profile.message=This is a default profile
Empty file.
4 changes: 4 additions & 0 deletions src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
guru:
springframework:
profile:
message: This is my DEV profile
1 change: 1 addition & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
guru.springframework.profile.message=This is my production profile
7 changes: 7 additions & 0 deletions src/main/resources/application-qa.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
guru.springframework.profile.message=This is my QA Profile

spring.datasource.url=jdbc:mysql://localhost:3306/springguru
spring.datasource.username=root
spring.datasource.password=

spring.jpa.hibernate.ddl-auto=update
8 changes: 7 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
spring.activemq.in-memory=true
spring.activemq.pooled=false
spring.activemq.pooled=false
guru.jms.server=10.10.10.123
guru.jms.port=3330
guru.jms.user=Ron
guru.jms.password=Burgundy

spring.profiles.active=dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package guru.springframework.test.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
* Created by jt on 5/21/16.
*/
@Configuration
@ComponentScan("guru.springframework.test.ds")
public class DataSourceConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package guru.springframework.test.config;

import guru.springframework.test.jms.FakeJmsBroker;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Created by jt on 5/7/16.
*/
@Configuration
public class SpringBootJavaConfig {
@Value("${guru.jms.server}")
String jmsServer;

@Value("${guru.jms.port}")
Integer jmsPort;

@Value("${guru.jms.user}")
String jmsUser;

@Value("${guru.jms.password}")
String jmsPassword;

@Bean
public FakeJmsBroker fakeJmsBroker(){
FakeJmsBroker fakeJmsBroker = new FakeJmsBroker();
fakeJmsBroker.setUrl(jmsServer);
fakeJmsBroker.setPort(jmsPort);
fakeJmsBroker.setUser(jmsUser);
fakeJmsBroker.setPassword(jmsPassword);
return fakeJmsBroker;
}
}
16 changes: 16 additions & 0 deletions src/test/java/guru/springframework/test/ds/DevDataSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package guru.springframework.test.ds;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Created by jt on 5/21/16.
*/
@Component
@Profile({"dev", "default"})
public class DevDataSource implements FakeDataSource {
@Override
public String getConnectionInfo() {
return "I'm the Development DataSource";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package guru.springframework.test.ds;

/**
* Created by jt on 5/21/16.
*/
public interface FakeDataSource {

String getConnectionInfo();
}
16 changes: 16 additions & 0 deletions src/test/java/guru/springframework/test/ds/ProdDataSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package guru.springframework.test.ds;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Created by jt on 5/21/16.
*/
@Component
@Profile("prod")
public class ProdDataSource implements FakeDataSource {
@Override
public String getConnectionInfo() {
return "I'm the Production Datasource";
}
}
17 changes: 17 additions & 0 deletions src/test/java/guru/springframework/test/ds/QADataSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package guru.springframework.test.ds;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Created by jt on 5/21/16.
*/
@Component
@Profile("qa")
public class QADataSource implements FakeDataSource {

@Override
public String getConnectionInfo() {
return "I'm the QA Datasource";
}
}
34 changes: 34 additions & 0 deletions src/test/java/guru/springframework/test/dstest/DataSourceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package guru.springframework.test.dstest;

/**
* Created by jt on 5/21/16.
*/

import guru.springframework.test.config.DataSourceConfig;
import guru.springframework.test.ds.FakeDataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(DataSourceConfig.class)
@ActiveProfiles("guru")
public class DataSourceTest {

private FakeDataSource fakeDataSource;

@Autowired
public void setFakeDataSource(FakeDataSource fakeDataSource) {
this.fakeDataSource = fakeDataSource;
}

@Test
public void TestDataSource() throws Exception {

System.out.println(fakeDataSource.getConnectionInfo());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package guru.springframework.test.external.props;

import guru.springframework.test.jms.FakeJmsBroker;
import guru.test.config.external.props.ExternalPropsEnvironment;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertEquals;

/**
* Created by jt on 5/7/16.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = ExternalPropsEnvironment.class)
public class PropertySourceEnvTest {

@Autowired
FakeJmsBroker fakeJmsBroker;

@Test
public void testPropsSet() throws Exception {
assertEquals("10.10.10.123", fakeJmsBroker.getUrl());
assertEquals(3330, fakeJmsBroker.getPort().intValue());
assertEquals("Ron", fakeJmsBroker.getUser());
assertEquals("Burgundy", fakeJmsBroker.getPassword());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package guru.springframework.test.external.props;

import guru.springframework.test.jms.FakeJmsBroker;
import guru.test.config.external.props.ExternalPropsMultiFileS4;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertEquals;

/**
* Created by jt on 5/7/16.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = ExternalPropsMultiFileS4.class)
public class PropertySourceMultiFileS4Test {

@Autowired
FakeJmsBroker fakeJmsBroker;

@Test
public void testPropsSet() throws Exception {
assertEquals("10.10.10.123", fakeJmsBroker.getUrl());
assertEquals(3330, fakeJmsBroker.getPort().intValue());
assertEquals("Ron", fakeJmsBroker.getUser());
assertEquals("&%$)(*&#^!@!@#$", fakeJmsBroker.getPassword());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package guru.springframework.test.external.props;

import guru.springframework.test.jms.FakeJmsBroker;
import guru.test.config.external.props.ExternalPropsMultiFile;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertEquals;

/**
* Created by jt on 5/7/16.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = ExternalPropsMultiFile.class)
public class PropertySourceMultiFileTest {

@Autowired
FakeJmsBroker fakeJmsBroker;

@Test
public void testPropsSet() throws Exception {
assertEquals("10.10.10.123", fakeJmsBroker.getUrl());
assertEquals(3330, fakeJmsBroker.getPort().intValue());
assertEquals("Ron", fakeJmsBroker.getUser());
assertEquals("&%$)(*&#^!@!@#$", fakeJmsBroker.getPassword());
}
}
Loading