diff --git a/spring-cloud-modules/spring-cloud-azure/pom.xml b/spring-cloud-modules/spring-cloud-azure/pom.xml index f9af6e3d9d..ceab18f21f 100644 --- a/spring-cloud-modules/spring-cloud-azure/pom.xml +++ b/spring-cloud-modules/spring-cloud-azure/pom.xml @@ -25,48 +25,23 @@ - - - - junit - junit - ${junit.version} - - - org.junit - junit-bom - ${junit-jupiter.version} + org.springframework.boot + spring-boot-dependencies + 2.7.8 pom import - - com.azure.spring - spring-cloud-azure-dependencies - 5.0.0 - pom - import - - - ch.qos.logback - logback-classic - - - - - org.springframework.boot - spring-boot-starter-web - com.azure.spring spring-cloud-azure-starter-keyvault-secrets + 5.0.0 - diff --git a/testing-modules/junit5-annotations/pom.xml b/testing-modules/junit5-annotations/pom.xml index 847baa827c..72e232e218 100644 --- a/testing-modules/junit5-annotations/pom.xml +++ b/testing-modules/junit5-annotations/pom.xml @@ -5,6 +5,18 @@ 4.0.0 junit5-annotations 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + + + junit5-annotations Intro to JUnit 5 @@ -42,10 +54,22 @@ ${junit-platform.version} test + + org.springframework.boot + spring-boot-starter-web + ${spring.boot.version} + + + org.springframework.boot + spring-boot-starter-test + ${spring.boot.test.version} + 2.19.0 + 3.0.4 + 3.0.5 \ No newline at end of file diff --git a/testing-modules/junit5-annotations/src/main/java/com/baeldung/junit5/activeprofile/Application.java b/testing-modules/junit5-annotations/src/main/java/com/baeldung/junit5/activeprofile/Application.java new file mode 100644 index 0000000000..ec776cb3c9 --- /dev/null +++ b/testing-modules/junit5-annotations/src/main/java/com/baeldung/junit5/activeprofile/Application.java @@ -0,0 +1,12 @@ +package com.baeldung.junit5.activeprofile; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main (String [] args){ + SpringApplication.run(Application.class); + } +} diff --git a/testing-modules/junit5-annotations/src/main/resources/application-dev.yaml b/testing-modules/junit5-annotations/src/main/resources/application-dev.yaml new file mode 100644 index 0000000000..bfd52770a6 --- /dev/null +++ b/testing-modules/junit5-annotations/src/main/resources/application-dev.yaml @@ -0,0 +1,3 @@ +profile: + property: + value: This the the application-dev.yaml file \ No newline at end of file diff --git a/testing-modules/junit5-annotations/src/main/resources/application.yaml b/testing-modules/junit5-annotations/src/main/resources/application.yaml new file mode 100644 index 0000000000..cf63649116 --- /dev/null +++ b/testing-modules/junit5-annotations/src/main/resources/application.yaml @@ -0,0 +1,6 @@ +spring: + profiles: + active: dev +profile: + property: + value: This the the application.yaml file \ No newline at end of file diff --git a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/activeprofile/DevActiveProfileUnitTest.java b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/activeprofile/DevActiveProfileUnitTest.java new file mode 100644 index 0000000000..f279e2a18a --- /dev/null +++ b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/activeprofile/DevActiveProfileUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.junit5.activeprofile; + +import java.util.Arrays; +import java.util.List; + +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; + +@SpringBootTest +public class DevActiveProfileUnitTest { + + @Value("${profile.property.value}") + private String propertyString; + + @Test + void whenDevIsActive_ThenValueShouldBeKeptFromApplicationDevYaml() { + ; + Assertions.assertEquals("This the the application-dev.yaml file", propertyString, propertyString); + } +} diff --git a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/activeprofile/MultipleActiveProfileUnitTest.java b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/activeprofile/MultipleActiveProfileUnitTest.java new file mode 100644 index 0000000000..6e61b8532b --- /dev/null +++ b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/activeprofile/MultipleActiveProfileUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.junit5.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.junit.jupiter.EnabledIf; + +@SpringBootTest +@EnabledIf(value = "#{{'dev', 'prod'}.contains(environment.getActiveProfiles()[0])}", loadContext = true) +public class MultipleActiveProfileUnitTest { + @Value("${profile.property.value}") + private String propertyString; + + @Test + void whenDevIsActive_ThenValueShouldBeKeptFromApplicationDevYaml() { + ; + Assertions.assertEquals("This the the application-dev.yaml file", propertyString, propertyString); + } +} diff --git a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/activeprofile/ProdActiveProfileUnitTest.java b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/activeprofile/ProdActiveProfileUnitTest.java new file mode 100644 index 0000000000..8ee00d9344 --- /dev/null +++ b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/activeprofile/ProdActiveProfileUnitTest.java @@ -0,0 +1,32 @@ +package com.baeldung.junit5.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.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.EnabledIf; + +@SpringBootTest +@EnabledIf(value = "#{environment.getActiveProfiles()[0] == 'prod'}", loadContext = true) +@ActiveProfiles(value = "prod") + +public class ProdActiveProfileUnitTest { + + @Value("${profile.property.value}") + private String propertyString; + + @Autowired + private + + @Test void whenProdIsActive_ThenValueShouldBeKeptFromApplicationYaml() { + Assertions.assertEquals("This the the application.yaml file", propertyString, propertyString); + } + + @Test + void whenProdIsASystemVariable_ThenTestShouldRun() { + Assertions.assertEquals("This the the application.yaml file", propertyString, propertyString); + } + +}