BAEL-3756-YAML-for-Spring-DevOps (#9368)

* Add modifications to include the configuration for YAML and DevOps

* Clean the Dockerfile

* Modify the name of testing environment and include YAML tests
This commit is contained in:
Carlos Cavero 2020-05-29 00:02:11 +02:00 committed by GitHub
parent 135c3160ac
commit 6076d4da3b
6 changed files with 92 additions and 2 deletions

View File

@ -0,0 +1,13 @@
# Logs
logs
*.log
# Git
.git
.cache
# Classes
**/*.class
# Ignore md files
*.md

View File

@ -0,0 +1,10 @@
FROM maven:3.6.0-jdk-11
WORKDIR /code/spring-boot-modules/spring-boot-properties/
COPY ./spring-boot-modules/spring-boot-properties/pom.xml .
COPY ./spring-boot-modules/spring-boot-properties/src ./src
COPY ./parent-boot-2/pom.xml /code/parent-boot-2/pom.xml
COPY ./pom.xml /code/pom.xml
COPY ./custom-pmd-0.0.1.jar /code/custom-pmd-0.0.1.jar
COPY ./baeldung-pmd-rules.xml /code/baeldung-pmd-rules.xml
RUN mvn dependency:resolve
CMD ["mvn", "spring-boot:run"]

View File

@ -128,7 +128,8 @@
<httpcore.version>4.4.11</httpcore.version>
<resource.delimiter>@</resource.delimiter>
<configuration-processor.version>2.2.4.RELEASE</configuration-processor.version>
<start-class>com.baeldung.buildproperties.Application</start-class>
<!-- <start-class>com.baeldung.buildproperties.Application</start-class> -->
<start-class>com.baeldung.yaml.MyApplication</start-class>
</properties>
</project>

View File

@ -1,7 +1,14 @@
spring:
profiles:
active:
- test
---
spring:
profiles: test
name: test-YAML
environment: test
environment: testing
servers:
- www.abc.test.com
- www.xyz.test.com
@ -15,3 +22,13 @@ environment: production
servers:
- www.abc.com
- www.xyz.com
---
spring:
profiles: dev
name: ${DEV_NAME:dev-YAML}
environment: development
servers:
- www.abc.dev.com
- www.xyz.dev.com

View File

@ -0,0 +1,25 @@
package com.baeldung.yaml;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyApplication.class)
@TestPropertySource(properties = {"spring.profiles.active = dev"})
class YAMLDevIntegrationTest {
@Autowired
private YAMLConfig config;
@Test
void whenProfileTest_thenNameTesting() {
assertTrue("development".equalsIgnoreCase(config.getEnvironment()));
assertTrue("dev-YAML".equalsIgnoreCase(config.getName()));
}
}

View File

@ -0,0 +1,24 @@
package com.baeldung.yaml;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyApplication.class)
class YAMLIntegrationTest {
@Autowired
private YAMLConfig config;
@Test
void whenProfileTest_thenNameTesting() {
assertTrue("testing".equalsIgnoreCase(config.getEnvironment()));
assertTrue("test-YAML".equalsIgnoreCase(config.getName()));
}
}