diff --git a/CHANGELOG.md b/CHANGELOG.md index b960e1e..e9f65e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.0.3] - 2024-04-02 + +* `wise.environments.active` property was renamed to `wise.profiles.active`. + +* "Environment" and "active profile" terms were separated in the code. + +* Now defaulting to 'WISE' active profile. + ## [0.0.2] - 2024-03-27 Initial version. \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index c623543..5c06d51 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.0.2 \ No newline at end of file +version=0.0.3 \ No newline at end of file diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/CachingWiseActiveProfilesProvider.java b/wise-environment-starter/src/main/java/com/wise/common/environment/CachingWiseActiveProfilesProvider.java new file mode 100644 index 0000000..a7413e9 --- /dev/null +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/CachingWiseActiveProfilesProvider.java @@ -0,0 +1,39 @@ +package com.wise.common.environment; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class CachingWiseActiveProfilesProvider implements WiseActiveProfilesProvider { + + private final List activeProfiles; + + private Map isActiveCache = new ConcurrentHashMap<>(); + + public CachingWiseActiveProfilesProvider(List activeProfiles) { + this.activeProfiles = activeProfiles; + } + + @Override + public List getActiveProfiles() { + return activeProfiles; + } + + @Override + public boolean isProfileActive(WiseProfile profile) { + return isActiveCache.computeIfAbsent(profile, k -> { + var activeProfiles = getActiveProfiles(); + + for (var activeProfile : activeProfiles) { + while (activeProfile != null) { + if (activeProfile == profile) { + return true; + } + activeProfile = activeProfile.parent(); + } + } + + return false; + }); + } +} diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/CachingWiseEnvironmentProvider.java b/wise-environment-starter/src/main/java/com/wise/common/environment/CachingWiseEnvironmentProvider.java deleted file mode 100644 index 95bdc1f..0000000 --- a/wise-environment-starter/src/main/java/com/wise/common/environment/CachingWiseEnvironmentProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.wise.common.environment; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -public class CachingWiseEnvironmentProvider implements WiseEnvironmentProvider { - - private final List activeEnvironments; - - private Map isActiveCache = new ConcurrentHashMap<>(); - - public CachingWiseEnvironmentProvider(List activeEnvironments) { - this.activeEnvironments = activeEnvironments; - } - - @Override - public List getActiveEnvironments() { - return activeEnvironments; - } - - @Override - public boolean isEnvironmentActive(WiseEnvironment environment) { - return isActiveCache.computeIfAbsent(environment, k -> { - var activeEnvironments = getActiveEnvironments(); - - for (var activeEnvironment : activeEnvironments) { - while (activeEnvironment != null) { - if (activeEnvironment == environment) { - return true; - } - activeEnvironment = activeEnvironment.parent(); - } - } - - return false; - }); - } -} diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/DefaultPropertiesSetterDsl.java b/wise-environment-starter/src/main/java/com/wise/common/environment/DefaultPropertiesSetterDsl.java index d59ac25..df79da8 100644 --- a/wise-environment-starter/src/main/java/com/wise/common/environment/DefaultPropertiesSetterDsl.java +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/DefaultPropertiesSetterDsl.java @@ -3,7 +3,7 @@ public class DefaultPropertiesSetterDsl implements PropertiesSetterDsl { private String source; - private WiseEnvironment wiseEnvironment; + private WiseProfile wiseProfile; private String keyPrefix; @@ -20,8 +20,8 @@ public Dsl0 source(String source) { class Dsl0Impl implements Dsl0 { @Override - public Dsl2 environment(WiseEnvironment wiseEnvironment) { - DefaultPropertiesSetterDsl.this.wiseEnvironment = wiseEnvironment; + public Dsl2 profile(WiseProfile profile) { + DefaultPropertiesSetterDsl.this.wiseProfile = profile; return dsl2; } @@ -35,8 +35,8 @@ public Dsl1 keyPrefix(String keyPrefix) { class Dsl1Impl implements Dsl1 { @Override - public Dsl2 environment(WiseEnvironment wiseEnvironment) { - DefaultPropertiesSetterDsl.this.wiseEnvironment = wiseEnvironment; + public Dsl2 profile(WiseProfile profile) { + DefaultPropertiesSetterDsl.this.wiseProfile = profile; return dsl2; } } @@ -44,8 +44,8 @@ public Dsl2 environment(WiseEnvironment wiseEnvironment) { class Dsl2Impl implements Dsl2 { @Override - public Dsl2 environment(WiseEnvironment wiseEnvironment) { - DefaultPropertiesSetterDsl.this.wiseEnvironment = wiseEnvironment; + public Dsl2 profile(WiseProfile profile) { + DefaultPropertiesSetterDsl.this.wiseProfile = profile; return this; } @@ -57,7 +57,7 @@ public Dsl2 keyPrefix(String keyPrefix) { @Override public Dsl2 set(String name, Object value) { - WiseEnvironment.setDefaultProperty(source, wiseEnvironment, keyPrefix == null ? name : keyPrefix + name, value); + WiseEnvironment.setDefaultProperty(source, wiseProfile, keyPrefix == null ? name : keyPrefix + name, value); return this; } } diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/DefaultWiseEnvironmentDetector.java b/wise-environment-starter/src/main/java/com/wise/common/environment/DefaultWiseEnvironmentDetector.java index d2692d7..f630bad 100644 --- a/wise-environment-starter/src/main/java/com/wise/common/environment/DefaultWiseEnvironmentDetector.java +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/DefaultWiseEnvironmentDetector.java @@ -13,21 +13,21 @@ public DefaultWiseEnvironmentDetector(String value) { } @Override - public List detect() { - final var result = new ArrayList(); + public List detectActiveProfiles() { + final var result = new ArrayList(); final var envs = StringUtils.split(value, ","); if (envs != null) { for (var env : envs) { final var trimmedEnv = StringUtils.trim(env); - result.add(WiseEnvironment.getByName(trimmedEnv)); + result.add(WiseProfile.getByName(trimmedEnv)); } } if (result.isEmpty()) { if (isExecutedByIntegrationTest()) { - result.add(WiseEnvironment.INTEGRATION_TEST); + result.add(WiseProfile.INTEGRATION_TEST); } else if (isExecutedByTest()) { - result.add(WiseEnvironment.UNIT_TEST); + result.add(WiseProfile.UNIT_TEST); } } diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/PropertiesSetterDsl.java b/wise-environment-starter/src/main/java/com/wise/common/environment/PropertiesSetterDsl.java index dbc33ad..59cdcc3 100644 --- a/wise-environment-starter/src/main/java/com/wise/common/environment/PropertiesSetterDsl.java +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/PropertiesSetterDsl.java @@ -6,20 +6,20 @@ public interface PropertiesSetterDsl { interface Dsl0 { - Dsl2 environment(WiseEnvironment environment); + Dsl2 profile(WiseProfile profile); Dsl1 keyPrefix(String prefix); } interface Dsl1 { - Dsl2 environment(WiseEnvironment wiseEnvironment); + Dsl2 profile(WiseProfile profile); } interface Dsl2 { - Dsl2 environment(WiseEnvironment environment); + Dsl2 profile(WiseProfile profile); Dsl2 keyPrefix(String keyPrefix); diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/PropertyContainer.java b/wise-environment-starter/src/main/java/com/wise/common/environment/PropertyContainer.java index ac88f80..62d68fb 100644 --- a/wise-environment-starter/src/main/java/com/wise/common/environment/PropertyContainer.java +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/PropertyContainer.java @@ -11,30 +11,30 @@ public class PropertyContainer { private Object value; - private WiseEnvironmentOrigin origin; + private WiseEnvironmentPropertyOrigin origin; - public PropertyContainer(String source, WiseEnvironment environment, Object value) { + public PropertyContainer(String source, WiseProfile profile, Object value) { Assert.notNull(value, "Value must not be null"); - this.origin = new WiseEnvironmentOrigin(source, environment); + this.origin = new WiseEnvironmentPropertyOrigin(source, profile); this.value = value; } @Data - public static class WiseEnvironmentOrigin implements Origin { + public static class WiseEnvironmentPropertyOrigin implements Origin { private String source; - private WiseEnvironment environment; + private WiseProfile profile; - public WiseEnvironmentOrigin(String source, WiseEnvironment environment) { + public WiseEnvironmentPropertyOrigin(String source, WiseProfile profile) { Assert.notNull(source, "Source must not be null"); - Assert.notNull(environment, "Environment must not be null"); + Assert.notNull(profile, "Profile must not be null"); this.source = source; - this.environment = environment; + this.profile = profile; } public String toString() { - return "Wise environment: '" + environment + "', source: '" + source + "'"; + return "Wise profile: '" + profile + "', source: '" + source + "'"; } } } diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseActiveProfilesProvider.java b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseActiveProfilesProvider.java new file mode 100644 index 0000000..0a58454 --- /dev/null +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseActiveProfilesProvider.java @@ -0,0 +1,10 @@ +package com.wise.common.environment; + +import java.util.List; + +public interface WiseActiveProfilesProvider { + + List getActiveProfiles(); + + boolean isProfileActive(WiseProfile profile); +} diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironment.java b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironment.java index 6e42d55..f1e62c4 100644 --- a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironment.java +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironment.java @@ -1,100 +1,57 @@ package com.wise.common.environment; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; -import java.util.stream.Collectors; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -@Slf4j -public enum WiseEnvironment { - WISE, +public class WiseEnvironment { - PRODUCTION(WISE), - PCI_PLASTIC_PRODUCTION(PRODUCTION), + private static WiseActiveProfilesProvider wiseActiveProfilesProvider; - STAGING(WISE), - CUSTOM_ENVIRONMENT(STAGING), - SANDBOX(STAGING), - PCI_PLASTIC_STAGING(STAGING), + static final Map> defaultProperties = new ConcurrentHashMap<>(); + private static final Map, String[]> defaultPropertyNamesCache = new ConcurrentHashMap<>(); - TEST(WISE), - INTEGRATION_TEST(TEST), - UNIT_TEST(TEST), - - DEVELOPMENT(WISE), - - DEVELOPMENT_AGAINST_CUSTOM_ENVIRONMENT(DEVELOPMENT); - - private WiseEnvironment parent; - - WiseEnvironment() { - } - - WiseEnvironment(WiseEnvironment parent) { - this.parent = parent; - } - - public WiseEnvironment parent() { - return parent; - } - - private static final Map NAME_INDEX = - Arrays.stream(WiseEnvironment.values()).collect(Collectors.toMap(we -> we.name().toLowerCase(), we -> we)); - - public static WiseEnvironment getByName(String name) { - return StringUtils.isAllLowerCase(name) ? NAME_INDEX.get(name) : NAME_INDEX.get(name.toLowerCase()); - } - - private static final Map> defaultProperties = new ConcurrentHashMap<>(); - - private static final Map, String[]> defaultPropertyNamesCache = new ConcurrentHashMap<>(); - - private static WiseEnvironmentProvider wiseEnvironmentProvider; - - public static void init(List activeEnvironments) { - wiseEnvironmentProvider = new CachingWiseEnvironmentProvider(activeEnvironments); + public static void init(List activeProfiles) { + wiseActiveProfilesProvider = new CachingWiseActiveProfilesProvider(activeProfiles); } public static void setDefaultProperty(String source, String name, Object value) { - setDefaultProperty(source, WiseEnvironment.WISE, name, value); + setDefaultProperty(source, WiseProfile.WISE, name, value); } - public static void setDefaultProperty(String source, WiseEnvironment wiseEnvironment, String name, Object value) { + public static void setDefaultProperty(String source, WiseProfile wiseProfile, String name, Object value) { defaultProperties - .computeIfAbsent(wiseEnvironment, k -> new ConcurrentHashMap<>()) - .put(name, new PropertyContainer(source, wiseEnvironment, value)); + .computeIfAbsent(wiseProfile, k -> new ConcurrentHashMap<>()) + .put(name, new PropertyContainer(source, wiseProfile, value)); defaultPropertyNamesCache.clear(); } - public static List getActiveEnvironments() { - return wiseEnvironmentProvider.getActiveEnvironments(); + public static List getActiveProfiles() { + return wiseActiveProfilesProvider.getActiveProfiles(); } - public static boolean isEnvironmentActive(WiseEnvironment environment) { - return wiseEnvironmentProvider.isEnvironmentActive(environment); + public static boolean isProfileActive(WiseProfile profile) { + return wiseActiveProfilesProvider.isProfileActive(profile); } static PropertyContainer getDefaultPropertyContainer(String name) { - var activeEnvironments = getActiveEnvironments(); - - if (activeEnvironments != null) { - for (var activeEnvironment : activeEnvironments) { - while (activeEnvironment != null) { - var envProps = WiseEnvironment.defaultProperties.get(activeEnvironment); - if (envProps != null) { - var value = envProps.get(name); + var activeProfiles = getActiveProfiles(); + + if (activeProfiles != null) { + for (var activeProfile : activeProfiles) { + while (activeProfile != null) { + var props = defaultProperties.get(activeProfile); + if (props != null) { + var value = props.get(name); if (value != null) { return value; } } - activeEnvironment = activeEnvironment.parent(); + activeProfile = activeProfile.parent(); } } } @@ -108,23 +65,23 @@ public static Object getDefaultProperty(String name) { } public static String[] getDefaultPropertyNames() { - var activeEnvironments = getActiveEnvironments(); + var activeProfiles = getActiveProfiles(); - if (activeEnvironments == null) { + if (activeProfiles == null) { return new String[0]; } - return defaultPropertyNamesCache.computeIfAbsent(activeEnvironments, k -> { + return defaultPropertyNamesCache.computeIfAbsent(activeProfiles, k -> { var result = new HashSet(); - for (var activeEnvironment : activeEnvironments) { - while (activeEnvironment != null) { - var envProps = WiseEnvironment.defaultProperties.get(activeEnvironment); - if (envProps != null) { - result.addAll(envProps.keySet()); + for (var activeProfile : activeProfiles) { + while (activeProfile != null) { + var props = defaultProperties.get(activeProfile); + if (props != null) { + result.addAll(props.keySet()); } - activeEnvironment = activeEnvironment.parent(); + activeProfile = activeProfile.parent(); } } return result.toArray(new String[0]); diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentDetector.java b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentDetector.java index c72534d..dd192c6 100644 --- a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentDetector.java +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentDetector.java @@ -4,5 +4,5 @@ public interface WiseEnvironmentDetector { - List detect(); + List detectActiveProfiles(); } diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentEnvironmentPostProcessor.java b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentEnvironmentPostProcessor.java index f7d62c3..1001603 100644 --- a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentEnvironmentPostProcessor.java +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentEnvironmentPostProcessor.java @@ -2,8 +2,10 @@ import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.logging.Log; import org.springframework.boot.SpringApplication; import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.boot.logging.DeferredLogFactory; import org.springframework.core.annotation.Order; import org.springframework.core.env.ConfigurableEnvironment; @@ -11,19 +13,33 @@ @Order public class WiseEnvironmentEnvironmentPostProcessor implements EnvironmentPostProcessor { + private final Log log; + + public WiseEnvironmentEnvironmentPostProcessor(DeferredLogFactory deferredLogFactory) { + log = deferredLogFactory.getLog(WiseEnvironmentEnvironmentPostProcessor.class); + } + @Override - public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - var wiseEnvironmentDetector = new DefaultWiseEnvironmentDetector(environment.getProperty("wise.environments.active")); - final var activeEnvironments = wiseEnvironmentDetector.detect(); + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication springApplication) { + var propValue = environment.getProperty("wise.profiles.active"); + if (propValue == null) { + // Deprecated property, can be removed later. + propValue = environment.getProperty("wise.environments.active"); + } + + var wiseEnvironmentDetector = new DefaultWiseEnvironmentDetector(propValue); + final var activeEnvironments = wiseEnvironmentDetector.detectActiveProfiles(); if (activeEnvironments.isEmpty()) { - log.info("No active Wise environments detected."); + log.info("No active Wise profile detected. Defaulting to 'WISE'."); + activeEnvironments.add(WiseProfile.WISE); } else { - log.info("Active Wise environments detected are '{}'.", activeEnvironments.stream().map(Enum::name).collect(Collectors.joining(","))); + log.info("Active Wise profiles detected are '" + activeEnvironments.stream().map(Enum::name).collect(Collectors.joining(",")) + "'."); } WiseEnvironment.init(activeEnvironments); environment.getPropertySources().addLast(new WiseEnvironmentDefaultsPropertySource()); } + } diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentProvider.java b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentProvider.java deleted file mode 100644 index d305e53..0000000 --- a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseEnvironmentProvider.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.wise.common.environment; - -import java.util.List; - -public interface WiseEnvironmentProvider { - - List getActiveEnvironments(); - - boolean isEnvironmentActive(WiseEnvironment environment); -} diff --git a/wise-environment-starter/src/main/java/com/wise/common/environment/WiseProfile.java b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseProfile.java new file mode 100644 index 0000000..95b1a80 --- /dev/null +++ b/wise-environment-starter/src/main/java/com/wise/common/environment/WiseProfile.java @@ -0,0 +1,48 @@ +package com.wise.common.environment; + +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +@Slf4j +public enum WiseProfile { + WISE, + + PRODUCTION(WISE), + PCI_PLASTIC_PRODUCTION(PRODUCTION), + + STAGING(WISE), + CUSTOM_ENVIRONMENT(STAGING), + SANDBOX(STAGING), + PCI_PLASTIC_STAGING(STAGING), + + TEST(WISE), + INTEGRATION_TEST(TEST), + UNIT_TEST(TEST), + + DEVELOPMENT(WISE), + + DEVELOPMENT_AGAINST_CUSTOM_ENVIRONMENT(DEVELOPMENT); + + private WiseProfile parent; + + WiseProfile() { + } + + WiseProfile(WiseProfile parent) { + this.parent = parent; + } + + public WiseProfile parent() { + return parent; + } + + private static final Map NAME_INDEX = + Arrays.stream(WiseProfile.values()).collect(Collectors.toMap(we -> we.name().toLowerCase(), we -> we)); + + public static WiseProfile getByName(String name) { + return StringUtils.isAllLowerCase(name) ? NAME_INDEX.get(name) : NAME_INDEX.get(name.toLowerCase()); + } +} diff --git a/wise-environment-starter/src/test/java/com/wise/common/environment/Application1IntTest.java b/wise-environment-starter/src/test/java/com/wise/common/environment/Application1IntTest.java index c7e427e..df791aa 100644 --- a/wise-environment-starter/src/test/java/com/wise/common/environment/Application1IntTest.java +++ b/wise-environment-starter/src/test/java/com/wise/common/environment/Application1IntTest.java @@ -12,8 +12,8 @@ public class Application1IntTest { @Test void applicationIsConfigured() { - assertTrue(WiseEnvironment.isEnvironmentActive(WiseEnvironment.PCI_PLASTIC_STAGING)); - assertTrue(WiseEnvironment.isEnvironmentActive(WiseEnvironment.STAGING)); + assertTrue(WiseEnvironment.isProfileActive(WiseProfile.PCI_PLASTIC_STAGING)); + assertTrue(WiseEnvironment.isProfileActive(WiseProfile.STAGING)); } } diff --git a/wise-environment-starter/src/test/java/com/wise/common/environment/Application2IntTest.java b/wise-environment-starter/src/test/java/com/wise/common/environment/Application2IntTest.java index c12e920..6d9a146 100644 --- a/wise-environment-starter/src/test/java/com/wise/common/environment/Application2IntTest.java +++ b/wise-environment-starter/src/test/java/com/wise/common/environment/Application2IntTest.java @@ -13,10 +13,10 @@ public class Application2IntTest { @Test void applicationIsConfigured() { - assertTrue(WiseEnvironment.isEnvironmentActive(WiseEnvironment.PCI_PLASTIC_STAGING)); - assertTrue(WiseEnvironment.isEnvironmentActive(WiseEnvironment.STAGING)); - assertTrue(WiseEnvironment.isEnvironmentActive(WiseEnvironment.DEVELOPMENT)); - assertFalse(WiseEnvironment.isEnvironmentActive(WiseEnvironment.DEVELOPMENT_AGAINST_CUSTOM_ENVIRONMENT)); + assertTrue(WiseEnvironment.isProfileActive(WiseProfile.PCI_PLASTIC_STAGING)); + assertTrue(WiseEnvironment.isProfileActive(WiseProfile.STAGING)); + assertTrue(WiseEnvironment.isProfileActive(WiseProfile.DEVELOPMENT)); + assertFalse(WiseEnvironment.isProfileActive(WiseProfile.DEVELOPMENT_AGAINST_CUSTOM_ENVIRONMENT)); } } diff --git a/wise-environment-starter/src/test/java/com/wise/common/environment/ApplicationIntTest.java b/wise-environment-starter/src/test/java/com/wise/common/environment/ApplicationIntTest.java index 92bfa2e..5214f44 100644 --- a/wise-environment-starter/src/test/java/com/wise/common/environment/ApplicationIntTest.java +++ b/wise-environment-starter/src/test/java/com/wise/common/environment/ApplicationIntTest.java @@ -18,30 +18,31 @@ public class ApplicationIntTest { @Test void applicationIsConfigured() { - assertTrue(WiseEnvironment.isEnvironmentActive(WiseEnvironment.TEST)); - assertTrue(WiseEnvironment.isEnvironmentActive(WiseEnvironment.INTEGRATION_TEST)); - assertFalse(WiseEnvironment.isEnvironmentActive(WiseEnvironment.UNIT_TEST)); + assertTrue(WiseEnvironment.isProfileActive(WiseProfile.TEST)); + assertTrue(WiseEnvironment.isProfileActive(WiseProfile.INTEGRATION_TEST)); + assertFalse(WiseEnvironment.isProfileActive(WiseProfile.UNIT_TEST)); } @Test void defaultsCanBeSet() { WiseEnvironment.setDefaultProperty("mySource", "mykey", "robot"); - WiseEnvironment.setDefaultProperty("mySource", WiseEnvironment.TEST, "mykey", "cat"); + WiseEnvironment.setDefaultProperty("mySource", WiseProfile.TEST, "mykey", "cat"); assertThat(environment.getProperty("mykey"), equalTo("cat")); - assertThat(WiseEnvironment.getDefaultPropertyContainer("mykey").getOrigin().getEnvironment(), equalTo(WiseEnvironment.TEST)); + assertThat(WiseEnvironment.getDefaultPropertyContainer("mykey").getOrigin().getProfile(), equalTo(WiseProfile.TEST)); - WiseEnvironment.setDefaultProperty("mySource", WiseEnvironment.INTEGRATION_TEST, "mykey", "dog"); + WiseEnvironment.setDefaultProperty("mySource", WiseProfile.INTEGRATION_TEST, "mykey", "dog"); assertThat(environment.getProperty("mykey"), equalTo("dog")); - assertThat(WiseEnvironment.getDefaultPropertyContainer("mykey").getOrigin().getEnvironment(), equalTo(WiseEnvironment.INTEGRATION_TEST)); + assertThat(WiseEnvironment.getDefaultPropertyContainer("mykey").getOrigin().getProfile(), equalTo( + WiseProfile.INTEGRATION_TEST)); WiseEnvironment.setDefaultProperties(dsl -> dsl .source("mySource") - .environment(WiseEnvironment.UNIT_TEST) + .profile(WiseProfile.UNIT_TEST) .keyPrefix("prefix.") .set("myotherkey", "horse") - .environment(WiseEnvironment.TEST) + .profile(WiseProfile.TEST) .set("myotherkey", "mouse") .keyPrefix(null) .set("onemorekey", "moose") diff --git a/wise-environment-starter/src/test/resources/application.yml b/wise-environment-starter/src/test/resources/application.yml index ab7756c..80d9779 100644 --- a/wise-environment-starter/src/test/resources/application.yml +++ b/wise-environment-starter/src/test/resources/application.yml @@ -3,7 +3,7 @@ spring: activate: on-profile: application1 -wise.environments.active: pci_plastic_staging +wise.profiles.active: pci_plastic_staging --- @@ -12,4 +12,4 @@ spring: activate: on-profile: application2 -wise.environments.active: development, staging, pci_plastic_staging \ No newline at end of file +wise.profiles.active: development, staging, pci_plastic_staging \ No newline at end of file