@@ -758,6 +758,78 @@ public void bootstrapPropertiesWithActivateOnProfile() {
758
758
then (this .context .getEnvironment ().getProperty ("info.name" )).isEqualTo ("externalPropertiesInfoName from bar" );
759
759
}
760
760
761
+ @ Test
762
+ void activatedOnProfile () {
763
+ PropertySourceConfiguration .MAP .put ("stage" , "dev" );
764
+ PropertySourceConfiguration .MAP .put ("spring.config.activate.on-profile" , "dev" );
765
+ String [] properties = new String [] { "spring.config.use-legacy-processing=true" };
766
+ this .context = new SpringApplicationBuilder ().web (WebApplicationType .NONE )
767
+ .properties (properties )
768
+ .sources (BareConfiguration .class )
769
+ .run ("--spring.profiles.active=dev" );
770
+ then (this .context .getEnvironment ().getProperty ("stage" )).isEqualTo ("dev" );
771
+ }
772
+
773
+ @ Test
774
+ void notActivatedOnNoActiveProfile () {
775
+ PropertySourceConfiguration .MAP .put ("stage" , "dev" );
776
+ PropertySourceConfiguration .MAP .put ("spring.config.activate.on-profile" , "dev" );
777
+ String [] properties = new String [] { "spring.config.use-legacy-processing=true" };
778
+ this .context = new SpringApplicationBuilder ().web (WebApplicationType .NONE )
779
+ .properties (properties )
780
+ .sources (BareConfiguration .class )
781
+ .run ();
782
+ then (this .context .getEnvironment ().getProperty ("stage" )).isNotEqualTo ("dev" );
783
+ }
784
+
785
+ @ Test
786
+ void notActivatedOnMismatchedProfile () {
787
+ PropertySourceConfiguration .MAP .put ("stage" , "dev" );
788
+ PropertySourceConfiguration .MAP .put ("spring.config.activate.on-profile" , "dev" );
789
+ String [] properties = new String [] { "spring.config.use-legacy-processing=true" };
790
+ this .context = new SpringApplicationBuilder ().web (WebApplicationType .NONE )
791
+ .properties (properties )
792
+ .sources (BareConfiguration .class )
793
+ .run ("--spring.profiles.active=prod" );
794
+ then (this .context .getEnvironment ().getProperty ("stage" )).isNotEqualTo ("dev" );
795
+ }
796
+
797
+ @ Test
798
+ void activatedOnCloudPlatform () {
799
+ PropertySourceConfiguration .MAP .put ("cloud" , "kubernetes" );
800
+ PropertySourceConfiguration .MAP .put ("spring.config.activate.on-cloud-platform" , "kubernetes" );
801
+ String [] properties = new String [] { "spring.config.use-legacy-processing=true" };
802
+ this .context = new SpringApplicationBuilder ().web (WebApplicationType .NONE )
803
+ .properties (properties )
804
+ .sources (BareConfiguration .class )
805
+ .run ("--spring.main.cloud-platform=kubernetes" );
806
+ then (this .context .getEnvironment ().getProperty ("cloud" )).isEqualTo ("kubernetes" );
807
+ }
808
+
809
+ @ Test
810
+ void notActivatedOnNoActiveCloudPlatform () {
811
+ PropertySourceConfiguration .MAP .put ("cloud" , "kubernetes" );
812
+ PropertySourceConfiguration .MAP .put ("spring.config.activate.on-cloud-platform" , "kubernetes" );
813
+ String [] properties = new String [] { "spring.config.use-legacy-processing=true" };
814
+ this .context = new SpringApplicationBuilder ().web (WebApplicationType .NONE )
815
+ .properties (properties )
816
+ .sources (BareConfiguration .class )
817
+ .run ();
818
+ then (this .context .getEnvironment ().getProperty ("cloud" )).isNotEqualTo ("kubernetes" );
819
+ }
820
+
821
+ @ Test
822
+ void notActivatedOnMismatchedCloudPlatform () {
823
+ PropertySourceConfiguration .MAP .put ("cloud" , "kubernetes" );
824
+ PropertySourceConfiguration .MAP .put ("spring.config.activate.on-cloud-platform" , "kubernetes" );
825
+ String [] properties = new String [] { "spring.config.use-legacy-processing=true" };
826
+ this .context = new SpringApplicationBuilder ().web (WebApplicationType .NONE )
827
+ .properties (properties )
828
+ .sources (BareConfiguration .class )
829
+ .run ("--spring.main.cloud-platform=heroku" );
830
+ then (this .context .getEnvironment ().getProperty ("cloud" )).isNotEqualTo ("kubernetes" );
831
+ }
832
+
761
833
@ Configuration (proxyBeanMethods = false )
762
834
@ EnableConfigurationProperties
763
835
protected static class BareConfiguration {
0 commit comments