@@ -506,6 +506,70 @@ void filterPropertySourcesWithDocuments() {
506506
507507 }
508508
509+ @ Test
510+ void testProfileSpecificPropertySources () {
511+ PropertySource p1 = new PropertySource ("overrides" , Collections .singletonMap ("foo" , "bar" ));
512+ PropertySource p2 = new PropertySource ("classpath:/test-default/config-client/application.yaml" ,
513+ Collections .singletonMap ("foo" , "baroverride" ));
514+ PropertySource p3 = new PropertySource (
515+ "git@github.com:demo/support-configuration-repo.git/Config resource 'file [/var/folders/k3/zv8hzdm17vv69j485fv3cf9r0000gp/T/config-repo-14772121892716396795/commons/application.properties' via location 'commons/' (document #0)" ,
516+ Collections .singletonMap ("hello" , "world" ));
517+ PropertySource p4 = new PropertySource ("aws:secrets:/secret/application-name_profile" ,
518+ Collections .singletonMap ("hello" , "world" ));
519+ Map <String , Object > activatesOnProfileCamelCase = new HashMap <>();
520+ activatesOnProfileCamelCase .put ("spring.config.activate.onProfile" , "foo" );
521+ PropertySource p5 = new PropertySource (
522+ "git@github.com:demo/support-configuration-repo.git/Config resource 'file [/var/folders/k3/zv8hzdm17vv69j485fv3cf9r0000gp/T/config-repo-14772121892716396795/commons/application.properties' via location 'commons/' (document #1)" ,
523+ activatesOnProfileCamelCase );
524+ Map <String , Object > activatesOnProfile = new HashMap <>();
525+ activatesOnProfile .put ("spring.config.activate.on-profile" , "foo" );
526+ PropertySource p6 = new PropertySource (
527+ "ssh://git@stash.int.openbet.com:7999/dbs/environments.git/Config resource 'file [/tmp/config-repo-16512912790018624282/platform/pinnacle-def.yaml' via location 'platform/' (document#0)" ,
528+ activatesOnProfile );
529+ ConfigData configData = setupConfigServerConfigDataLoader (Arrays .asList (p6 , p5 , p4 , p3 , p2 , p1 ),
530+ "application-slash" , "def" );
531+ assertThat (configData .getPropertySources ()).hasSize (7 );
532+ assertThat (configData .getOptions (configData .getPropertySources ().get (0 ))
533+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isFalse ();
534+ assertThat (configData .getOptions (configData .getPropertySources ().get (1 ))
535+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isTrue ();
536+ assertThat (configData .getOptions (configData .getPropertySources ().get (2 ))
537+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isFalse ();
538+ assertThat (configData .getOptions (configData .getPropertySources ().get (3 ))
539+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isFalse ();
540+ assertThat (configData .getOptions (configData .getPropertySources ().get (4 ))
541+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isFalse ();
542+ assertThat (configData .getOptions (configData .getPropertySources ().get (5 ))
543+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isFalse ();
544+ assertThat (configData .getOptions (configData .getPropertySources ().get (6 ))
545+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isTrue ();
546+ }
547+
548+ @ Test
549+ void testProfileSpecificPropertySourcesWithDefaultProfile () {
550+ PropertySource p1 = new PropertySource ("overrides" , Collections .singletonMap ("foo" , "bar" ));
551+ PropertySource p2 = new PropertySource ("classpath:/test-default/config-client/application.yaml" ,
552+ Collections .singletonMap ("foo" , "baroverride" ));
553+ PropertySource p3 = new PropertySource (
554+ "git@github.com:demo/support-configuration-repo.git/Config resource 'file [/var/folders/k3/zv8hzdm17vv69j485fv3cf9r0000gp/T/config-repo-14772121892716396795/commons/application.properties' via location 'commons/' (document #0)" ,
555+ Collections .singletonMap ("hello" , "world" ));
556+ PropertySource p4 = new PropertySource ("aws:secrets:/secret/application-name_profile" ,
557+ Collections .singletonMap ("hello" , "world" ));
558+ ConfigData configData = setupConfigServerConfigDataLoader (Arrays .asList (p4 , p3 , p2 , p1 ), "application-slash" ,
559+ "default" );
560+ assertThat (configData .getPropertySources ()).hasSize (5 );
561+ assertThat (configData .getOptions (configData .getPropertySources ().get (0 ))
562+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isFalse ();
563+ assertThat (configData .getOptions (configData .getPropertySources ().get (1 ))
564+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isTrue ();
565+ assertThat (configData .getOptions (configData .getPropertySources ().get (2 ))
566+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isFalse ();
567+ assertThat (configData .getOptions (configData .getPropertySources ().get (3 ))
568+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isFalse ();
569+ assertThat (configData .getOptions (configData .getPropertySources ().get (4 ))
570+ .contains (ConfigData .Option .PROFILE_SPECIFIC )).isFalse ();
571+ }
572+
509573 private ConfigData setupConfigServerConfigDataLoader (List <PropertySource > propertySources , String applicationName ,
510574 String ... profileList ) {
511575 RestTemplate rest = mock (RestTemplate .class );
0 commit comments