BAEL-6197 - Execute Tests Based on Active Profile with JUnit 5 (#13776)
* BAEL-6255 - Run a Spring Boot application in AWS Lambda
* BAEL-6255 - Run a Spring Boot application in AWS Lambda
* fix on template.yaml
* fix on template.yaml
* removed log from test
* resolved issues reported on PR
* BAEL-6277 - A Guide To Spring Cloud Azure
First commit
* BAEL-6277 - A Guide To Spring Cloud Azure
Added to README.md the steps to create the secrets
* BAEL-6277 - A Guide To Spring Cloud Azure
Added the integration Azure Key Vault Properties
* BAEL-6277 - A Guide To Spring Cloud Azure
Added the integration Azure Key Vault Properties
* BAEL-6277 - A Guide To Spring Cloud Azure Key Vault
Added one level package keyvault
* BAEL-6277 - A Guide To Spring Cloud Azure Key Vault
removed target release version
* BAEL-6277 - A Guide To Spring Cloud Azure Key Vault
fix compilation of NoSuchElementException
* BAEL-6277 - A Guide To Spring Cloud Azure Key Vault
fix pom.xml
* Revert "BAEL-6277 - A Guide To Spring Cloud Azure Key Vault"
This reverts commit 1cca1d0d69.
* BAEL-6277 - A Guide To Spring Cloud Azure Key Vault
fix pom.xml
* BAEL-6277 - A Guide To Spring Cloud Azure Key Vault
downgrade version to fix jenkins pipeline error
* BAEL-6277 - A Guide To Spring Cloud Azure Key Vault
comment run on main class
* Revert "reset last commit"
This reverts commit c557fad67f1c15bb384f0af5781430a45121a838.
* BAEL 6197 - Execute Tests Based on Active Profile with JUnit 5
#First push
* BAEL-6277 - A Guide To Spring Cloud Azure Key Vault
Revert for new pr
* reset last commit
* reset last commit
* BAEL 6197 - Execute Tests Based on Active Profile with JUnit 5
#Remove redundant test
* BAEL 6197 - Execute Tests Based on Active Profile with JUnit 5
#Format fix
* BAEL 6197 - Execute Tests Based on Active Profile with JUnit 5
#fix from review
* BAEL 6197 - Execute Tests Based on Active Profile with JUnit 5
#fix from review
* BAEL 6197 - Execute Tests Based on Active Profile with JUnit 5
#fix test name
---------
Co-authored-by: Cesare <cesare.valenti@hotmail.com>
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.activeprofile;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ActiveProfileApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ActiveProfileApplication.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.activeprofile;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest(classes = ActiveProfileApplication.class)
|
||||
public class DevActiveProfileUnitTest {
|
||||
|
||||
@Value("${profile.property.value}")
|
||||
private String propertyString;
|
||||
|
||||
@Test
|
||||
void whenDevIsActive_thenValueShouldBeKeptFromApplicationYaml() {
|
||||
Assertions.assertEquals("This the the application.yaml file", propertyString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.activeprofile;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
@SpringBootTest(classes = ActiveProfileApplication.class)
|
||||
@EnabledIf(value = "#{{'test', 'prod'}.contains(environment.getActiveProfiles()[0])}", loadContext = true)
|
||||
@ActiveProfiles(value = "test")
|
||||
public class MultipleActiveProfileUnitTest {
|
||||
@Value("${profile.property.value}")
|
||||
private String propertyString;
|
||||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
|
||||
@Test
|
||||
void whenDevIsActive_thenValueShouldBeKeptFromDedicatedApplicationYaml() {
|
||||
String currentProfile = env.getActiveProfiles()[0];
|
||||
Assertions.assertEquals(String.format("This the the application-%s.yaml file", currentProfile), propertyString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.activeprofile;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit.jupiter.EnabledIf;
|
||||
|
||||
@SpringBootTest(classes = ActiveProfileApplication.class)
|
||||
@EnabledIf(value = "#{environment.getActiveProfiles()[0] == 'prod'}", loadContext = true)
|
||||
@ActiveProfiles(value = "prod")
|
||||
public class ProdActiveProfileUnitTest {
|
||||
|
||||
@Value("${profile.property.value}")
|
||||
private String propertyString;
|
||||
|
||||
@Test
|
||||
void whenProdIsActive_thenValueShouldBeKeptFromApplicationProdYaml() {
|
||||
Assertions.assertEquals("This the the application-prod.yaml file", propertyString);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.activeprofile;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
@SpringBootTest(classes = ActiveProfileApplication.class)
|
||||
@ActiveProfiles(value = "test")
|
||||
public class TestActiveProfileUnitTest {
|
||||
|
||||
@Value("${profile.property.value}")
|
||||
private String propertyString;
|
||||
|
||||
@Test
|
||||
void whenTestIsActive_thenValueShouldBeKeptFromApplicationTestYaml() {
|
||||
Assertions.assertEquals("This the the application-test.yaml file", propertyString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
profile:
|
||||
property:
|
||||
value: This the the application-prod.yaml file
|
||||
@@ -0,0 +1,3 @@
|
||||
profile:
|
||||
property:
|
||||
value: This the the application-test.yaml file
|
||||
@@ -0,0 +1,6 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
profile:
|
||||
property:
|
||||
value: This the the application.yaml file
|
||||
Reference in New Issue
Block a user