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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!--MySQL Dep-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.6</version>
</dependency>

<!--JMS Dep-->
<dependency>
<groupId>org.springframework</groupId>
Expand Down
14 changes: 14 additions & 0 deletions src/main/SQL/mysql-service-account.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE USER 'springframework'@'localhost' IDENTIFIED BY 'guru';

GRANT SELECT ON springguru.* to 'springframework'@'localhost';
GRANT INSERT ON springguru.* to 'springframework'@'localhost';
GRANT DELETE ON springguru.* to 'springframework'@'localhost';
GRANT UPDATE ON springguru.* to 'springframework'@'localhost';


CREATE USER 'qa2user'@'localhost' IDENTIFIED BY 'qa2password';

GRANT SELECT ON qa2.* to 'qa2user'@'localhost';
GRANT INSERT ON qa2.* to 'qa2user'@'localhost';
GRANT DELETE ON qa2.* to 'qa2user'@'localhost';
GRANT UPDATE ON qa2.* to 'qa2user'@'localhost';
281 changes: 143 additions & 138 deletions src/main/java/guru/springframework/bootstrap/DevOpsBootstrap.java

Large diffs are not rendered by default.

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
10 changes: 10 additions & 0 deletions src/main/resources/application-qa.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
guru.springframework.profile.message=This is my QA Profile

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

spring.jpa.hibernate.ddl-auto=update

jasypt.encryptor.password=password

spring.datasource.username=ENC(CdGBqXnwaPYaC8CdW88gK8/XiAX+rtvU)
spring.datasource.password=ENC(dP8dBsQ+C/LOK1resD3iqg==)
10 changes: 10 additions & 0 deletions src/main/resources/application-qa2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
guru.springframework.profile.message=This is my QA2 Profile

spring.datasource.url=jdbc:mysql://localhost:3306/qa2

spring.jpa.hibernate.ddl-auto=update

jasypt.encryptor.password=passwordqa2

spring.datasource.username=ENC(IrEYiwrINlieoi2/LuGnSA==)
spring.datasource.password=ENC(LGqQfwqKDyVCyUKZfX+SG4/3/biZLnXa)
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());
}

}
Loading