diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicator.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicator.java index a57ae7c1bf..08c2e08b79 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicator.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicator.java @@ -35,6 +35,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.environment.EnvironmentRepository; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.util.CollectionUtils; /** @@ -74,8 +75,8 @@ protected void doHealthCheck(Health.Builder builder) { String profiles = repository.getProfiles(); try { - Environment environment = this.environmentRepository.findOne(application, profiles, - repository.getLabel(), false); + Environment environment = this.environmentRepository.findOne(new RequestContext.Builder() + .name(application).profiles(profiles).label(repository.getLabel()).build()); HashMap detail = new HashMap<>(); detail.put("name", environment.getName()); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AbstractScmEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AbstractScmEnvironmentRepository.java index 3b8a253cd2..4392718334 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AbstractScmEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AbstractScmEnvironmentRepository.java @@ -21,6 +21,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.support.AbstractScmAccessor; import org.springframework.cloud.config.server.support.AbstractScmAccessorProperties; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.Ordered; import org.springframework.core.env.ConfigurableEnvironment; @@ -51,19 +52,14 @@ public AbstractScmEnvironmentRepository(ConfigurableEnvironment environment, } @Override - public synchronized Environment findOne(String application, String profile, String label) { - return findOne(application, profile, label, false); - } - - @Override - public synchronized Environment findOne(String application, String profile, String label, boolean includeOrigin) { + public synchronized Environment findOne(RequestContext ctx) { NativeEnvironmentRepository delegate = new NativeEnvironmentRepository(getEnvironment(), new NativeEnvironmentProperties(), this.observationRegistry); - Locations locations = getLocations(application, profile, label); + Locations locations = getLocations(ctx); delegate.setSearchLocations(locations.getLocations()); - Environment result = delegate.findOne(application, profile, "", includeOrigin); + Environment result = delegate.findOne(ctx.toBuilder().label("").build()); result.setVersion(locations.getVersion()); - result.setLabel(label); + result.setLabel(ctx.getLabel()); return this.cleaner.clean(result, getWorkingDirectory().toURI().toString(), getUri()); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AbstractVaultEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AbstractVaultEnvironmentRepository.java index 7d47d6437e..6c82aaaaad 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AbstractVaultEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AbstractVaultEnvironmentRepository.java @@ -31,6 +31,7 @@ import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.Ordered; import org.springframework.core.io.ByteArrayResource; import org.springframework.util.StringUtils; @@ -77,13 +78,13 @@ public AbstractVaultEnvironmentRepository(ObjectProvider req } @Override - public Environment findOne(String application, String profile, String label) { - String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); + public Environment findOne(RequestContext ctx) { + String[] profiles = StringUtils.commaDelimitedListToStringArray(ctx.getProfiles()); List scrubbedProfiles = scrubProfiles(profiles); - List keys = findKeys(application, scrubbedProfiles); + List keys = findKeys(ctx.getName(), scrubbedProfiles); - Environment environment = new Environment(application, profiles, label, null, getWatchState()); + Environment environment = new Environment(ctx.getName(), profiles, ctx.getLabel(), null, getWatchState()); for (String key : keys) { // read raw 'data' key from vault diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepository.java index 9510d4dc5c..80f3c90f19 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepository.java @@ -35,6 +35,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.config.ConfigServerProperties; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.Ordered; import org.springframework.util.StringUtils; @@ -62,18 +63,15 @@ public AwsParameterStoreEnvironmentRepository(SsmClient awsSsmClient, ConfigServ } @Override - public Environment findOne(String application, String profile, String label) { - if (!StringUtils.hasLength(application)) { - application = configServerProperties.getDefaultApplicationName(); - } - - if (!StringUtils.hasLength(profile)) { - profile = configServerProperties.getDefaultProfile(); - } + public Environment findOne(RequestContext ctx) { + String application = StringUtils.hasLength(ctx.getName()) ? ctx.getName() + : configServerProperties.getDefaultApplicationName(); + String profile = StringUtils.hasLength(ctx.getProfiles()) ? ctx.getProfiles() + : configServerProperties.getDefaultProfile(); String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); - Environment result = new Environment(application, profiles, label, null, null); + Environment result = new Environment(application, profiles, ctx.getLabel(), null, null); Set paths = buildParameterPaths(application, profiles); List propertySources = getPropertySources(paths); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java index e815eda091..fba2d8a313 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java @@ -34,6 +34,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.config.ConfigServerProperties; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.Ordered; import org.springframework.core.io.InputStreamResource; import org.springframework.util.ObjectUtils; @@ -76,12 +77,12 @@ public void setOrder(int order) { } @Override - public Environment findOne(String specifiedApplication, String specifiedProfiles, String specifiedLabel) { - final String application = ObjectUtils.isEmpty(specifiedApplication) - ? serverProperties.getDefaultApplicationName() : specifiedApplication; - final String profiles = ObjectUtils.isEmpty(specifiedProfiles) ? serverProperties.getDefaultProfile() - : specifiedProfiles; - final String label = ObjectUtils.isEmpty(specifiedLabel) ? serverProperties.getDefaultLabel() : specifiedLabel; + public Environment findOne(RequestContext ctx) { + final String application = ObjectUtils.isEmpty(ctx.getName()) ? serverProperties.getDefaultApplicationName() + : ctx.getName(); + final String profiles = ObjectUtils.isEmpty(ctx.getProfiles()) ? serverProperties.getDefaultProfile() + : ctx.getProfiles(); + final String label = ObjectUtils.isEmpty(ctx.getLabel()) ? serverProperties.getDefaultLabel() : ctx.getLabel(); String[] profileArray = parseProfiles(profiles); List apps = Arrays.asList(StringUtils.commaDelimitedListToStringArray(application.replace(" ", ""))); @@ -204,7 +205,9 @@ private ResponseInputStream getObject(String key) throws Exce } @Override - public Locations getLocations(String application, String profiles, String label) { + public Locations getLocations(RequestContext ctx) { + String label = ctx.getLabel(); + StringBuilder baseLocation = new StringBuilder(AWS_S3_RESOURCE_SCHEME + bucketName + PATH_SEPARATOR); if (!StringUtils.hasText(label) && StringUtils.hasText(serverProperties.getDefaultLabel())) { label = serverProperties.getDefaultLabel(); @@ -214,7 +217,7 @@ public Locations getLocations(String application, String profiles, String label) baseLocation.append(label); } - return new Locations(application, profiles, label, null, new String[] { baseLocation.toString() }); + return new Locations(ctx.getName(), ctx.getProfiles(), label, null, new String[] { baseLocation.toString() }); } } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepository.java index e497b8b715..f3d2911b44 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepository.java @@ -37,6 +37,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.config.ConfigServerProperties; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.Ordered; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -72,26 +73,15 @@ public AwsSecretsManagerEnvironmentRepository(SecretsManagerClient awsSmClient, } @Override - public Environment findOne(String application, String profileList, String label) { + public Environment findOne(RequestContext ctx) { final String defaultApplication = configServerProperties.getDefaultApplicationName(); final String defaultProfile = configServerProperties.getDefaultProfile(); final String defaultLabel = environmentProperties.getDefaultLabel(); final boolean ignoreLabel = environmentProperties.isIgnoreLabel(); - if (ObjectUtils.isEmpty(application)) { - application = defaultApplication; - } - - if (ObjectUtils.isEmpty(profileList)) { - profileList = defaultProfile; - } - - if (ignoreLabel) { - label = null; - } - else if (StringUtils.isEmpty(label)) { - label = defaultLabel; - } + String application = ObjectUtils.isEmpty(ctx.getName()) ? defaultApplication : ctx.getName(); + String profileList = ObjectUtils.isEmpty(ctx.getProfiles()) ? defaultProfile : ctx.getProfiles(); + String label = ignoreLabel ? null : (StringUtils.isEmpty(ctx.getLabel()) ? defaultLabel : ctx.getLabel()); String[] profiles = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(profileList)); Environment environment = new Environment(application, profiles, label, null, null); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepository.java index 01802a3d48..c3b6dfa209 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepository.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.OrderComparator; /** @@ -71,16 +72,11 @@ public CompositeEnvironmentRepository(List environmentRep } @Override - public Environment findOne(String application, String profile, String label) { - return findOne(application, profile, label, false); - } - - @Override - public Environment findOne(String application, String profile, String label, boolean includeOrigin) { - Environment env = new Environment(application, new String[] { profile }, label, null, null); + public Environment findOne(RequestContext ctx) { + Environment env = new Environment(ctx.getName(), new String[] { ctx.getProfiles() }, ctx.getLabel(), null, + null); if (this.environmentRepositories.size() == 1) { - Environment envRepo = this.environmentRepositories.get(0).findOne(application, profile, label, - includeOrigin); + Environment envRepo = this.environmentRepositories.get(0).findOne(ctx); env.addAll(envRepo.getPropertySources()); env.setVersion(envRepo.getVersion()); env.setState(envRepo.getState()); @@ -88,7 +84,7 @@ public Environment findOne(String application, String profile, String label, boo else { for (EnvironmentRepository repo : environmentRepositories) { try { - env.addAll(repo.findOne(application, profile, label, includeOrigin).getPropertySources()); + env.addAll(repo.findOne(ctx).getPropertySources()); } catch (Exception e) { if (failOnError) { diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepository.java index 3e0d93356d..6b9cead34e 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepository.java @@ -21,6 +21,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.Ordered; import org.springframework.credhub.core.CredHubOperations; import org.springframework.credhub.support.CredentialDetails; @@ -52,30 +53,26 @@ public CredhubEnvironmentRepository(CredHubOperations credHubOperations) { } @Override - public Environment findOne(String application, String profilesList, String label) { - if (ObjectUtils.isEmpty(profilesList)) { - profilesList = DEFAULT_PROFILE; - } - if (ObjectUtils.isEmpty(label)) { - label = DEFAULT_LABEL; - } + public Environment findOne(RequestContext ctx) { + String profilesList = ObjectUtils.isEmpty(ctx.getProfiles()) ? DEFAULT_PROFILE : ctx.getProfiles(); + String label = ObjectUtils.isEmpty(ctx.getLabel()) ? DEFAULT_LABEL : ctx.getLabel(); String[] profiles = StringUtils.commaDelimitedListToStringArray(profilesList); - Environment environment = new Environment(application, profiles, label, null, null); + Environment environment = new Environment(ctx.getName(), profiles, label, null, null); for (String profile : profiles) { - environment.add(new PropertySource("credhub-" + application + "-" + profile + "-" + label, - findProperties(application, profile, label))); - if (!DEFAULT_APPLICATION.equals(application)) { + environment.add(new PropertySource("credhub-" + ctx.getName() + "-" + profile + "-" + label, + findProperties(ctx.getName(), profile, label))); + if (!DEFAULT_APPLICATION.equals(ctx.getName())) { addDefaultPropertySource(environment, DEFAULT_APPLICATION, profile, label); } } if (!Arrays.asList(profiles).contains(DEFAULT_PROFILE)) { - addDefaultPropertySource(environment, application, DEFAULT_PROFILE, label); + addDefaultPropertySource(environment, ctx.getName(), DEFAULT_PROFILE, label); } - if (!Arrays.asList(profiles).contains(DEFAULT_PROFILE) && !DEFAULT_APPLICATION.equals(application)) { + if (!Arrays.asList(profiles).contains(DEFAULT_PROFILE) && !DEFAULT_APPLICATION.equals(ctx.getName())) { addDefaultPropertySource(environment, DEFAULT_APPLICATION, DEFAULT_PROFILE, label); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java index e8766a3b79..277e4a50e3 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java @@ -37,6 +37,7 @@ import org.springframework.cloud.config.environment.EnvironmentMediaType; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.support.PathUtils; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -107,31 +108,36 @@ public void setAcceptEmpty(boolean acceptEmpty) { @GetMapping(path = "/{name}/{profiles:(?!.*\\b\\.(?:ya?ml|properties|json)\\b).*}", produces = MediaType.APPLICATION_JSON_VALUE) public Environment defaultLabel(@PathVariable String name, @PathVariable String profiles) { - return getEnvironment(name, profiles, null, false); + RequestContext ctx = new RequestContext.Builder().name(normalize(name)).profiles(profiles).build(); + return getEnvironment(ctx); } @GetMapping(path = "/{name}/{profiles:(?!.*\\b\\.(?:ya?ml|properties|json)\\b).*}", produces = EnvironmentMediaType.V2_JSON) public Environment defaultLabelIncludeOrigin(@PathVariable String name, @PathVariable String profiles) { - return getEnvironment(name, profiles, null, true); + RequestContext ctx = new RequestContext.Builder().name(normalize(name)).profiles(profiles).includeOrigin(true) + .build(); + return getEnvironment(ctx); } @GetMapping(path = "/{name}/{profiles}/{label:.*}", produces = MediaType.APPLICATION_JSON_VALUE) public Environment labelled(@PathVariable String name, @PathVariable String profiles, @PathVariable String label) { - return getEnvironment(name, profiles, label, false); + RequestContext ctx = new RequestContext.Builder().name(normalize(name)).profiles(profiles) + .label(normalize(label)).build(); + return getEnvironment(ctx); } @GetMapping(path = "/{name}/{profiles}/{label:.*}", produces = EnvironmentMediaType.V2_JSON) public Environment labelledIncludeOrigin(@PathVariable String name, @PathVariable String profiles, @PathVariable String label) { - return getEnvironment(name, profiles, label, true); + RequestContext ctx = new RequestContext.Builder().name(normalize(name)).profiles(profiles) + .label(normalize(label)).includeOrigin(true).build(); + return getEnvironment(ctx); } - public Environment getEnvironment(String name, String profiles, String label, boolean includeOrigin) { + public Environment getEnvironment(RequestContext ctx) { try { - name = normalize(name); - label = normalize(label); - Environment environment = this.repository.findOne(name, profiles, label, includeOrigin); + Environment environment = this.repository.findOne(ctx); if (!this.acceptEmpty && (environment == null || environment.getPropertySources().isEmpty())) { throw new EnvironmentNotFoundException("Profile Not found"); } @@ -139,7 +145,7 @@ public Environment getEnvironment(String name, String profiles, String label, bo } catch (Exception e) { LOG.warn(String.format("Error getting the Environment with name=%s profiles=%s label=%s includeOrigin=%b", - name, profiles, label, includeOrigin), e); + ctx.getName(), ctx.getProfiles(), ctx.getLabel(), ctx.getIncludeOrigin()), e); throw e; } } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepository.java index 2c3513bc12..4ea13fe3f8 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepository.java @@ -27,6 +27,7 @@ import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.environment.PropertyValueDescriptor; import org.springframework.cloud.config.server.encryption.EnvironmentEncryptor; +import org.springframework.cloud.config.server.support.RequestContext; /** * A delegating {@link EnvironmentRepository} that can decrypt the properties if an @@ -55,20 +56,15 @@ public EnvironmentEncryptorEnvironmentRepository(EnvironmentRepository delegate, } @Override - public Environment findOne(String name, String profiles, String label) { - return findOne(name, profiles, label, false); - } - - @Override - public Environment findOne(String name, String profiles, String label, boolean includeOrigin) { - Environment environment = this.delegate.findOne(name, profiles, label, includeOrigin); + public Environment findOne(RequestContext ctx) { + Environment environment = this.delegate.findOne(ctx); if (this.environmentEncryptors != null) { for (EnvironmentEncryptor environmentEncryptor : environmentEncryptors) { environment = environmentEncryptor.decrypt(environment); } } if (!this.overrides.isEmpty()) { - environment.addFirst(new PropertySource("overrides", getOverridesMap(includeOrigin))); + environment.addFirst(new PropertySource("overrides", getOverridesMap(ctx.getIncludeOrigin()))); } return environment; } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentRepository.java index f4811b3600..b4589c01df 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentRepository.java @@ -17,6 +17,7 @@ package org.springframework.cloud.config.server.environment; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.support.RequestContext; /** * @author Dave Syer @@ -24,10 +25,6 @@ */ public interface EnvironmentRepository { - Environment findOne(String application, String profile, String label); - - default Environment findOne(String application, String profile, String label, boolean includeOrigin) { - return findOne(application, profile, label); - } + Environment findOne(RequestContext ctx); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentRepositoryPropertySourceLocator.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentRepositoryPropertySourceLocator.java index 2274f7d290..449e31dedd 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentRepositoryPropertySourceLocator.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentRepositoryPropertySourceLocator.java @@ -20,6 +20,7 @@ import org.springframework.cloud.bootstrap.config.PropertySourceLocator; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.Environment; import org.springframework.core.env.MapPropertySource; @@ -50,7 +51,8 @@ public EnvironmentRepositoryPropertySourceLocator(EnvironmentRepository reposito @Override public org.springframework.core.env.PropertySource locate(Environment environment) { CompositePropertySource composite = new CompositePropertySource("configService"); - for (PropertySource source : this.repository.findOne(this.name, this.profiles, this.label, false) + for (PropertySource source : this.repository + .findOne(new RequestContext.Builder().name(name).profiles(profiles).label(label).build()) .getPropertySources()) { @SuppressWarnings("unchecked") Map map = (Map) source.getSource(); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/GoogleSecretManagerEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/GoogleSecretManagerEnvironmentRepository.java index b8232d210e..6ae5310f9a 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/GoogleSecretManagerEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/GoogleSecretManagerEnvironmentRepository.java @@ -31,6 +31,7 @@ import org.springframework.cloud.config.server.environment.secretmanager.GoogleSecretManagerAccessStrategy; import org.springframework.cloud.config.server.environment.secretmanager.GoogleSecretManagerAccessStrategyFactory; import org.springframework.cloud.config.server.environment.secretmanager.HttpHeaderGoogleConfigProvider; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.Ordered; import org.springframework.web.client.RestTemplate; @@ -63,7 +64,10 @@ public GoogleSecretManagerEnvironmentRepository(ObjectProvider repos } @Override - public Locations getLocations(String application, String profile, String label) { + public Locations getLocations(RequestContext ctx) { for (PatternMatchingJGitEnvironmentRepository repository : this.repos.values()) { - if (repository.matches(application, profile, label)) { - for (JGitEnvironmentRepository candidate : getRepositories(repository, application, profile, label)) { + if (repository.matches(ctx.getName(), ctx.getProfiles(), ctx.getLabel())) { + for (JGitEnvironmentRepository candidate : getRepositories(repository, ctx.getName(), ctx.getProfiles(), + ctx.getLabel())) { try { - Environment source = candidate.findOne(application, profile, label, false); + Environment source = candidate.findOne(ctx); if (source != null) { - return candidate.getLocations(application, profile, label); + return candidate.getLocations(ctx); } } catch (Exception e) { @@ -139,23 +141,26 @@ public Locations getLocations(String application, String profile, String label) } } } - JGitEnvironmentRepository candidate = getRepository(this, application, profile, label); + JGitEnvironmentRepository candidate = getRepository(this, ctx.getName(), ctx.getProfiles(), ctx.getLabel()); if (candidate == this) { - return super.getLocations(application, profile, label); + return super.getLocations(ctx); } - return candidate.getLocations(application, profile, label); + return candidate.getLocations(ctx); } @Override - public Environment findOne(String application, String profile, String label, boolean includeOrigin) { + public Environment findOne(RequestContext ctx) { + String label = ctx.getLabel(); + for (PatternMatchingJGitEnvironmentRepository repository : this.repos.values()) { - if (repository.matches(application, profile, label)) { - for (JGitEnvironmentRepository candidate : getRepositories(repository, application, profile, label)) { + if (repository.matches(ctx.getName(), ctx.getProfiles(), label)) { + for (JGitEnvironmentRepository candidate : getRepositories(repository, ctx.getName(), ctx.getProfiles(), + label)) { try { if (label == null) { label = candidate.getDefaultLabel(); } - Environment source = candidate.findOne(application, profile, label, includeOrigin); + Environment source = candidate.findOne(ctx.toBuilder().label(label).build()); if (source != null) { return source; } @@ -170,31 +175,30 @@ public Environment findOne(String application, String profile, String label, boo } } } - JGitEnvironmentRepository candidate = getRepository(this, application, profile, label); + JGitEnvironmentRepository candidate = getRepository(this, ctx.getName(), ctx.getProfiles(), label); if (label == null) { label = candidate.getDefaultLabel(); } try { - return findOneFromCandidate(candidate, application, profile, label, includeOrigin); + return findOneFromCandidate(candidate, ctx.toBuilder().label(label).build()); } catch (Exception e) { if (MultipleJGitEnvironmentProperties.MAIN_LABEL.equals(label) && isTryMasterBranch()) { logger.info("Cannot find Environment with default label " + getDefaultLabel(), e); logger.info("Will try to find Environment master label instead."); - candidate = getRepository(this, application, profile, MultipleJGitEnvironmentProperties.MASTER_LABEL); - return findOneFromCandidate(candidate, application, profile, - MultipleJGitEnvironmentProperties.MASTER_LABEL, includeOrigin); + candidate = getRepository(this, ctx.getName(), ctx.getProfiles(), + MultipleJGitEnvironmentProperties.MASTER_LABEL); + return findOneFromCandidate(candidate, ctx); } throw e; } } - private Environment findOneFromCandidate(JGitEnvironmentRepository candidate, String application, String profile, - String label, boolean includeOrigin) { + private Environment findOneFromCandidate(JGitEnvironmentRepository candidate, RequestContext ctx) { if (candidate == this) { - return super.findOne(application, profile, label, includeOrigin); + return super.findOne(ctx); } - return candidate.findOne(application, profile, label, includeOrigin); + return candidate.findOne(ctx); } private List getRepositories(JGitEnvironmentRepository repository, String application, @@ -295,14 +299,14 @@ public boolean matches(String application, String profile, String label) { } @Override - public Environment findOne(String application, String profile, String label, boolean includeOrigin) { + public Environment findOne(RequestContext ctx) { if (this.pattern == null || this.pattern.length == 0) { return null; } - if (PatternMatchUtils.simpleMatch(this.pattern, application + "/" + profile)) { - return super.findOne(application, profile, label, includeOrigin); + if (PatternMatchUtils.simpleMatch(this.pattern, ctx.getName() + "/" + ctx.getProfiles())) { + return super.findOne(ctx); } return null; diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java index ff595aec3a..be2fdbd58f 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java @@ -37,6 +37,7 @@ import org.springframework.boot.context.config.StandardConfigDataResource; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.NestedExceptionUtils; import org.springframework.core.Ordered; import org.springframework.core.env.ConfigurableEnvironment; @@ -131,19 +132,14 @@ public void setDefaultLabel(String defaultLabel) { } @Override - public Environment findOne(String config, String profile, String label) { - return findOne(config, profile, label, false); - } - - @Override - public Environment findOne(String config, String profile, String label, boolean includeOrigin) { + public Environment findOne(RequestContext ctx) { try { - ConfigurableEnvironment environment = getEnvironment(config, profile, label); + ConfigurableEnvironment environment = getEnvironment(ctx); DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); Map, PropertySourceConfigData> propertySourceToConfigData = new HashMap<>(); ConfigDataEnvironmentPostProcessor.applyTo(environment, resourceLoader, null, - StringUtils.commaDelimitedListToSet(profile), new ConfigDataEnvironmentUpdateListener() { + StringUtils.commaDelimitedListToSet(ctx.getProfiles()), new ConfigDataEnvironmentUpdateListener() { @Override public void onPropertySourceAdded(org.springframework.core.env.PropertySource propertySource, ConfigDataLocation location, ConfigDataResource resource) { @@ -154,12 +150,12 @@ public void onPropertySourceAdded(org.springframework.core.env.PropertySource environment.getPropertySources().remove("config-data-setup"); return clean(ObservationEnvironmentRepositoryWrapper - .wrap(this.observationRegistry, new PassthruEnvironmentRepository(environment)) - .findOne(config, profile, label, includeOrigin), propertySourceToConfigData); + .wrap(this.observationRegistry, new PassthruEnvironmentRepository(environment)).findOne(ctx), + propertySourceToConfigData); } catch (Exception e) { String msg = String.format("Could not construct context for config=%s profile=%s label=%s includeOrigin=%b", - config, profile, label, includeOrigin); + ctx.getName(), ctx.getProfiles(), ctx.getLabel(), ctx.getIncludeOrigin()); String completeMessage = NestedExceptionUtils.buildMessage(msg, NestedExceptionUtils.getMostSpecificCause(e)); throw new FailedToConstructEnvironmentException(completeMessage, e); @@ -167,7 +163,11 @@ public void onPropertySourceAdded(org.springframework.core.env.PropertySource } @Override - public Locations getLocations(String application, String profile, String label) { + public Locations getLocations(RequestContext ctx) { + String application = ctx.getName(); + String profile = ctx.getProfiles(); + String label = ctx.getLabel(); + String[] locations = this.searchLocations; if (this.searchLocations == null || this.searchLocations.length == 0) { locations = DEFAULT_LOCATIONS; @@ -220,18 +220,17 @@ public Locations getLocations(String application, String profile, String label) return new Locations(application, profile, label, this.version, output.toArray(new String[0])); } - private ConfigurableEnvironment getEnvironment(String application, String profile, String label) { + private ConfigurableEnvironment getEnvironment(RequestContext ctx) { ConfigurableEnvironment environment = new StandardEnvironment(); Map map = new HashMap<>(); - map.put("spring.profiles.active", profile); - String config = application; + map.put("spring.profiles.active", ctx.getProfiles()); + String config = ctx.getName(); if (!config.equals("application")) { config = "application," + config; } map.put("spring.config.name", config); // map.put("encrypt.failOnError=" + this.failOnError); - map.put("spring.config.location", - StringUtils.arrayToDelimitedString(getLocations(application, profile, label).getLocations(), ";")); + map.put("spring.config.location", StringUtils.arrayToDelimitedString(getLocations(ctx).getLocations(), ";")); // globally ignore config files that are not found map.put("spring.config.on-not-found", "IGNORE"); environment.getPropertySources().addFirst(new MapPropertySource("config-data-setup", map)); @@ -319,7 +318,9 @@ private boolean matchesLocation(String[] locations, String name, Environment res } String profile = result.getProfiles() == null ? null : StringUtils.arrayToCommaDelimitedString(result.getProfiles()); - for (String pattern : getLocations(result.getName(), profile, result.getLabel()).getLocations()) { + for (String pattern : getLocations( + new RequestContext.Builder().name(result.getName()).profiles(profile).label(result.getLabel()).build()) + .getLocations()) { if (!pattern.contains(":")) { pattern = "file:" + pattern; } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/ObservationEnvironmentRepositoryWrapper.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/ObservationEnvironmentRepositoryWrapper.java index 4f139d2fb9..534128a030 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/ObservationEnvironmentRepositoryWrapper.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/ObservationEnvironmentRepositoryWrapper.java @@ -19,6 +19,7 @@ import io.micrometer.observation.ObservationRegistry; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.support.RequestContext; /** * Wraps a {@link EnvironmentRepository} execution with observation. @@ -58,21 +59,11 @@ public static EnvironmentRepository wrap(ObservationRegistry observationRegistry } @Override - public Environment findOne(String application, String profile, String label) { + public Environment findOne(RequestContext ctx) { ObservationEnvironmentRepositoryContext context = new ObservationEnvironmentRepositoryContext( - this.delegate.getClass(), application, profile, label); + this.delegate.getClass(), ctx.getName(), ctx.getProfiles(), ctx.getLabel()); return DocumentedConfigObservation.ENVIRONMENT_REPOSITORY - .observation(null, CONVENTION, () -> context, this.registry) - .observe(() -> this.delegate.findOne(application, profile, label)); - } - - @Override - public Environment findOne(String application, String profile, String label, boolean includeOrigin) { - ObservationEnvironmentRepositoryContext context = new ObservationEnvironmentRepositoryContext( - this.delegate.getClass(), application, profile, label); - return DocumentedConfigObservation.ENVIRONMENT_REPOSITORY - .observation(null, CONVENTION, () -> context, this.registry) - .observe(() -> this.delegate.findOne(application, profile, label, includeOrigin)); + .observation(null, CONVENTION, () -> context, this.registry).observe(() -> this.delegate.findOne(ctx)); } /** diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepository.java index 00ff3bcf50..554df3e89d 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepository.java @@ -28,6 +28,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.environment.PropertyValueDescriptor; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.StandardEnvironment; @@ -63,18 +64,13 @@ public String getDefaultLabel() { } @Override - public Environment findOne(String application, String profile, String label) { - return findOne(application, profile, label, false); - } - - @Override - public Environment findOne(String application, String profile, String label, boolean includeOrigin) { - Environment result = new Environment(application, StringUtils.commaDelimitedListToStringArray(profile), label, - null, null); + public Environment findOne(RequestContext ctx) { + Environment result = new Environment(ctx.getName(), + StringUtils.commaDelimitedListToStringArray(ctx.getProfiles()), ctx.getLabel(), null, null); for (org.springframework.core.env.PropertySource source : this.environment.getPropertySources()) { String name = source.getName(); if (!this.standardSources.contains(name) && source instanceof MapPropertySource) { - result.add(new PropertySource(name, getMap(source, includeOrigin), source)); + result.add(new PropertySource(name, getMap(source, ctx.getIncludeOrigin()), source)); } } return result; diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/RedisEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/RedisEnvironmentRepository.java index 66b7aa6949..3d8a53fc73 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/RedisEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/RedisEnvironmentRepository.java @@ -24,6 +24,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.Ordered; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.util.StringUtils; @@ -47,10 +48,10 @@ public RedisEnvironmentRepository(StringRedisTemplate redis, RedisEnvironmentPro } @Override - public Environment findOne(String application, String profile, String label) { - String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); - Environment environment = new Environment(application, profiles, label, null, null); - final List keys = addKeys(application, Arrays.asList(profiles)); + public Environment findOne(RequestContext ctx) { + String[] profiles = StringUtils.commaDelimitedListToStringArray(ctx.getProfiles()); + Environment environment = new Environment(ctx.getName(), profiles, ctx.getLabel(), null, null); + final List keys = addKeys(ctx.getName(), Arrays.asList(profiles)); keys.forEach(it -> { Map m = redis.opsForHash().entries(it); environment.add(new PropertySource("redis:" + it, m)); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SearchPathCompositeEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SearchPathCompositeEnvironmentRepository.java index e7666398a9..47243acc4c 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SearchPathCompositeEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SearchPathCompositeEnvironmentRepository.java @@ -22,6 +22,8 @@ import io.micrometer.observation.ObservationRegistry; +import org.springframework.cloud.config.server.support.RequestContext; + /** * A {@link CompositeEnvironmentRepository} which implements {@link SearchPathLocator}. * @@ -43,16 +45,16 @@ public SearchPathCompositeEnvironmentRepository(List envi } @Override - public Locations getLocations(String application, String profile, String label) { + public Locations getLocations(RequestContext ctx) { List locations = new ArrayList<>(); for (EnvironmentRepository repo : this.environmentRepositories) { try { if (repo instanceof SearchPathLocator searchPathLocator) { - addForSearchPathLocators(application, profile, label, locations, searchPathLocator); + addForSearchPathLocators(ctx, locations, searchPathLocator); } else if (repo instanceof ObservationEnvironmentRepositoryWrapper wrapper && wrapper.getDelegate() instanceof SearchPathLocator searchPathLocator) { - addForSearchPathLocators(application, profile, label, locations, searchPathLocator); + addForSearchPathLocators(ctx, locations, searchPathLocator); } } catch (RepositoryException ex) { @@ -64,12 +66,13 @@ else if (repo instanceof ObservationEnvironmentRepositoryWrapper wrapper } } } - return new Locations(application, profile, label, null, locations.toArray(new String[locations.size()])); + return new Locations(ctx.getName(), ctx.getProfiles(), ctx.getLabel(), null, + locations.toArray(new String[locations.size()])); } - private void addForSearchPathLocators(String application, String profile, String label, List locations, + private void addForSearchPathLocators(RequestContext ctx, List locations, SearchPathLocator searchPathLocator) { - locations.addAll(Arrays.asList(searchPathLocator.getLocations(application, profile, label).getLocations())); + locations.addAll(Arrays.asList(searchPathLocator.getLocations(ctx).getLocations())); } } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SearchPathLocator.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SearchPathLocator.java index b24eb19d27..dbc879b7b0 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SearchPathLocator.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SearchPathLocator.java @@ -19,6 +19,8 @@ import java.util.Arrays; import java.util.Objects; +import org.springframework.cloud.config.server.support.RequestContext; + /** * Strategy for locating a search path for resource (e.g. in the file system or * classpath). @@ -28,7 +30,7 @@ */ public interface SearchPathLocator { - Locations getLocations(String application, String profile, String label); + Locations getLocations(RequestContext ctx); /** * Locations POJO. diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SvnKitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SvnKitEnvironmentRepository.java index 19a5c57919..5f8903282d 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SvnKitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/SvnKitEnvironmentRepository.java @@ -33,6 +33,7 @@ import org.tmatesoft.svn.core.wc2.SvnUpdate; import org.springframework.beans.factory.InitializingBean; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -70,10 +71,8 @@ public void setDefaultLabel(String defaultLabel) { } @Override - public synchronized Locations getLocations(String application, String profile, String label) { - if (label == null) { - label = this.defaultLabel; - } + public synchronized Locations getLocations(RequestContext ctx) { + String label = ctx.getLabel() == null ? this.defaultLabel : ctx.getLabel(); SvnOperationFactory svnOperationFactory = new SvnOperationFactory(); if (hasText(getUsername())) { svnOperationFactory.setAuthenticationManager( @@ -87,7 +86,8 @@ public synchronized Locations getLocations(String application, String profile, S else { version = checkout(svnOperationFactory); } - return new Locations(application, profile, label, version, getPaths(application, profile, label)); + return new Locations(ctx.getName(), ctx.getProfiles(), label, version, + getPaths(ctx.getName(), ctx.getProfiles(), label)); } catch (SVNException e) { throw new IllegalStateException("Cannot checkout repository", e); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/GenericResourceRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/GenericResourceRepository.java index 80797b8807..82eed883fc 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/GenericResourceRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/GenericResourceRepository.java @@ -27,6 +27,7 @@ import org.springframework.cloud.config.server.config.ConfigServerProperties; import org.springframework.cloud.config.server.environment.SearchPathLocator; import org.springframework.cloud.config.server.support.PathUtils; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; @@ -61,10 +62,10 @@ public void setResourceLoader(ResourceLoader resourceLoader) { } @Override - public synchronized Resource findOne(String application, String profile, String label, String path) { + public synchronized Resource findOne(RequestContext ctx) { - if (StringUtils.hasText(path)) { - String[] locations = this.service.getLocations(application, profile, label).getLocations(); + if (StringUtils.hasText(ctx.getPath())) { + String[] locations = this.service.getLocations(ctx).getLocations(); if (!ObjectUtils.isEmpty(properties) && properties.isReverseLocationOrder()) { Collections.reverse(Arrays.asList(locations)); } @@ -77,7 +78,7 @@ public synchronized Resource findOne(String application, String profile, String try { for (Resource location : locationResources) { - for (String local : getProfilePaths(profile, path)) { + for (String local : getProfilePaths(ctx.getProfiles(), ctx.getPath())) { if (!PathUtils.isInvalidPath(local) && !PathUtils.isInvalidEncodedPath(local)) { Resource file = location.createRelative(local); if (file.exists() && file.isReadable() @@ -89,10 +90,10 @@ public synchronized Resource findOne(String application, String profile, String } } catch (IOException e) { - throw new NoSuchResourceException("Error : " + path + ". (" + e.getMessage() + ")"); + throw new NoSuchResourceException("Error : " + ctx.getPath() + ". (" + e.getMessage() + ")"); } } - throw new NoSuchResourceException("Not found: " + path); + throw new NoSuchResourceException("Not found: " + ctx.getPath()); } private Collection getProfilePaths(String profiles, String path) { diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceController.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceController.java index ca835a4de4..6a5d26f418 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceController.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceController.java @@ -28,6 +28,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.encryption.ResourceEncryptor; import org.springframework.cloud.config.server.environment.EnvironmentRepository; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.util.StreamUtils; @@ -100,15 +101,20 @@ public void setPlainTextEncryptEnabled(boolean plainTextEncryptEnabled) { public String retrieve(@PathVariable String name, @PathVariable String profile, @PathVariable String label, ServletWebRequest request, @RequestParam(defaultValue = "true") boolean resolvePlaceholders) throws IOException { + RequestContext ctx = new RequestContext.Builder().name(Environment.normalize(name)).profiles(profile) + .label(Environment.normalize(label)).path(getFilePath(request, name, profile, label)) + .resolvePlaceholders(resolvePlaceholders).build(); String path = getFilePath(request, name, profile, label); - return retrieve(request, name, profile, label, path, resolvePlaceholders); + return retrieve(request, ctx); } @GetMapping(value = "/{name}/{profile}/{path:.*}", params = "useDefaultLabel") public String retrieveDefault(@PathVariable String name, @PathVariable String profile, @PathVariable String path, ServletWebRequest request, @RequestParam(defaultValue = "true") boolean resolvePlaceholders) throws IOException { - return retrieve(request, name, profile, null, path, resolvePlaceholders); + RequestContext ctx = new RequestContext.Builder().name(Environment.normalize(name)).profiles(profile).path(path) + .resolvePlaceholders(resolvePlaceholders).build(); + return retrieve(request, ctx); } private String getFilePath(ServletWebRequest request, String name, String profile, String label) { @@ -129,11 +135,8 @@ private String getFilePath(ServletWebRequest request, String name, String profil * be threadsafe (JGit for example). Calling this method could result in an update to * the files on disk. */ - synchronized String retrieve(ServletWebRequest request, String name, String profile, String label, String path, - boolean resolvePlaceholders) throws IOException { - name = Environment.normalize(name); - label = Environment.normalize(label); - Resource resource = this.resourceRepository.findOne(name, profile, label, path); + synchronized String retrieve(ServletWebRequest request, RequestContext ctx) throws IOException { + Resource resource = this.resourceRepository.findOne(ctx); if (checkNotModified(request, resource)) { // Content was not modified. Just return. return null; @@ -145,8 +148,8 @@ synchronized String retrieve(ServletWebRequest request, String name, String prof if (ext != null) { ext = ext.toLowerCase(); } - Environment environment = this.environmentRepository.findOne(name, profile, label, false); - if (resolvePlaceholders) { + Environment environment = this.environmentRepository.findOne(ctx); + if (ctx.getResolvePlaceholders()) { text = resolvePlaceholders(prepareEnvironment(environment), text); } if (ext != null && encryptEnabled && plainTextEncryptEnabled) { @@ -167,41 +170,45 @@ synchronized String retrieve(ServletWebRequest request, String name, String prof */ String retrieve(String name, String profile, String label, String path, boolean resolvePlaceholders) throws IOException { - return retrieve(null, name, profile, label, path, resolvePlaceholders); + RequestContext ctx = new RequestContext.Builder().name(Environment.normalize(name)).profiles(profile) + .label(Environment.normalize(label)).path(path).resolvePlaceholders(resolvePlaceholders).build(); + return retrieve(null, ctx); } @GetMapping(value = "/{name}/{profile}/{label}/**", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public byte[] binary(@PathVariable String name, @PathVariable String profile, @PathVariable String label, ServletWebRequest request) throws IOException { - String path = getFilePath(request, name, profile, label); - return binary(request, name, profile, label, path); + RequestContext ctx = new RequestContext.Builder().name(Environment.normalize(name)).profiles(profile) + .label(Environment.normalize(label)).path(getFilePath(request, name, profile, label)).build(); + return binary(request, ctx); } @GetMapping(value = "/{name}/{profile}/{path:.*}", params = "useDefaultLabel", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public byte[] binaryDefault(@PathVariable String name, @PathVariable String profile, @PathVariable String path, ServletWebRequest request) throws IOException { - return binary(request, name, profile, null, path); + RequestContext ctx = new RequestContext.Builder().name(Environment.normalize(name)).profiles(profile).path(path) + .build(); + return binary(request, ctx); } /* * Used only for unit tests. */ byte[] binary(String name, String profile, String label, String path) throws IOException { - return binary(null, name, profile, label, path); + RequestContext ctx = new RequestContext.Builder().name(Environment.normalize(name)).profiles(profile) + .label(Environment.normalize(label)).path(path).build(); + return binary(null, ctx); } - private synchronized byte[] binary(ServletWebRequest request, String name, String profile, String label, - String path) throws IOException { - name = Environment.normalize(name); - label = Environment.normalize(label); - Resource resource = this.resourceRepository.findOne(name, profile, label, path); + private synchronized byte[] binary(ServletWebRequest request, RequestContext ctx) throws IOException { + Resource resource = this.resourceRepository.findOne(ctx); if (checkNotModified(request, resource)) { // Content was not modified. Just return. return null; } // TODO: is this line needed for side effects? - prepareEnvironment(this.environmentRepository.findOne(name, profile, label)); + prepareEnvironment(this.environmentRepository.findOne(ctx)); try (InputStream is = resource.getInputStream()) { return StreamUtils.copyToByteArray(is); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceRepository.java index 8f0d02aa1b..f3f462eea5 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceRepository.java @@ -16,6 +16,7 @@ package org.springframework.cloud.config.server.resource; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.io.Resource; /** @@ -24,6 +25,6 @@ */ public interface ResourceRepository { - Resource findOne(String name, String profile, String label, String path); + Resource findOne(RequestContext ctx); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/RequestContext.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/RequestContext.java new file mode 100644 index 0000000000..09bf723db4 --- /dev/null +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/RequestContext.java @@ -0,0 +1,151 @@ +/* + * Copyright 2013-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.config.server.support; + +import java.util.Objects; + +/** + * @author Yuto Yamada + */ +public final class RequestContext { + + private final String name; + + private final String profiles; + + private final String label; + + private final String path; + + private final boolean resolvePlaceholders; + + /** + * includeOrigin does not come from HTTP request but specific to endpoint. + */ + private final boolean includeOrigin; + + private RequestContext(Builder builder) { + this.name = builder.name; + this.profiles = builder.profiles; + this.label = builder.label; + this.path = builder.path; + this.resolvePlaceholders = builder.resolvePlaceholders; + this.includeOrigin = builder.includeOrigin; + } + + public String getName() { + return name; + } + + public String getProfiles() { + return profiles; + } + + public String getLabel() { + return label; + } + + public String getPath() { + return path; + } + + public boolean getResolvePlaceholders() { + return resolvePlaceholders; + } + + public boolean getIncludeOrigin() { + return includeOrigin; + } + + public Builder toBuilder() { + return new Builder().name(getName()).profiles(getProfiles()).label(getLabel()).path(getPath()) + .resolvePlaceholders(getResolvePlaceholders()).includeOrigin(getIncludeOrigin()); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RequestContext ctx = (RequestContext) o; + return (getName() == null ? ctx.getName() == null : getName().equals(ctx.getName())) + && (getProfiles() == null ? ctx.getProfiles() == null : getProfiles().equals(ctx.getProfiles())) + && (getLabel() == null ? ctx.getLabel() == null : getLabel().equals(ctx.getLabel())) + && (getPath() == null ? ctx.getPath() == null : getPath().equals(ctx.getPath())) + && getResolvePlaceholders() == ctx.getResolvePlaceholders() + && getIncludeOrigin() == ctx.getIncludeOrigin(); + } + + @Override + public int hashCode() { + return 31 * Objects.hash(getName(), getProfiles(), getLabel(), getResolvePlaceholders(), getIncludeOrigin()); + } + + public static class Builder { + + private String name = null; + + private String profiles = null; + + private String label = null; + + private String path = null; + + private boolean resolvePlaceholders = false; + + private boolean includeOrigin = false; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder profiles(String profiles) { + this.profiles = profiles; + return this; + } + + public Builder label(String label) { + this.label = label; + return this; + } + + public Builder path(String path) { + this.path = path; + return this; + } + + public Builder resolvePlaceholders(boolean resolvePlaceholders) { + this.resolvePlaceholders = resolvePlaceholders; + return this; + } + + public Builder includeOrigin(boolean includeOrigin) { + this.includeOrigin = includeOrigin; + return this; + } + + public RequestContext build() { + return new RequestContext(this); + } + + } + +} diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java index d18059461f..c8a2ca3b6f 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java @@ -34,6 +34,7 @@ import org.springframework.cloud.config.server.ConfigClientOffIntegrationTests.TestConfiguration; import org.springframework.cloud.config.server.environment.EnvironmentRepository; import org.springframework.cloud.config.server.resource.ResourceRepository; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.context.ApplicationContext; @@ -44,8 +45,7 @@ import org.springframework.test.context.ActiveProfiles; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -87,16 +87,14 @@ protected static class TestConfiguration { @Bean public EnvironmentRepository environmentRepository() { EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class); - given(repository.findOne(anyString(), anyString(), anyString(), anyBoolean())) - .willReturn(new Environment("", "")); + given(repository.findOne(any(RequestContext.class))).willReturn(new Environment("", "")); return repository; } @Bean public ResourceRepository resourceRepository() { ResourceRepository repository = Mockito.mock(ResourceRepository.class); - given(repository.findOne(anyString(), anyString(), anyString(), anyString())) - .willReturn(new ByteArrayResource("".getBytes())); + given(repository.findOne(any(RequestContext.class))).willReturn(new ByteArrayResource("".getBytes())); return repository; } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOnIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOnIntegrationTests.java index 633b339129..f6e8210df9 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOnIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOnIntegrationTests.java @@ -37,6 +37,7 @@ import org.springframework.cloud.config.server.ConfigClientOnIntegrationTests.TestConfiguration; import org.springframework.cloud.config.server.environment.EnvironmentRepository; import org.springframework.cloud.config.server.resource.ResourceRepository; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -46,8 +47,7 @@ import org.springframework.test.context.ActiveProfiles; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @SpringBootTest(classes = TestConfiguration.class, @@ -101,16 +101,14 @@ protected static class TestConfiguration { @Bean public EnvironmentRepository environmentRepository() { EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class); - given(repository.findOne(anyString(), anyString(), anyString(), anyBoolean())) - .willReturn(new Environment("", "")); + given(repository.findOne(any(RequestContext.class))).willReturn(new Environment("", "")); return repository; } @Bean public ResourceRepository resourceRepository() { ResourceRepository repository = Mockito.mock(ResourceRepository.class); - given(repository.findOne(anyString(), anyString(), anyString(), anyString())) - .willReturn(new ByteArrayResource("".getBytes())); + given(repository.findOne(any(RequestContext.class))).willReturn(new ByteArrayResource("".getBytes())); return repository; } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java index b5ca28ba1e..6da63a6a9b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java @@ -34,6 +34,7 @@ import org.springframework.cloud.config.server.RefreshableConfigServerIntegrationTests.TestConfiguration; import org.springframework.cloud.config.server.environment.EnvironmentRepository; import org.springframework.cloud.config.server.resource.ResourceRepository; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -48,7 +49,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.BDDMockito.given; import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.assertOriginTrackedValue; import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.getV2AcceptEntity; @@ -124,16 +124,14 @@ protected static class TestConfiguration { public EnvironmentRepository environmentRepository() { EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class); Environment environment = new Environment("", ""); - given(repository.findOne(isA(String.class), isA(String.class), nullable(String.class), isA(Boolean.class))) - .willReturn(environment); + given(repository.findOne(isA(RequestContext.class))).willReturn(environment); return repository; } @Bean public ResourceRepository resourceRepository() { ResourceRepository repository = Mockito.mock(ResourceRepository.class); - given(repository.findOne(isA(String.class), isA(String.class), nullable(String.class), isA(String.class))) - .willReturn(new ByteArrayResource("".getBytes())); + given(repository.findOne(isA(RequestContext.class))).willReturn(new ByteArrayResource("".getBytes())); return repository; } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java index 43ec711423..bb1b0c3731 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java @@ -22,17 +22,16 @@ import org.junit.jupiter.api.Test; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.Mockito; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.config.ConfigServerHealthIndicator.Repository; import org.springframework.cloud.config.server.environment.EnvironmentRepository; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; @@ -58,23 +57,20 @@ public void init() { @Test public void defaultStatusWorks() { - when(this.repository.findOne(anyString(), anyString(), Mockito.isNull(), anyBoolean())) - .thenReturn(this.environment); + when(this.repository.findOne(any(RequestContext.class))).thenReturn(this.environment); assertThat(this.indicator.health().getStatus()).as("wrong default status").isEqualTo(Status.UP); } @Test public void exceptionStatusIsDownByDefault() { - when(this.repository.findOne(anyString(), anyString(), Mockito.isNull(), anyBoolean())) - .thenThrow(new RuntimeException()); + when(this.repository.findOne(any(RequestContext.class))).thenThrow(new RuntimeException()); assertThat(this.indicator.health().getStatus()).as("wrong exception status").isEqualTo(Status.DOWN); } @Test public void exceptionDownStatusMayBeCustomized() { ReflectionTestUtils.setField(this.indicator, "downHealthStatus", "CUSTOM"); - when(this.repository.findOne(anyString(), anyString(), Mockito.isNull(), anyBoolean())) - .thenThrow(new RuntimeException()); + when(this.repository.findOne(any(RequestContext.class))).thenThrow(new RuntimeException()); assertThat(this.indicator.health().getStatus()).as("wrong exception status").isEqualTo(new Status(("CUSTOM"))); } @@ -85,7 +81,9 @@ public void customLabelWorks() { repo.setProfiles("myprofile"); repo.setLabel("mylabel"); this.indicator.setRepositories(Collections.singletonMap("myname", repo)); - when(this.repository.findOne("myname", "myprofile", "mylabel", false)).thenReturn(this.environment); + when(this.repository + .findOne(new RequestContext.Builder().name("myname").profiles("myprofile").label("mylabel").build())) + .thenReturn(this.environment); assertThat(this.indicator.health().getStatus()).as("wrong default status").isEqualTo(Status.UP); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomCompositeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomCompositeEnvironmentRepositoryTests.java index ef416e23cc..2d2f9048ef 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomCompositeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomCompositeEnvironmentRepositoryTests.java @@ -35,6 +35,7 @@ import org.springframework.cloud.config.server.environment.EnvironmentRepository; import org.springframework.cloud.config.server.environment.EnvironmentRepositoryFactory; import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -196,12 +197,7 @@ static class CustomEnvironmentRepository implements EnvironmentRepository, Order } @Override - public Environment findOne(String application, String profile, String label) { - return findOne(application, profile, label, false); - } - - @Override - public Environment findOne(String application, String profile, String label, boolean includeOrigin) { + public Environment findOne(RequestContext ctx) { Environment e = new Environment("test", new String[0], "label", "version", "state"); PropertySource p = new PropertySource(this.properties.getPropertySourceName(), new HashMap<>()); e.add(p); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomEnvironmentRepositoryTests.java index faba923424..65dd351b73 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomEnvironmentRepositoryTests.java @@ -28,6 +28,7 @@ import org.springframework.cloud.config.server.EnableConfigServer; import org.springframework.cloud.config.server.config.CustomEnvironmentRepositoryTests.TestApplication; import org.springframework.cloud.config.server.environment.EnvironmentRepository; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; @@ -67,14 +68,8 @@ public static void main(String[] args) throws Exception { @Bean public EnvironmentRepository environmentRepository() { return new EnvironmentRepository() { - - @Override - public Environment findOne(String application, String profile, String label) { - return findOne(application, profile, label, false); - } - @Override - public Environment findOne(String application, String profile, String label, boolean includeOrigin) { + public Environment findOne(RequestContext ctx) { return new Environment("test", new String[0], "label", "version", "state"); } }; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java index a10df257dc..e6af65bd2b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java @@ -40,6 +40,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.config.ConfigServerProperties; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.util.StringUtils; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; @@ -101,7 +102,8 @@ public void testFindOneWithPaginatedAwsSsmClientResponse() { setupAwsSsmClientMocks(expected, false, true); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java index 2648f838f1..6d7e641664 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java @@ -45,6 +45,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.config.ConfigServerProperties; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.core.Ordered; import org.springframework.util.StringUtils; @@ -108,7 +109,8 @@ public void testFindOneWithNullApplicationAndNullProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -134,7 +136,8 @@ public void testFindOneWithNullApplicationAndDefaultProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -157,7 +160,8 @@ public void testFindOneWithNullApplicationAndNonExistentProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -183,7 +187,8 @@ public void testFindOneWithNullApplicationAndExistentProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -209,7 +214,8 @@ public void testFindOneWithDefaultApplicationAndNullProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -234,7 +240,8 @@ public void testFindOneWithDefaultApplicationAndDefaultProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -256,7 +263,8 @@ public void testFindOneWithDefaultApplicationAndNonExistentProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -281,7 +289,8 @@ public void testFindOneWithDefaultApplicationAndExistentProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -307,7 +316,8 @@ public void testFindOneWithNonExistentApplicationAndNullProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -332,7 +342,8 @@ public void testFindOneWithNonExistentApplicationAndDefaultProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -354,7 +365,8 @@ public void testFindOneWithNonExistentApplicationAndNonExistentProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -379,7 +391,8 @@ public void testFindOneWithNonExistentApplicationAndExistentProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -415,7 +428,8 @@ public void testFindOneWithExistentApplicationAndNullProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -450,7 +464,8 @@ public void testFindOneWithExistentApplicationAndDefaultProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -476,7 +491,8 @@ public void testFindOneWithExistentApplicationAndNonExistentProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -511,7 +527,8 @@ public void testFindOneWithExistentApplicationAndExistentProfile() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -553,7 +570,8 @@ public void testFindOneWithExistentApplicationAndMultipleExistentProfiles() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -582,7 +600,8 @@ public void testFindOneWithExistentApplicationAndMultipleOrderedExistentProfiles putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -620,7 +639,8 @@ public void testFindOneWithOverrides() { putParameters(expected); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -645,7 +665,8 @@ public void testFindOneWithSlashesInTheParameterKeyPath() { putParameters(expected, true); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); @@ -661,7 +682,8 @@ public void testFindOneWithNoParametersInThePaths() { Environment expected = new Environment(application, profiles, null, null, null); // Act - Environment result = repository.findOne(application, profile, null); + Environment result = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); // Assert assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java index d34e53c552..2df1298215 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java @@ -44,6 +44,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.config.ConfigServerProperties; +import org.springframework.cloud.config.server.support.RequestContext; import static org.assertj.core.api.Assertions.assertThat; import static org.testcontainers.containers.localstack.LocalStackContainer.Service.S3; @@ -125,7 +126,7 @@ public void cleanUp() { @Test public void failToFindNonexistentObject() { - Environment env = envRepo.findOne("foo", "bar", null); + Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertThat(env.getPropertySources()).isEmpty(); } @@ -143,7 +144,7 @@ public void findPropertiesObject() throws UnsupportedEncodingException { // Pulling content from a .properties file forces a boolean into a String expectedProperties.put("cloudfoundry.enabled", "true"); - final Environment env = envRepo.findOne("foo", "bar", null); + final Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); } @@ -152,7 +153,7 @@ public void findPropertiesObject() throws UnsupportedEncodingException { public void findJsonObject() throws UnsupportedEncodingException { String versionId = putFiles("foo-bar.json", jsonContent); - final Environment env = envRepo.findOne("foo", "bar", null); + final Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); } @@ -161,7 +162,7 @@ public void findJsonObject() throws UnsupportedEncodingException { public void findYamlObject() throws UnsupportedEncodingException { String versionId = putFiles("foo-bar.yaml", yamlContent); - final Environment env = envRepo.findOne("foo", "bar", null); + final Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); } @@ -170,7 +171,7 @@ public void findYamlObject() throws UnsupportedEncodingException { public void findYmlObject() throws UnsupportedEncodingException { String versionId = putFiles("foo-bar.yml", yamlContent); - final Environment env = envRepo.findOne("foo", "bar", null); + final Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); } @@ -179,7 +180,7 @@ public void findYmlObject() throws UnsupportedEncodingException { public void findWithDefaultProfile() throws UnsupportedEncodingException { String versionId = putFiles("foo.yml", yamlContent); - final Environment env = envRepo.findOne("foo", null, null); + final Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").build()); assertExpectedEnvironment(env, "foo", null, versionId, 1, "default"); } @@ -188,7 +189,7 @@ public void findWithDefaultProfile() throws UnsupportedEncodingException { public void findWithDefaultProfileUsingSuffix() throws UnsupportedEncodingException { String versionId = putFiles("foo-default.yml", yamlContent); - final Environment env = envRepo.findOne("foo", null, null); + final Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").build()); assertExpectedEnvironment(env, "foo", null, versionId, 1, "default"); } @@ -198,7 +199,8 @@ public void findWithMultipleProfilesAllFound() throws UnsupportedEncodingExcepti putFiles("foo-profile1.yml", yamlContent); String versionId = putFiles("foo-profile2.yml", jsonContent); - final Environment env = envRepo.findOne("foo", "profile1,profile2", null); + final Environment env = envRepo + .findOne(new RequestContext.Builder().name("foo").profiles("profile1,profile2").build()); assertExpectedEnvironment(env, "foo", null, versionId, 2, "profile1", "profile2"); } @@ -207,7 +209,8 @@ public void findWithMultipleProfilesAllFound() throws UnsupportedEncodingExcepti public void findWithMultipleProfilesOneFound() throws UnsupportedEncodingException { String versionId = putFiles("foo-profile2.yml", jsonContent); - final Environment env = envRepo.findOne("foo", "profile1,profile2", null); + final Environment env = envRepo + .findOne(new RequestContext.Builder().name("foo").profiles("profile1,profile2").build()); assertExpectedEnvironment(env, "foo", null, versionId, 1, "profile1", "profile2"); } @@ -217,7 +220,7 @@ public void findWithOneProfileDefaultOneFound() throws UnsupportedEncodingExcept putFiles("foo-profile1.yml", jsonContent); String versionId = putFiles("foo.yml", yamlContent); - final Environment env = envRepo.findOne("foo", "profile1", null); + final Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").profiles("profile1").build()); assertExpectedEnvironment(env, "foo", null, versionId, 2, "profile1"); } @@ -227,7 +230,7 @@ public void findWithNoProfileAndNoServerDefaultOneFound() throws UnsupportedEnco server.setDefaultProfile(null); String versionId = putFiles("foo.yml", yamlContent); - final Environment env = envRepo.findOne("foo", null, null); + final Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").build()); assertExpectedEnvironment(env, "foo", null, versionId, 1); @@ -237,7 +240,8 @@ public void findWithNoProfileAndNoServerDefaultOneFound() throws UnsupportedEnco public void findWithLabel() throws UnsupportedEncodingException { String versionId = putFiles("label1/foo-bar.yml", yamlContent); - final Environment env = envRepo.findOne("foo", "bar", "label1"); + final Environment env = envRepo + .findOne(new RequestContext.Builder().name("foo").profiles("bar").label("label1").build()); assertExpectedEnvironment(env, "foo", "label1", versionId, 1, "bar"); } @@ -246,7 +250,7 @@ public void findWithLabel() throws UnsupportedEncodingException { public void findWithVersion() throws UnsupportedEncodingException { String versionId = putFiles("foo-bar.yml", yamlContent); - final Environment env = envRepo.findOne("foo", "bar", null); + final Environment env = envRepo.findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); } @@ -256,7 +260,8 @@ public void findWithMultipleApplicationAllFound() throws UnsupportedEncodingExce putFiles("foo-profile1.yml", jsonContent); String versionId = putFiles("bar-profile1.yml", jsonContent); - final Environment env = envRepo.findOne("foo,bar", "profile1", null); + final Environment env = envRepo + .findOne(new RequestContext.Builder().name("foo,bar").profiles("profile1").build()); assertExpectedEnvironment(env, "foo,bar", null, versionId, 2, "profile1"); @@ -280,25 +285,33 @@ public void getLocationsTest() { properties.setBucket("test"); AwsS3EnvironmentRepository repository = factory.build(properties); - assertThat(repository.getLocations("app", "default", "main")).isEqualTo( - new SearchPathLocator.Locations("app", "default", "main", null, new String[] { "s3://test/main" })); + assertThat(repository + .getLocations(new RequestContext.Builder().name("app").profiles("default").label("main").build())) + .isEqualTo(new SearchPathLocator.Locations("app", "default", "main", null, + new String[] { "s3://test/main" })); - assertThat(repository.getLocations("app", "default", null)).isEqualTo( - new SearchPathLocator.Locations("app", "default", null, null, new String[] { "s3://test/" })); + assertThat(repository.getLocations(new RequestContext.Builder().name("app").profiles("default").build())) + .isEqualTo( + new SearchPathLocator.Locations("app", "default", null, null, new String[] { "s3://test/" })); - assertThat(repository.getLocations("app", "default", "")) - .isEqualTo(new SearchPathLocator.Locations("app", "default", "", null, new String[] { "s3://test/" })); + assertThat( + repository.getLocations(new RequestContext.Builder().name("app").profiles("default").label("").build())) + .isEqualTo(new SearchPathLocator.Locations("app", "default", "", null, + new String[] { "s3://test/" })); ConfigServerProperties configServerProperties = new ConfigServerProperties(); configServerProperties.setDefaultLabel("defaultlabel"); factory = new AwsS3EnvironmentRepositoryFactory(configServerProperties); repository = factory.build(properties); - assertThat(repository.getLocations("app", "default", null)).isEqualTo(new SearchPathLocator.Locations("app", - "default", "defaultlabel", null, new String[] { "s3://test/defaultlabel" })); + assertThat(repository.getLocations(new RequestContext.Builder().name("app").profiles("default").build())) + .isEqualTo(new SearchPathLocator.Locations("app", "default", "defaultlabel", null, + new String[] { "s3://test/defaultlabel" })); - assertThat(repository.getLocations("app", "default", "")).isEqualTo(new SearchPathLocator.Locations("app", - "default", "defaultlabel", null, new String[] { "s3://test/defaultlabel" })); + assertThat( + repository.getLocations(new RequestContext.Builder().name("app").profiles("default").label("").build())) + .isEqualTo(new SearchPathLocator.Locations("app", "default", "defaultlabel", null, + new String[] { "s3://test/defaultlabel" })); } private String putFiles(String fileName, String propertyContent) { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java index 6164efa596..173529118f 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java @@ -48,6 +48,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.config.ConfigServerProperties; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -279,7 +280,8 @@ public void testFindOneWithNullApplicationAndNonExistingProfileAndNullLabelWhenD putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -305,7 +307,8 @@ public void testFindOneWithNullApplicationAndDefaultProfileAndNullLabelWhenDefau putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -336,7 +339,8 @@ public void testFindOneWithNullApplicationAndExistingProfileAndNullLabelWhenDefa putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -362,7 +366,8 @@ public void testFindOneWithDefaultApplicationAndNullProfileAndNullLabelWhenDefau putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -387,7 +392,8 @@ public void testFindOneWithDefaultApplicationAndDefaultProfileAndNullLabelWhenDe putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -412,7 +418,8 @@ public void testFindOneWithDefaultApplicationAndNonExistingProfileAndNullLabelWh putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -442,7 +449,8 @@ public void testFindOneWithDefaultApplicationAndExistingProfileAndNullLabelWhenD putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -468,7 +476,8 @@ public void testFindOneWithNonExistingApplicationAndNullProfileAndNullLabelWhenD putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -493,7 +502,8 @@ public void testFindOneWithNonExistingApplicationAndDefaultProfileAndNullLabelWh putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -518,7 +528,8 @@ public void testFindOneWithNonExistingApplicationAndNonExistingProfileAndNullLab putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -548,7 +559,8 @@ public void testFindOneWithNonExistingApplicationAndExistingProfileAndNullLabelW putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -581,7 +593,8 @@ public void testFindOneWithExistingApplicationAndNullProfileAndNullLabelWhenDefa putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -613,7 +626,8 @@ public void testFindOneWithExistingApplicationAndDefaultProfileAndNullLabelWhenD putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -645,7 +659,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNullLabelW putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -669,7 +684,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNoDefaultP putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -697,7 +713,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNoDefaultP putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -736,7 +753,8 @@ public void testFindOneWithExistingApplicationAndExistingProfileAndNullLabelWhen putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -768,7 +786,8 @@ public void testFindOneWithExistingApplicationAndExistingProfileAndNoDefaultProf putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -815,7 +834,8 @@ public void testFindOneWithExistingApplicationAndMultipleExistingProfileAndNullL putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -854,7 +874,8 @@ public void testFindOneWithExistingApplicationAndMultipleExistingProfileAndNoDef putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -872,7 +893,8 @@ public void testFindOneWithNullApplicationAndNullProfileAndNonExistingLabelWhenD putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -889,7 +911,8 @@ public void testFindOneWithNullApplicationAndNonExistingProfileAndNonExistingLab putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -906,7 +929,8 @@ public void testFindOneWithNullApplicationAndDefaultProfileAndNonExistingLabelWh putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -923,7 +947,8 @@ public void testFindOneWithNullApplicationAndExistingProfileAndNonExistingLabelW putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -940,7 +965,8 @@ public void testFindOneWithDefaultApplicationAndNullProfileAndNonExistingLabelWh putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -956,7 +982,8 @@ public void testFindOneWithDefaultApplicationAndDefaultProfileAndNonExistingLabe putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -972,7 +999,8 @@ public void testFindOneWithDefaultApplicationAndNonExistingProfileAndNonExisting putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -988,7 +1016,8 @@ public void testFindOneWithDefaultApplicationAndExistingProfileAndNonExistingLab putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1005,7 +1034,8 @@ public void testFindOneWithNonExistingApplicationAndNullProfileAndNonExistingLab putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1021,7 +1051,8 @@ public void testFindOneWithNonExistingApplicationAndDefaultProfileAndNonExisting putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1037,7 +1068,8 @@ public void testFindOneWithNonExistingApplicationAndNonExistingProfileAndNonExis putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1053,7 +1085,8 @@ public void testFindOneWithNonExistingApplicationAndExistingProfileAndNonExistin putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1070,7 +1103,8 @@ public void testFindOneWithExistingApplicationAndNullProfileAndNonExistingLabelW putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1086,7 +1120,8 @@ public void testFindOneWithExistingApplicationAndDefaultProfileAndNonExistingLab putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1102,7 +1137,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNonExistin putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1118,7 +1154,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNoDefaultP putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1134,7 +1171,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNoDefaultP putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1150,7 +1188,8 @@ public void testFindOneWithExistingApplicationAndExistingProfileAndNonExistingLa putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1166,7 +1205,8 @@ public void testFindOneWithExistingApplicationAndExistingProfileAndNoDefaultProf putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1182,7 +1222,8 @@ public void testFindOneWithExistingApplicationAndMultipleExistingProfileAndNonEx putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1198,7 +1239,8 @@ public void testFindOneWithExistingApplicationAndMultipleExistingProfileAndNoDef putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1225,7 +1267,8 @@ public void testFindOneWithNullApplicationAndNullProfileAndExistingLabelWhenDefa putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1251,7 +1294,8 @@ public void testFindOneWithNullApplicationAndNonExistingProfileAndExistingLabelW putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1277,7 +1321,8 @@ public void testFindOneWithNullApplicationAndDefaultProfileAndExistingLabelWhenD putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1308,7 +1353,8 @@ public void testFindOneWithNullApplicationAndExistingProfileAndExistingLabelWhen putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1334,7 +1380,8 @@ public void testFindOneWithDefaultApplicationAndNullProfileAndExistingLabelWhenD putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1359,7 +1406,8 @@ public void testFindOneWithDefaultApplicationAndDefaultProfileAndExistingLabelWh putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1384,7 +1432,8 @@ public void testFindOneWithDefaultApplicationAndNonExistingProfileAndExistingLab putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1414,7 +1463,8 @@ public void testFindOneWithDefaultApplicationAndExistingProfileAndExistingLabelW putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1440,7 +1490,8 @@ public void testFindOneWithNonExistingApplicationAndNullProfileAndExistingLabelW putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1465,7 +1516,8 @@ public void testFindOneWithNonExistingApplicationAndDefaultProfileAndExistingLab putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1490,7 +1542,8 @@ public void testFindOneWithNonExistingApplicationAndNonExistingProfileAndExistin putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1520,7 +1573,8 @@ public void testFindOneWithNonExistingApplicationAndExistingProfileAndExistingLa putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1554,7 +1608,8 @@ public void testFindOneWithExistingApplicationAndNullProfileAndExistingLabelWhen putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1587,7 +1642,8 @@ public void testFindOneWithExistingApplicationAndDefaultProfileAndExistingLabelW putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1620,7 +1676,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndExistingLa putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1644,7 +1701,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNoDefaultP putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1672,7 +1730,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNoDefaultP putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1712,7 +1771,8 @@ public void testFindOneWithExistingApplicationAndExistingProfileAndExistingLabel putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1744,7 +1804,8 @@ public void testFindOneWithExistingApplicationAndExistingProfileAndNoDefaultProf putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1792,7 +1853,8 @@ public void testFindOneWithExistingApplicationAndMultipleExistingProfileAndExist putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1831,7 +1893,8 @@ public void testFindOneWithExistingApplicationAndMultipleExistingProfileAndNoDef putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, label); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1871,7 +1934,8 @@ public void testFindOneWithExistingApplicationAndExistingProfileAndExistingLabel putSecrets(expectedEnv); - Environment resultEnv = ignoreLabelRepository.findOne(application, profile, label); + Environment resultEnv = ignoreLabelRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(label).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1897,7 +1961,8 @@ public void testFindOneWithNullApplicationAndNullProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -1924,7 +1989,8 @@ public void testFindOneWithNullApplicationAndNullProfileAndNullLabelWhenDefaultL putSecrets(expectedEnv); - Environment resultEnv = labeledRepository.findOne(application, profile, defaultLabel); + Environment resultEnv = labeledRepository + .findOne(new RequestContext.Builder().name(application).profiles(profile).label(defaultLabel).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv); } @@ -1949,7 +2015,8 @@ public void testFindOneWithNullApplicationAndNonExistingProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -1974,7 +2041,8 @@ public void testFindOneWithNullApplicationAndDefaultProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2004,7 +2072,8 @@ public void testFindOneWithNullApplicationAndExistingProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2029,7 +2098,8 @@ public void testFindOneWithDefaultApplicationAndNullProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2053,7 +2123,8 @@ public void testFindOneWithDefaultApplicationAndDefaultProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2077,7 +2148,8 @@ public void testFindOneWithDefaultApplicationAndNonExistingProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2106,7 +2178,8 @@ public void testFindOneWithDefaultApplicationAndExistingProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2131,7 +2204,8 @@ public void testFindOneWithNonExistingApplicationAndNullProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2155,7 +2229,8 @@ public void testFindOneWithNonExistingApplicationAndDefaultProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2179,7 +2254,8 @@ public void testFindOneWithNonExistingApplicationAndNonExistingProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2208,7 +2284,8 @@ public void testFindOneWithNonExistingApplicationAndExistingProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2240,7 +2317,8 @@ public void testFindOneWithExistingApplicationAndNullProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2271,7 +2349,8 @@ public void testFindOneWithExistingApplicationAndDefaultProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2302,7 +2381,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2325,7 +2405,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNoDefaultP putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2352,7 +2433,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNoDefaultP putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2390,7 +2472,8 @@ public void testFindOneWithExistingApplicationAndExistingProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2421,7 +2504,8 @@ public void testFindOneWithExistingApplicationAndExistingProfileAndNoDefaultProf putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2467,7 +2551,8 @@ public void testFindOneWithExistingApplicationAndMultipleExistingProfile() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2505,7 +2590,8 @@ public void testFindOneWithExistingApplicationAndMultipleExistingProfileAndNoDef putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2530,7 +2616,8 @@ public void testFindOneWithExistingApplicationAndOrderedMultipleExistingProfileA putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2564,7 +2651,8 @@ public void testFindOneWithOverrides() { putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2578,7 +2666,8 @@ public void testFindOneWithNoSecretsStored() { Environment environment = new Environment(application, profiles, null, null, null); putSecrets(environment); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(environment); } @@ -2608,7 +2697,8 @@ public void testFindOneWithExistingApplicationAndNonExistingProfileAndNoDefaultP Environment emptyEnvironment = new Environment(application, profiles, null, null, null); - Environment resultEnv = repository.findOne(application, profile, null); + Environment resultEnv = repository + .findOne(new RequestContext.Builder().name(application).profiles(profile).build()); assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(emptyEnvironment); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java index 7fe1d0e425..ca14b9ded7 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java @@ -27,6 +27,7 @@ import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.config.CompositeConfiguration; import org.springframework.cloud.config.server.config.ConfigServerHealthIndicator; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -80,7 +81,8 @@ public void testOrder() { repos.add(new TestOrderedEnvironmentRepository(1, e2, loc3)); SearchPathCompositeEnvironmentRepository compositeRepo = new SearchPathCompositeEnvironmentRepository(repos, ObservationRegistry.NOOP, true); - Environment compositeEnv = compositeRepo.findOne("foo", "bar", "world", false); + Environment compositeEnv = compositeRepo + .findOne(new RequestContext.Builder().name("foo").profiles("bar").label("world").build()); List propertySources = compositeEnv.getPropertySources(); assertThat(propertySources).hasSize(5); assertThat(propertySources.get(0).getName()).isEqualTo("p2"); @@ -89,7 +91,8 @@ public void testOrder() { assertThat(propertySources.get(3).getName()).isEqualTo("p1"); assertThat(propertySources.get(4).getName()).isEqualTo("p5"); - SearchPathLocator.Locations locations = compositeRepo.getLocations("app", "dev", "label"); + SearchPathLocator.Locations locations = compositeRepo + .getLocations(new RequestContext.Builder().name("app").profiles("dev").label("label").build()); String[] locationStrings = locations.getLocations(); assertThat(locationStrings.length).isEqualTo(5); assertThat(locationStrings[0]).isEqualTo(sLoc3); @@ -128,10 +131,12 @@ public void testVersion() { ObservationRegistry.NOOP, true); SearchPathCompositeEnvironmentRepository multiCompositeRepo = new SearchPathCompositeEnvironmentRepository( repos2, ObservationRegistry.NOOP, true); - Environment env = compositeRepo.findOne("app", "dev", "label", false); + Environment env = compositeRepo + .findOne(new RequestContext.Builder().name("app").profiles("dev").label("label").build()); assertThat(env.getVersion()).isEqualTo("1"); assertThat(env.getState()).isEqualTo("state"); - Environment multiEnv = multiCompositeRepo.findOne("app", "dev", "label", false); + Environment multiEnv = multiCompositeRepo + .findOne(new RequestContext.Builder().name("app").profiles("dev").label("label").build()); assertThat(multiEnv.getVersion()).isEqualTo(null); assertThat(multiEnv.getState()).isEqualTo(null); } @@ -171,7 +176,8 @@ public void testFailingSubordinateRepositorySkipped() { SearchPathCompositeEnvironmentRepository compositeRepo = new SearchPathCompositeEnvironmentRepository(repos, ObservationRegistry.NOOP, false); - Environment env = compositeRepo.findOne("app", "dev", "label", false); + Environment env = compositeRepo + .findOne(new RequestContext.Builder().name("app").profiles("dev").label("label").build()); List propertySources = env.getPropertySources(); assertThat(propertySources).hasSize(1); assertThat(propertySources.get(0).getName()).isEqualTo("p1"); @@ -188,7 +194,8 @@ public void testFailOnErrorFlagFalseForGetLocations() { SearchPathCompositeEnvironmentRepository compositeRepo = new SearchPathCompositeEnvironmentRepository(repos, ObservationRegistry.NOOP, false); - SearchPathLocator.Locations locations = compositeRepo.getLocations("app", "dev", "label"); + SearchPathLocator.Locations locations = compositeRepo + .getLocations(new RequestContext.Builder().name("app").profiles("dev").label("label").build()); assertThat(locations.getLocations()).isEmpty(); } @@ -203,8 +210,8 @@ public void testFailOnErrorFlagTrueForGetLocations() { SearchPathCompositeEnvironmentRepository compositeRepo = new SearchPathCompositeEnvironmentRepository(repos, ObservationRegistry.NOOP, true); - assertThatExceptionOfType(RepositoryException.class) - .isThrownBy(() -> compositeRepo.getLocations("app", "dev", "label")); + assertThatExceptionOfType(RepositoryException.class).isThrownBy(() -> compositeRepo + .getLocations(new RequestContext.Builder().name("app").profiles("dev").label("label").build())); } private static class TestOrderedEnvironmentRepository implements EnvironmentRepository, SearchPathLocator, Ordered { @@ -222,17 +229,12 @@ private static class TestOrderedEnvironmentRepository implements EnvironmentRepo } @Override - public Environment findOne(String application, String profile, String label) { - return findOne(application, profile, label, false); - } - - @Override - public Environment findOne(String application, String profile, String label, boolean includeOrigin) { + public Environment findOne(RequestContext ctx) { return env; } @Override - public Locations getLocations(String application, String profile, String label) { + public Locations getLocations(RequestContext ctx) { return this.locations; } @@ -250,12 +252,7 @@ private static class TestFailingEnvironmentRepository extends TestOrderedEnviron } @Override - public Environment findOne(String application, String profile, String label, boolean includeOrigin) { - throw new IllegalArgumentException("Failing for some reason"); - } - - @Override - public Environment findOne(String application, String profile, String label) { + public Environment findOne(RequestContext ctx) { throw new IllegalArgumentException("Failing for some reason"); } @@ -268,7 +265,7 @@ private static class TestFailingLocationRepository extends TestOrderedEnvironmen } @Override - public Locations getLocations(String application, String profile, String label) { + public Locations getLocations(RequestContext ctx) { throw new RepositoryException("Failing for some reason"); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepositoryTests.java index 402327bc09..a1c471f1d1 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepositoryTests.java @@ -23,6 +23,7 @@ import org.mockito.Mockito; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.credhub.core.CredHubOperations; import org.springframework.credhub.core.credential.CredHubCredentialOperations; import org.springframework.credhub.support.CredentialDetails; @@ -60,7 +61,8 @@ public void setUp() { public void shouldDisplayEmptyPropertiesWhenNoPathFound() { when(this.credhubCredentialOperations.findByPath("/my-application/production/mylabel")).thenReturn(emptyList()); - Environment environment = this.credhubEnvironmentRepository.findOne("my-application", "production", "mylabel"); + Environment environment = this.credhubEnvironmentRepository.findOne( + new RequestContext.Builder().name("my-application").profiles("production").label("mylabel").build()); assertThat(environment.getName()).isEqualTo("my-application"); assertThat(environment.getProfiles()).containsExactly("production"); @@ -76,7 +78,8 @@ public void shouldDisplayEmptyPropertiesWhenNoPathFound() { public void shouldRetrieveDefaultsWhenNoLabelNorProfileProvided() { stubCredentials("/my-application/default/master", "toggles", "key1", "value1"); - Environment environment = this.credhubEnvironmentRepository.findOne("my-application", null, null); + Environment environment = this.credhubEnvironmentRepository + .findOne(new RequestContext.Builder().name("my-application").build()); assertThat(environment.getName()).isEqualTo("my-application"); assertThat(environment.getProfiles()).containsExactly("default"); @@ -92,7 +95,8 @@ public void shouldRetrieveDefaultsWhenNoLabelNorProfileProvided() { public void shouldRetrieveGivenProfileAndLabel() { stubCredentials("/my-application/production/mylabel", "toggles", "key1", "value1"); - Environment environment = this.credhubEnvironmentRepository.findOne("my-application", "production", "mylabel"); + Environment environment = this.credhubEnvironmentRepository.findOne( + new RequestContext.Builder().name("my-application").profiles("production").label("mylabel").build()); assertThat(environment.getName()).isEqualTo("my-application"); assertThat(environment.getProfiles()).containsExactly("production"); @@ -109,8 +113,8 @@ public void shouldRetrieveGivenMultipleProfiles() { stubCredentials("/my-application/production/mylabel", "toggles", "key1", "value1"); stubCredentials("/my-application/cloud/mylabel", "abs", "key2", "value2"); - Environment environment = this.credhubEnvironmentRepository.findOne("my-application", "production,cloud", - "mylabel"); + Environment environment = this.credhubEnvironmentRepository.findOne(new RequestContext.Builder() + .name("my-application").profiles("production,cloud").label("mylabel").build()); assertThat(environment.getName()).isEqualTo("my-application"); assertThat(environment.getProfiles()).containsExactly("production", "cloud"); @@ -144,7 +148,8 @@ public void shouldMergeWhenMoreThanOneCredentialsFound() { when(this.credhubCredentialOperations.getByName(absCredentialName, JsonCredential.class)) .thenReturn(new CredentialDetails<>("id2", absCredentialName, CredentialType.JSON, otherCredentials)); - Environment environment = this.credhubEnvironmentRepository.findOne("my-application", "production", "mylabel"); + Environment environment = this.credhubEnvironmentRepository.findOne( + new RequestContext.Builder().name("my-application").profiles("production").label("mylabel").build()); assertThat(environment.getName()).isEqualTo("my-application"); assertThat(environment.getProfiles()).containsExactly("production"); @@ -164,7 +169,8 @@ public void shouldIncludeDefaultApplicationWhenOtherProvided() { stubCredentials("/my-application/production/mylabel", "toggles", "key1", "value1"); stubCredentials("/application/production/mylabel", "abs", "key2", "value2"); - Environment environment = this.credhubEnvironmentRepository.findOne("my-application", "production", "mylabel"); + Environment environment = this.credhubEnvironmentRepository.findOne( + new RequestContext.Builder().name("my-application").profiles("production").label("mylabel").build()); assertThat(environment.getName()).isEqualTo("my-application"); assertThat(environment.getProfiles()).containsExactly("production"); @@ -186,7 +192,8 @@ public void shouldIncludeDefaultProfileWhenOtherProvided() { stubCredentials("/my-application/default/mylabel", "abs", "key3", "value3"); stubCredentials("/application/default/mylabel", "abs", "key4", "value4"); - Environment environment = this.credhubEnvironmentRepository.findOne("my-application", "production", "mylabel"); + Environment environment = this.credhubEnvironmentRepository.findOne( + new RequestContext.Builder().name("my-application").profiles("production").label("mylabel").build()); assertThat(environment.getName()).isEqualTo("my-application"); assertThat(environment.getProfiles()).contains("production"); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java index 73c5d065b3..a0b09e5a4d 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java @@ -31,6 +31,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -74,32 +75,35 @@ public void init() { @Test public void environmentNoLabel() throws Exception { - when(this.repository.findOne("foo", "default", null, false)).thenReturn(this.environment); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").build(); + when(this.repository.findOne(ctx)).thenReturn(this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default")) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", "default", null, false); + verify(this.repository).findOne(ctx); } @Test public void profileWithDash() throws Exception { + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("dev-db").build(); Environment dashEnvironment = new Environment("foo", "dev-db"); dashEnvironment.add(new PropertySource("foo", new HashMap<>())); - when(this.repository.findOne("foo", "dev-db", null, false)).thenReturn(dashEnvironment); + when(this.repository.findOne(ctx)).thenReturn(dashEnvironment); this.mvc.perform(MockMvcRequestBuilders.get("/foo/dev-db")) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", "dev-db", null, false); + verify(this.repository).findOne(ctx); } @ParameterizedTest @ValueSource(strings = { "yml", "yaml", "json", "properties" }) public void profileContainingExtensionKeyword(String extensionKeyword) throws Exception { String profiles = "dev-" + extensionKeyword; + RequestContext ctx = new RequestContext.Builder().name("foo").profiles(profiles).build(); Environment dashEnvironment = new Environment("foo", profiles); dashEnvironment.add(new PropertySource("foo", new HashMap<>())); - when(this.repository.findOne("foo", profiles, null, false)).thenReturn(dashEnvironment); + when(this.repository.findOne(ctx)).thenReturn(dashEnvironment); this.mvc.perform(MockMvcRequestBuilders.get("/foo/" + profiles)) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", profiles, null, false); + verify(this.repository).findOne(ctx); } @ParameterizedTest @@ -115,72 +119,81 @@ public void profileHavingAnExtension(String extensionKeyword) throws Exception { @Test public void propertiesNoLabel() throws Exception { - when(this.repository.findOne("foo", "default", null, false)).thenReturn(this.environment); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").build(); + when(this.repository.findOne(ctx)).thenReturn(this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo-default.properties")) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", "default", null, false); + verify(this.repository).findOne(ctx); } @Test public void propertiesLabel() throws Exception { - when(this.repository.findOne("foo", "default", "label", false)).thenReturn(this.environment); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("label").build(); + when(this.repository.findOne(ctx)).thenReturn(this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/label/foo-default.properties")) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", "default", "label", false); + verify(this.repository).findOne(ctx); } @Test public void propertiesLabelWhenApplicationNameContainsHyphen() throws Exception { + RequestContext ctx = new RequestContext.Builder().name("foo-bar").profiles("default").label("label") + .build(); Environment environment = new Environment("foo-bar", "default"); environment.add(new PropertySource("foo", new HashMap<>())); - when(this.repository.findOne("foo-bar", "default", "label", false)).thenReturn(this.environment); + when(this.repository.findOne(ctx)).thenReturn(this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/label/foo-bar-default.properties")) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo-bar", "default", "label", false); + verify(this.repository).findOne(ctx); } @Test public void propertiesLabelWithSlash() throws Exception { - - when(this.repository.findOne("foo", "default", "label/spam", false)).thenReturn(this.environment); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("label/spam") + .build(); + when(this.repository.findOne(ctx)).thenReturn(this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/label(_)spam/foo-default.properties")) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", "default", "label/spam", false); + verify(this.repository).findOne(ctx); } @Test public void environmentWithLabel() throws Exception { - when(this.repository.findOne("foo", "default", "awesome", false)).thenReturn(this.environment); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("awesome").build(); + when(this.repository.findOne(ctx)).thenReturn(this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/awesome")) .andExpect(MockMvcResultMatchers.status().isOk()); } @Test public void environmentWithMissingLabel() throws Exception { - when(this.repository.findOne("foo", "default", "missing", false)) - .thenThrow(new NoSuchLabelException("Planned")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("missing").build(); + when(this.repository.findOne(ctx)).thenThrow(new NoSuchLabelException("Planned")); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/missing")) .andExpect(MockMvcResultMatchers.status().isNotFound()); } @Test public void environmentWithMissingRepo() throws Exception { - when(this.repository.findOne("foo", "default", "missing", false)) - .thenThrow(new NoSuchRepositoryException("Planned")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("missing").build(); + when(this.repository.findOne(ctx)).thenThrow(new NoSuchRepositoryException("Planned")); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/missing")) .andExpect(MockMvcResultMatchers.status().isNotFound()); } @Test public void environmentWithLabelContainingPeriod() throws Exception { - when(this.repository.findOne("foo", "default", "1.0.0", false)).thenReturn(this.environment); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("1.0.0").build(); + when(this.repository.findOne(ctx)).thenReturn(this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/1.0.0")) .andExpect(MockMvcResultMatchers.status().isOk()); } @Test public void environmentWithLabelContainingSlash() throws Exception { - when(this.repository.findOne("foo", "default", "feature/puff", false)).thenReturn(this.environment); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("feature/puff") + .build(); + when(this.repository.findOne(ctx)).thenReturn(this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/feature(_)puff")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"propertySources\":"))); @@ -188,9 +201,10 @@ public void environmentWithLabelContainingSlash() throws Exception { @Test public void environmentWithApplicationContainingSlash() throws Exception { + RequestContext ctx = new RequestContext.Builder().name("foo/app").profiles("default").build(); Environment environment = new Environment("foo/app", "default"); environment.add(new PropertySource("foo", new HashMap<>())); - when(this.repository.findOne("foo/app", "default", null, false)).thenReturn(environment); + when(this.repository.findOne(ctx)).thenReturn(environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo(_)app/default")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"propertySources\":"))); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerTests.java index 415a33bdb7..e021f5ee0d 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerTests.java @@ -34,6 +34,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -47,7 +48,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.entry; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -83,7 +83,8 @@ public void vanillaYaml() throws Exception { Map map = new HashMap(); map.put("a.b.c", "d"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("a:\n b:\n c: d\n"); } @@ -94,7 +95,8 @@ public void propertyOverrideInYaml() throws Exception { map.put("a.b.c", "d"); this.environment.add(new PropertySource("one", map)); this.environment.addFirst(new PropertySource("two", Collections.singletonMap("a.b.c", "e"))); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("a:\n b:\n c: e\n"); } @@ -110,7 +112,8 @@ public void propertyOverrideInYamlMultipleValues() throws Exception { map.put("A", "Z"); map.put("S", 3); this.environment.addFirst(new PropertySource("two", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("A: Z\nS: 3\nY: 0\n"); } @@ -177,7 +180,8 @@ public void arrayInYaml() throws Exception { map.put("a.b[0]", "c"); map.put("a.b[1]", "d"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("a:\n b:\n - c\n - d\n"); } @@ -190,7 +194,8 @@ public void yamlWithBrackets() throws Exception { map.put("a.b[world]", "d"); map.put("a.b[world]d", "f"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("a:\n test: e\n b[hello]: c\n b[world]: d\n b[world]d: f\n"); } @@ -210,7 +215,8 @@ public void arrayOverridenInEnvironment() throws Exception { twoMap.put("a.b[1]", "h"); this.environment.addFirst(new PropertySource("two", twoMap)); - when(this.repository.findOne("foo", "bar", "two", false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").label("two").build())) + .thenReturn(this.environment); Environment environment = this.controller.labelled("foo", "bar", "two"); assertThat(environment).isNotNull(); assertThat(environment.getName()).isEqualTo("foo"); @@ -226,7 +232,9 @@ public void arrayOverridenInEnvironment() throws Exception { @Test public void testNameWithSlash() { - when(this.repository.findOne("foo/spam", "bar", "two", false)).thenReturn(this.environment); + when(this.repository + .findOne(new RequestContext.Builder().name("foo/spam").profiles("bar").label("two").build())) + .thenReturn(this.environment); Environment returnedEnvironment = this.controller.labelled("foo(_)spam", "bar", "two"); @@ -244,7 +252,8 @@ public void testEnvironmentNotFound() { @Test public void testwithValidEnvironment() { - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); Environment environment = this.controller.labelled("foo", "bar", null); assertThat(environment).isNotNull(); @@ -253,7 +262,9 @@ public void testwithValidEnvironment() { @Test public void testLabelWithSlash() { - when(this.repository.findOne("foo", "bar", "two/spam", false)).thenReturn(this.environment); + when(this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").label("two/spam").build())) + .thenReturn(this.environment); Environment returnedEnvironment = this.controller.labelled("foo", "bar", "two(_)spam"); @@ -276,7 +287,8 @@ public void arrayOverridenInYaml() throws Exception { twoMap.put("a.b[1]", "h"); this.environment.addFirst(new PropertySource("two", twoMap)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); // Result will not contain original, extra values from oneMap @@ -288,7 +300,8 @@ public void textAtTopLevelInYaml() throws Exception { Map map = new LinkedHashMap(); map.put("document", "blah"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("blah\n"); } @@ -299,7 +312,8 @@ public void arrayAtTopLevelInYaml() throws Exception { map.put("document[0]", "c"); map.put("document[1]", "d"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("- c\n- d\n"); } @@ -310,7 +324,8 @@ public void arrayObObjectAtTopLevelInYaml() throws Exception { map.put("document[0].a", "c"); map.put("document[1].a", "d"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("- a: c\n- a: d\n"); } @@ -321,7 +336,8 @@ public void yamlWithProperties() throws Exception { map.put("org.springframework", "WARN"); map.put("org.springframework.cloud", "ERROR"); this.environment.add(new PropertySource("abo", map)); - when(this.repository.findOne("ay", "äzöq", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("ay").profiles("äzöq").build())) + .thenReturn(this.environment); System.out.println("this.controller = " + this.controller); String yaml = this.controller.yaml("ay", "äzöq", false).getBody(); assertThat(yaml).isEqualTo("org:\n springframework: WARN\n springframework.cloud: ERROR\n"); @@ -334,7 +350,8 @@ public void arrayOfObjectInYaml() throws Exception { map.put("a.b[0].d", "e"); map.put("a.b[1].c", "d"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat("a:\n b:\n - d: e\n c: d\n - c: d\n".equals(yaml) || "a:\n b:\n - c: d\n d: e\n - c: d\n".equals(yaml)).as("Wrong output: " + yaml).isTrue(); @@ -351,7 +368,8 @@ public void nestedArraysOfObjectInYaml() throws Exception { map.put("a.b[3][0]", "r"); map.put("a.b[3][1]", "s"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); Map level1 = new Yaml().load(yaml); @@ -391,7 +409,8 @@ public void nestedArraysOfObjectInJson() throws Exception { map.put("a.b[1].c", "y"); map.put("a.b[1].e[0].d", "z"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String json = this.controller.jsonProperties("foo", "bar", false).getBody(); assertThat(json).as("Wrong output: " + json) .isEqualTo("{\"a\":{\"b\":[{\"c\":\"x\",\"d\":[\"xx\",\"yy\"]},{\"c\":\"y\",\"e\":[{\"d\":\"z\"}]}]}}"); @@ -403,7 +422,8 @@ public void arrayOfObjectAtTopLevelInYaml() throws Exception { map.put("b[0].c", "d"); map.put("b[1].c", "d"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("b:\n- c: d\n- c: d\n"); } @@ -414,7 +434,8 @@ public void arrayOfObjectNestedLevelInYaml() throws Exception { map.put("x.a.b[0].c", "d"); map.put("x.a.b[1].c", "d"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); String yaml = this.controller.yaml("foo", "bar", false).getBody(); assertThat(yaml).isEqualTo("x:\n a:\n b:\n - c: d\n - c: d\n"); } @@ -507,19 +528,22 @@ private void whenPlaceholders() { map.put("foo", "bar"); this.environment.add(new PropertySource("one", map)); this.environment.addFirst(new PropertySource("two", Collections.singletonMap("a.b.c", "${foo}"))); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); } private void whenPlaceholdersSystemProps() { System.setProperty("foo", "bar"); this.environment.addFirst(new PropertySource("two", Collections.singletonMap("a.b.c", "${foo}"))); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); } private void whenPlaceholdersSystemPropsWithDefault() { System.setProperty("foo", "bar"); this.environment.addFirst(new PropertySource("two", Collections.singletonMap("a.b.c", "${foo:spam}"))); - when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment); + when(this.repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(this.environment); } @Test @@ -558,31 +582,35 @@ abstract class MockMvcTestCases { @Test public void mappingForEnvironment() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo", "bar", null, false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo/bar")).andExpect(MockMvcResultMatchers.status().isOk()); } @Test public void mappingForLabelledEnvironment() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo", "bar", "other", false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").label("other").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo/bar/other")) .andExpect(MockMvcResultMatchers.status().isOk()); } @Test public void environmentMissing() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo1", "notfound", null, false)) - .thenThrow(new EnvironmentNotFoundException("Missing Environment")); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo1").profiles("notfound").build())) + .thenThrow(new EnvironmentNotFoundException("Missing Environment")); this.mvc.perform(MockMvcRequestBuilders.get("/foo1/notfound")) .andExpect(MockMvcResultMatchers.status().isNotFound()); } @Test public void mappingForYaml() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo", "bar", null, false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo-bar.yml")) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.TEXT_PLAIN)) .andExpect(MockMvcResultMatchers.content().string("{}\n")); @@ -590,8 +618,9 @@ public void mappingForYaml() throws Exception { @Test public void mappingForJson() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo", "bar", null, false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo-bar.json")) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.content().string("{}")); @@ -599,56 +628,63 @@ public void mappingForJson() throws Exception { @Test public void mappingForLabelledYaml() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo", "bar", "other", false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").label("other").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar.yml")) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.TEXT_PLAIN)); } @Test public void mappingForLabelledProperties() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo", "bar", "other", false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").label("other").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar.properties")) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.TEXT_PLAIN)); } @Test public void mappingForProperties() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo", "bar", null, false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo-bar.properties")) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.TEXT_PLAIN)); } @Test public void mappingForLabelledYamlWithHyphen() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo-bar-foo2-bar2", "spam", "other", false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository.findOne( + new RequestContext.Builder().name("foo-bar-foo2-bar2").profiles("spam").label("other").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar-foo2-bar2-spam.yml")) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.TEXT_PLAIN)); } @Test public void mappingforLabelledJsonProperties() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo", "bar", "other", false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").label("other").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar.json")) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)); } @Test public void mappingforJsonProperties() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo", "bar", null, false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/foo-bar.json")) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)); } @Test public void mappingForLabelledJsonPropertiesWithHyphen() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne("foo-bar-foo2-bar2", "spam", "other", false)) - .thenReturn(EnvironmentControllerTests.this.environment); + when(EnvironmentControllerTests.this.repository.findOne( + new RequestContext.Builder().name("foo-bar-foo2-bar2").profiles("spam").label("other").build())) + .thenReturn(EnvironmentControllerTests.this.environment); this.mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar-foo2-bar2-spam.json")) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)); @@ -656,8 +692,9 @@ public void mappingForLabelledJsonPropertiesWithHyphen() throws Exception { @Test public void handleEnvironmentException() throws Exception { - when(EnvironmentControllerTests.this.repository.findOne(eq("exception"), eq("bad_syntax.ext"), any(), - eq(false))) + + when(EnvironmentControllerTests.this.repository.findOne( + new RequestContext.Builder().name("exception").profiles("bad_syntax.ext").label(any()).build())) .thenThrow(new FailedToConstructEnvironmentException("Cannot construct", new RuntimeException("underlier"))); MvcResult result = this.mvc.perform(MockMvcRequestBuilders.get("/exception/bad_syntax.ext")) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepositoryTests.java index 4a0b8877ed..312f4bdf64 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepositoryTests.java @@ -29,6 +29,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.support.RequestContext; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -55,24 +56,26 @@ public void init() { @Test public void allowOverrideFalse() throws Exception { + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("bar").label("master").build(); this.controller.setOverrides(Collections.singletonMap("foo", "bar")); Map map = new HashMap(); map.put("a.b.c", "d"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", "master", false)).thenReturn(this.environment); - assertThat(this.controller.findOne("foo", "bar", "master", false).getPropertySources().get(0).getSource() - .toString()).isEqualTo("{foo=bar}"); + when(this.repository.findOne(ctx)).thenReturn(this.environment); + assertThat(this.controller.findOne(ctx).getPropertySources().get(0).getSource().toString()) + .isEqualTo("{foo=bar}"); } @Test public void overrideWithEscapedPlaceholders() throws Exception { + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("bar").label("master").build(); this.controller.setOverrides(Collections.singletonMap("foo", "$\\{bar}")); Map map = new HashMap(); map.put("bar", "foo"); this.environment.add(new PropertySource("one", map)); - when(this.repository.findOne("foo", "bar", "master", false)).thenReturn(this.environment); - assertThat(this.controller.findOne("foo", "bar", "master", false).getPropertySources().get(0).getSource() - .toString()).isEqualTo("{foo=${bar}}"); + when(this.repository.findOne(ctx)).thenReturn(this.environment); + assertThat(this.controller.findOne(ctx).getPropertySources().get(0).getSource().toString()) + .isEqualTo("{foo=${bar}}"); } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryConcurrencyTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryConcurrencyTests.java index 1b1e25abbe..9c5455bf0d 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryConcurrencyTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryConcurrencyTests.java @@ -56,6 +56,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.config.ConfigServerProperties; import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; @@ -108,14 +109,16 @@ public void vanilla() throws Exception { tasks.add(threads.submit(new Runnable() { @Override public void run() { - repository.findOne("bar", "staging", "master"); + repository.findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); } }, true)); } for (Future future : tasks) { future.get(); } - Environment environment = repository.findOne("bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getName()).isEqualTo("bar"); assertThat(environment.getProfiles()).isEqualTo(new String[] { "staging" }); @@ -146,7 +149,8 @@ public void concurrentRefreshContextAndGetLabels() throws Exception { public void run() { JGitEnvironmentRepositoryConcurrencyTests.this.logger.info("client start."); try { - Environment environment = testData.getRepository().findOne("bar", "staging", "master"); + Environment environment = testData.getRepository().findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); } catch (Exception e) { errorCount.incrementAndGet(); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java index 3052622fbe..b10fe6cb41 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java @@ -54,6 +54,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.config.ConfigServerProperties; import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; @@ -105,7 +106,8 @@ public void vanilla() throws IOException { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .properties("spring.cloud.config.server.git.uri:" + uri).run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getName()).isEqualTo("bar"); assertThat(environment.getProfiles()).isEqualTo(new String[] { "staging" }); @@ -121,7 +123,8 @@ public void shouldFailIfNotTryingMaster() { "spring.cloud.config.server.git.tryMasterBranch:false") .run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", null); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").build()); }); } @@ -132,7 +135,8 @@ public void pull() throws Exception { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .run("--spring.cloud.config.server.git.uri=" + uri); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("bar"); Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile()); git.checkout().setName("master").call(); @@ -140,7 +144,8 @@ public void pull() throws Exception { new FileOutputStream(ResourceUtils.getFile(uri + "/bar.properties"))); git.add().addFilepattern("bar.properties").call(); git.commit().setMessage("Updated for pull").call(); - environment = repository.findOne("bar", "staging", "master"); + environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("foo"); } @@ -176,7 +181,8 @@ public void pullDirtyRepo() throws Exception { JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); // Fetches the repository for the first time. - SearchPathLocator.Locations locations = repository.getLocations("bar", "test", "raw"); + SearchPathLocator.Locations locations = repository + .getLocations(new RequestContext.Builder().name("bar").profiles("test").label("raw").build()); assertThat(commitToRevertBeforePull).isEqualTo(locations.getVersion()); // Resets to the original commit. @@ -196,7 +202,8 @@ public void pullDirtyRepo() throws Exception { git.reset().setMode(ResetType.HARD).setRef(commitToRevertBeforePull).call(); // Triggers the repository refresh. - locations = repository.getLocations("bar", "test", "raw"); + locations = repository + .getLocations(new RequestContext.Builder().name("bar").profiles("test").label("raw").build()); assertThat(conflictingCommit).isEqualTo(locations.getVersion()); assertThat(git.status().call().isClean()).as("Local repository is not cleaned after retrieving resources.") @@ -208,7 +215,8 @@ public void pullMissingRepo() throws Exception { pull(); JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); new File(repository.getUri().replaceAll("file:", ""), ".git/index.lock").createNewFile(); - Environment environment = repository.findOne("bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("foo"); } @@ -219,7 +227,8 @@ public void nested() throws IOException { // TODO: why didn't .properties() work for me? .run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths=sub"); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); } @@ -231,7 +240,8 @@ public void nestedWithApplicationPlaceholders() throws IOException { .run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths={application}"); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("foo,bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("foo,bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(3); } @@ -242,7 +252,8 @@ public void verifyPropertySourceOrdering() throws IOException { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths=**"); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("application", "test", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("application").profiles("test").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo("file:././target/repos/ordering-repo//project/sub/application-test.yml"); @@ -258,7 +269,8 @@ public void nestedWithProfilePlaceholders() throws IOException { .run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths={profile}"); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("staging", "foo,bar", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("staging").profiles("foo,bar").label("master").build()); assertThat(environment.getPropertySources()).hasSize(3); } @@ -290,7 +302,8 @@ public void invalidLabel() { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .properties("spring.cloud.config.server.git.uri:" + uri).run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - repository.findOne("bar", "staging", "unknownlabel"); + repository.findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("unknownlabel").build()); }); } @@ -302,7 +315,8 @@ public void findOne_CloneOnStartTrue_FindOneSuccess() throws Exception { "--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.cloneOnStart=true"); EnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class); assertThat(((JGitEnvironmentRepository) repository).isCloneOnStart()).isTrue(); - Environment environment = repository.findOne("bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getName()).isEqualTo("bar"); assertThat(environment.getProfiles()).isEqualTo(new String[] { "staging" }); @@ -316,7 +330,8 @@ public void findOne_FileAddedToRepo_FindOneSuccess() throws Exception { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).run( "--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.cloneOnStart=true"); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("bar"); Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile()); git.checkout().setName("master").call(); @@ -324,7 +339,8 @@ public void findOne_FileAddedToRepo_FindOneSuccess() throws Exception { new FileOutputStream(ResourceUtils.getFile(uri + "/bar.properties"))); git.add().addFilepattern("bar.properties").call(); git.commit().setMessage("Updated for pull").call(); - environment = repository.findOne("bar", "staging", "master"); + environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("foo"); } @@ -336,7 +352,8 @@ public void findOne_NestedSearchPath_FindOneSuccess() throws IOException { .run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths=sub", "--spring.cloud.config.server.git.cloneOnStart=true"); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); } @@ -349,7 +366,8 @@ public void findOne_FindInvalidLabel_IllegalStateExceptionThrown() throws IOExce "--spring.cloud.config.server.git.cloneOnStart=true") .run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - repository.findOne("bar", "staging", "unknownlabel"); + repository.findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("unknownlabel").build()); }); } @@ -363,7 +381,8 @@ public void testVersionUpdate() throws Exception { String startingRemoteVersion = getCommitID(testData.getServerGit().getGit(), "master"); // make sure we get the right version out of the gate - Environment environment = testData.getRepository().findOne("bar", "staging", "master"); + Environment environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); // make sure the environments version is the same as the remote repo // version @@ -378,7 +397,8 @@ public void testVersionUpdate() throws Exception { // pull the environment again which should update the local repo from // the just updated remote repo - environment = testData.getRepository().findOne("bar", "staging", "master"); + environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); // do some more check outs to get updated version numbers String updatedLocalVersion = getCommitID(testData.getClonedGit().getGit(), "master"); @@ -399,7 +419,8 @@ public void testNewRemoteBranch() throws Exception { JGitConfigServerTestData testData = JGitConfigServerTestData .prepareClonedGitRepository(TestConfiguration.class); - Environment environment = testData.getRepository().findOne("bar", "staging", "master"); + Environment environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); Object fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("bar").isEqualTo(fooProperty); @@ -414,7 +435,8 @@ public void testNewRemoteBranch() throws Exception { testData.getServerGit().getGit().add().addFilepattern("bar.properties").call(); testData.getServerGit().getGit().commit().setMessage("Updated for branch test").call(); - environment = testData.getRepository().findOne("bar", "staging", "testNewRemoteBranch"); + environment = testData.getRepository().findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("testNewRemoteBranch").build()); fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("branchBar").isEqualTo(fooProperty); } @@ -426,7 +448,8 @@ public void testNewRemoteTag() throws Exception { Git serverGit = testData.getServerGit().getGit(); - Environment environment = testData.getRepository().findOne("bar", "staging", "master"); + Environment environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); Object fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("bar").isEqualTo(fooProperty); @@ -442,18 +465,21 @@ public void testNewRemoteTag() throws Exception { testData.getServerGit().getGit().add().addFilepattern("bar.properties").call(); testData.getServerGit().getGit().commit().setMessage("Updated for branch test").call(); - environment = testData.getRepository().findOne("bar", "staging", "master"); + environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("testAfterTag").isEqualTo(fooProperty); - environment = testData.getRepository().findOne("bar", "staging", "testTag"); + environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("testTag").build()); fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("bar").isEqualTo(fooProperty); // now move the tag and test again serverGit.tag().setName("testTag").setForceUpdate(true).setMessage("Testing a moved tag").call(); - environment = testData.getRepository().findOne("bar", "staging", "testTag"); + environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("testTag").build()); fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("testAfterTag").isEqualTo(fooProperty); @@ -468,7 +494,8 @@ public void testNewCommitID() throws Exception { String startingRemoteVersion = getCommitID(testData.getServerGit().getGit(), "master"); // make sure we get the right version out of the gate - Environment environment = testData.getRepository().findOne("bar", "staging", "master"); + Environment environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(startingRemoteVersion).isEqualTo(environment.getVersion()); // update the remote repo @@ -480,13 +507,15 @@ public void testNewCommitID() throws Exception { String updatedRemoteVersion = getCommitID(testData.getServerGit().getGit(), "master"); // do a normal request and verify we get the new version - environment = testData.getRepository().findOne("bar", "staging", "master"); + environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(updatedRemoteVersion).isEqualTo(environment.getVersion()); Object fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("barNewCommit").isEqualTo(fooProperty); // request the prior commit ID and make sure we get it - environment = testData.getRepository().findOne("bar", "staging", startingRemoteVersion); + environment = testData.getRepository().findOne( + new RequestContext.Builder().name("bar").profiles("staging").label(startingRemoteVersion).build()); assertThat(startingRemoteVersion).isEqualTo(environment.getVersion()); fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("bar").isEqualTo(fooProperty); @@ -512,7 +541,8 @@ public void testNewCommitIDWithRefreshRate() throws Exception { // Ask test label configuration first try { - testData.getRepository().findOne("bar", "staging", "test"); + testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("test").build()); fail("Should have thrown NoSuchLabelException."); } catch (NoSuchLabelException ex) { @@ -520,7 +550,8 @@ public void testNewCommitIDWithRefreshRate() throws Exception { } // make sure we get the right version out of the gate - Environment environment = testData.getRepository().findOne("bar", "staging", "master"); + Environment environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(startingRemoteVersion).isEqualTo(environment.getVersion()); // update the remote repo @@ -536,7 +567,8 @@ public void testNewCommitIDWithRefreshRate() throws Exception { // Ask test label configuration first try { - testData.getRepository().findOne("bar", "staging", "test"); + testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("test").build()); fail("Should have thrown NoSuchLabelException."); } catch (NoSuchLabelException ex) { @@ -544,13 +576,15 @@ public void testNewCommitIDWithRefreshRate() throws Exception { } // do a normal request and verify we get the new version - environment = testData.getRepository().findOne("bar", "staging", "master"); + environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(updatedRemoteVersion).isEqualTo(environment.getVersion()); Object fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("barNewCommit").isEqualTo(fooProperty); // request the prior commit ID and make sure we get it - environment = testData.getRepository().findOne("bar", "staging", startingRemoteVersion); + environment = testData.getRepository().findOne( + new RequestContext.Builder().name("bar").profiles("staging").label(startingRemoteVersion).build()); assertThat(startingRemoteVersion).isEqualTo(environment.getVersion()); fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo"); assertThat("bar").isEqualTo(fooProperty); @@ -561,7 +595,8 @@ public void testUnknownLabelWithRemote() throws Exception { assertThatExceptionOfType(NoSuchLabelException.class).isThrownBy(() -> { JGitConfigServerTestData testData = JGitConfigServerTestData .prepareClonedGitRepository(TestConfiguration.class); - testData.getRepository().findOne("bar", "staging", "BADLabel"); + testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("BADLabel").build()); }); } @@ -611,11 +646,13 @@ public void testShouldReturnEnvironmentFromLocalBranchInCaseRemoteDeleted() thro String branchToDelete = "branchToDelete"; testData.getServerGit().getGit().branchCreate().setName(branchToDelete).call(); - Environment environment = testData.getRepository().findOne("bar", "staging", "branchToDelete"); + Environment environment = testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("branchToDelete").build()); assertThat(environment).isNotNull(); testData.getServerGit().getGit().branchDelete().setBranchNames(branchToDelete).call(); - testData.getRepository().findOne("bar", "staging", "branchToDelete"); + testData.getRepository() + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("branchToDelete").build()); assertThat(environment).isNotNull(); } @@ -630,14 +667,16 @@ public void testShouldFailIfRemoteBranchWasDeleted() throws Exception { testData.getServerGit().getGit().branchCreate().setName(branchToDelete).call(); // checkout and simulate regular flow - Environment environment = testData.getRepository().findOne("bar", "staging", "branchToDelete"); + Environment environment = testData.getRepository().findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("branchToDelete").build()); assertThat(environment).isNotNull(); // remove branch testData.getServerGit().getGit().branchDelete().setBranchNames(branchToDelete).call(); // test - testData.getRepository().findOne("bar", "staging", "branchToDelete"); + testData.getRepository().findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("branchToDelete").build()); }); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositorySslTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositorySslTests.java index 00b1858c55..7f5eece237 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositorySslTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositorySslTests.java @@ -37,6 +37,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.config.server.config.ConfigServerProperties; import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -79,7 +80,8 @@ public void selfSignedCertIsRejected() { JGitEnvironmentRepository repository = context.getBean(JGitEnvironmentRepository.class); try { - repository.findOne("bar", "staging", "master"); + repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); } catch (Throwable e) { while (e.getCause() != null) { @@ -100,7 +102,7 @@ public void selfSignedCertWithSkipSslValidationIsAccepted() { .web(WebApplicationType.NONE).run(); JGitEnvironmentRepository repository = context.getBean(JGitEnvironmentRepository.class); - repository.findOne("bar", "staging", "master"); + repository.findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); } @Configuration(proxyBeanMethods = false) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java index 2a3aee03df..0e59d362bb 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java @@ -77,6 +77,7 @@ import org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider; import org.springframework.cloud.config.server.support.GitSkipSslValidationCredentialsProvider; import org.springframework.cloud.config.server.support.PassphraseCredentialsProvider; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.core.env.StandardEnvironment; @@ -130,7 +131,8 @@ public void init() throws Exception { @Test public void vanilla() { - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -142,7 +144,8 @@ public void nested() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.repository.setUri(uri); this.repository.setSearchPaths(new String[] { "sub" }); - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/sub/application.yml"); @@ -154,7 +157,8 @@ public void placeholderInSearchPath() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.repository.setUri(uri); this.repository.setSearchPaths(new String[] { "{application}" }); - Environment environment = this.repository.findOne("sub", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("sub").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/sub/application.yml"); @@ -173,7 +177,8 @@ public void nestedPattern() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.repository.setUri(uri); this.repository.setSearchPaths(new String[] { "sub*" }); - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/sub/application.yml"); @@ -183,7 +188,8 @@ public void nestedPattern() throws IOException { @Test public void branch() { this.repository.setBasedir(this.basedir); - Environment environment = this.repository.findOne("bar", "staging", "raw"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("raw").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -193,7 +199,8 @@ public void branch() { @Test public void tag() { this.repository.setBasedir(this.basedir); - Environment environment = this.repository.findOne("bar", "staging", "foo"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("foo").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -203,7 +210,8 @@ public void tag() { @Test public void basedir() { this.repository.setBasedir(this.basedir); - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -215,7 +223,8 @@ public void basedirExists() throws Exception { assertThat(this.basedir.mkdirs()).isTrue(); assertThat(new File(this.basedir, ".nothing").createNewFile()).isTrue(); this.repository.setBasedir(this.basedir); - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -240,11 +249,13 @@ public void testBranchEndsWithTag() throws IOException { this.repository.setUri(uri); // exists branch "feature/foo" - Environment environment = this.repository.findOne("bar", "staging", "feature/foo"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("feature/foo").build()); assertVersion(environment); // try tag "foo" - environment = this.repository.findOne("bar", "staging", "foo"); + environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("foo").build()); assertThat(environment.getPropertySources().get(0).getSource().get("key")).isEqualTo("value from tag"); } @@ -628,7 +639,8 @@ public void testFetchException() throws Exception { // here is our exception we are testing when(mergeCommand.call()).thenThrow(new NotMergedException()); - SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", null); + SearchPathLocator.Locations locations = this.repository + .getLocations(new RequestContext.Builder().name("bar").profiles("staging").build()); assertThat(newObjectId.getName()).isEqualTo(locations.getVersion()); verify(git, times(0)).branchDelete(); @@ -743,7 +755,8 @@ public void testMergeException() throws Exception { // exception we // are testing - SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", "master"); + SearchPathLocator.Locations locations = this.repository + .getLocations(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(newObjectId.getName()).isEqualTo(locations.getVersion()); verify(git, times(0)).branchDelete(); @@ -855,7 +868,8 @@ public void testResetHardException() throws Exception { when(git.reset()).thenReturn(resetCommand); when(resetCommand.call()).thenReturn(ref); - SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", "master"); + SearchPathLocator.Locations locations = this.repository + .getLocations(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(newObjectId.getName()).isEqualTo(locations.getVersion()); verify(git, times(0)).branchDelete(); @@ -877,7 +891,7 @@ public void shouldDeleteBaseDirWhenCloneFails() throws Exception { envRepository.setBasedir(this.basedir); try { - envRepository.findOne("bar", "staging", "master"); + envRepository.findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); } catch (Exception ex) { // expected - ignore @@ -1189,7 +1203,8 @@ public void shouldHandleExceptionWhileRemovingBranches() throws Exception { when(mergeResult.getMergeStatus()).thenReturn(mergeStatus); when(mergeStatus.isSuccessful()).thenReturn(true); - SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", "master"); + SearchPathLocator.Locations locations = this.repository + .getLocations(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(newObjectId.getName()).isEqualTo(locations.getVersion()); verify(deleteBranchCommand).setBranchNames(eq("feature/deletedBranchFromOrigin")); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryTests.java index 7ff0534ab9..f716c81a70 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryTests.java @@ -27,6 +27,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.JdbcEnvironmentRepositoryTests.ApplicationConfiguration; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.context.annotation.Configuration; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; @@ -53,7 +54,8 @@ public class JdbcEnvironmentRepositoryTests { public void basicProperties() { JdbcEnvironmentProperties properties = new JdbcEnvironmentProperties(); Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties, - new JdbcEnvironmentRepository.PropertiesResultSetExtractor()).findOne("foo", "bar", ""); + new JdbcEnvironmentRepository.PropertiesResultSetExtractor()) + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertThat(env.getName()).isEqualTo("foo"); assertThat(env.getProfiles()).isEqualTo(new String[] { "bar" }); assertThat(env.getLabel()).isEqualTo("master"); @@ -72,7 +74,8 @@ public void basicProperties() { public void testDefaultProfile() { JdbcEnvironmentProperties properties = new JdbcEnvironmentProperties(); Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties, - new JdbcEnvironmentRepository.PropertiesResultSetExtractor()).findOne("foo", "", ""); + new JdbcEnvironmentRepository.PropertiesResultSetExtractor()) + .findOne(new RequestContext.Builder().name("foo").build()); assertThat(env.getName()).isEqualTo("foo"); assertThat(env.getProfiles()).isEqualTo(new String[] { "default" }); assertThat(env.getLabel()).isEqualTo("master"); @@ -91,7 +94,8 @@ public void testDefaultProfile() { public void testProfileNotExist() { JdbcEnvironmentProperties properties = new JdbcEnvironmentProperties(); Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties, - new JdbcEnvironmentRepository.PropertiesResultSetExtractor()).findOne("foo", "not_exist", ""); + new JdbcEnvironmentRepository.PropertiesResultSetExtractor()) + .findOne(new RequestContext.Builder().name("foo").profiles("not_exist").build()); assertThat(env.getName()).isEqualTo("foo"); assertThat(env.getProfiles()).isEqualTo(new String[] { "not_exist" }); assertThat(env.getLabel()).isEqualTo("master"); @@ -106,7 +110,8 @@ public void testProfileNotExist() { public void testApplicationNotExist() { JdbcEnvironmentProperties properties = new JdbcEnvironmentProperties(); Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties, - new JdbcEnvironmentRepository.PropertiesResultSetExtractor()).findOne("not_exist", "bar", ""); + new JdbcEnvironmentRepository.PropertiesResultSetExtractor()) + .findOne(new RequestContext.Builder().name("not_exist").profiles("bar").build()); assertThat(env.getName()).isEqualTo("not_exist"); assertThat(env.getProfiles()).isEqualTo(new String[] { "bar" }); assertThat(env.getLabel()).isEqualTo("master"); @@ -121,7 +126,8 @@ public void testApplicationNotExist() { public void testApplicationProfileBothNotExist() { JdbcEnvironmentProperties properties = new JdbcEnvironmentProperties(); Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties, - new JdbcEnvironmentRepository.PropertiesResultSetExtractor()).findOne("not_exist", "not_exist", ""); + new JdbcEnvironmentRepository.PropertiesResultSetExtractor()) + .findOne(new RequestContext.Builder().name("not_exist").profiles("not_exist").build()); assertThat(env.getName()).isEqualTo("not_exist"); assertThat(env.getProfiles()).isEqualTo(new String[] { "not_exist" }); assertThat(env.getLabel()).isEqualTo("master"); @@ -137,7 +143,8 @@ public void testCustomSql() { properties.setSqlWithoutProfile( "SELECT MY_KEY, MY_VALUE from MY_PROPERTIES where APPLICATION=? and PROFILE is null and LABEL=?"); Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties, - new JdbcEnvironmentRepository.PropertiesResultSetExtractor()).findOne("foo", "bar", ""); + new JdbcEnvironmentRepository.PropertiesResultSetExtractor()) + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertThat(env.getName()).isEqualTo("foo"); assertThat(env.getProfiles()).isEqualTo(new String[] { "bar" }); assertThat(env.getLabel()).isEqualTo("master"); @@ -157,7 +164,8 @@ public void testIncompleteConfig() { JdbcEnvironmentProperties properties = new JdbcEnvironmentProperties(); properties.setSql("SELECT MY_KEY, MY_VALUE from MY_PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?"); Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties, - new JdbcEnvironmentRepository.PropertiesResultSetExtractor()).findOne("foo", "bar", ""); + new JdbcEnvironmentRepository.PropertiesResultSetExtractor()) + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertThat(env.getName()).isEqualTo("foo"); assertThat(env.getProfiles()).isEqualTo(new String[] { "default", "bar" }); assertThat(env.getLabel()).isEqualTo("master"); @@ -183,7 +191,8 @@ public void testNotFailOnError() { properties.setSqlWithoutProfile( "SELECT SHOULD_FAIL from TABLE_NOTEXIST where APPLICATION=? and PROFILE is null and LABEL=?"); Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties, - new JdbcEnvironmentRepository.PropertiesResultSetExtractor()).findOne("foo", "bar", ""); + new JdbcEnvironmentRepository.PropertiesResultSetExtractor()) + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertThat(env.getName()).isEqualTo("foo"); assertThat(env.getProfiles()).isEqualTo(new String[] { "bar" }); assertThat(env.getLabel()).isEqualTo("master"); @@ -201,7 +210,8 @@ public void testFailOnError() { "SELECT SHOULD_FAIL from TABLE_NOTEXIST where APPLICATION=? and PROFILE is null and LABEL=?"); JdbcEnvironmentRepository repository = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties); - assertThatThrownBy(() -> repository.findOne("foo", "bar", "")).isInstanceOf(DataAccessException.class); + assertThatThrownBy(() -> repository.findOne(new RequestContext.Builder().name("foo").profiles("bar").build())) + .isInstanceOf(DataAccessException.class); } @Test @@ -209,7 +219,8 @@ public void testCustomLabel() { JdbcEnvironmentProperties properties = new JdbcEnvironmentProperties(); properties.setDefaultLabel("main"); Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties, - new JdbcEnvironmentRepository.PropertiesResultSetExtractor()).findOne("foo", "bar", ""); + new JdbcEnvironmentRepository.PropertiesResultSetExtractor()) + .findOne(new RequestContext.Builder().name("foo").profiles("bar").build()); assertThat(env.getName()).isEqualTo("foo"); assertThat(env.getProfiles()).isEqualTo(new String[] { "bar" }); assertThat(env.getLabel()).isEqualTo("main"); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests.java index 19a4f2e2eb..36ffe68ad7 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests.java @@ -30,6 +30,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository; import org.springframework.cloud.config.server.environment.SearchPathLocator.Locations; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.core.env.StandardEnvironment; @@ -81,7 +82,8 @@ private PatternMatchingJGitEnvironmentRepository createRepository(String name, S @Test public void defaultRepo() { - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -90,7 +92,8 @@ public void defaultRepo() { @Test public void missingRepo() { - Environment environment = this.repository.findOne("missing-config-repo", "staging", "master"); + Environment environment = this.repository.findOne( + new RequestContext.Builder().name("missing-config-repo").profiles("staging").label("master").build()); assertThat(environment.getPropertySources().size()).as("Wrong property sources: " + environment).isEqualTo(1); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/application.yml"); @@ -99,7 +102,8 @@ public void missingRepo() { @Test public void mappingRepo() { - Environment environment = this.repository.findOne("test1-config-repo", "staging", "master"); + Environment environment = this.repository.findOne( + new RequestContext.Builder().name("test1-config-repo").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(getUri("*").replace("{application}", "test1-config-repo") + "/application.yml"); @@ -108,7 +112,8 @@ public void mappingRepo() { @Test public void otherMappingRepo() { - Environment environment = this.repository.findOne("test2-config-repo", "staging", "master"); + Environment environment = this.repository.findOne( + new RequestContext.Builder().name("test2-config-repo").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(getUri("*").replace("{application}", "test2-config-repo") + "/application.properties"); @@ -119,7 +124,8 @@ public void otherMappingRepo() { @Disabled("not supported yet (placeholders in search paths with lists)") public void profilesInSearchPaths() { this.repository.setSearchPaths("{profile}"); - Locations locations = this.repository.getLocations("foo", "dev,one,two", "master"); + Locations locations = this.repository + .getLocations(new RequestContext.Builder().name("foo").profiles("dev,one,two").label("master").build()); assertThat(locations.getLocations().length).isEqualTo(3); assertThat(locations.getLocations()[0]).isEqualTo("classpath:/test/dev/"); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentLabelPlaceholderRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentLabelPlaceholderRepositoryTests.java index b5a03ec62c..ab86873380 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentLabelPlaceholderRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentLabelPlaceholderRepositoryTests.java @@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.core.env.StandardEnvironment; @@ -57,7 +58,8 @@ public void init() throws Exception { @Test public void defaultRepo() { - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getName()).isEqualTo(this.defaultUri + "application.yml"); assertVersion(environment); @@ -65,7 +67,8 @@ public void defaultRepo() { @Test public void missingRepo() { - Environment environment = this.repository.findOne("missing-config-repo", "staging", "master"); + Environment environment = this.repository.findOne( + new RequestContext.Builder().name("missing-config-repo").profiles("staging").label("master").build()); assertThat(environment.getPropertySources().size()).as("Wrong property sources: " + environment).isEqualTo(1); assertThat(environment.getPropertySources().get(0).getName()).isEqualTo(this.defaultUri + "application.yml"); assertVersion(environment); @@ -73,7 +76,8 @@ public void missingRepo() { @Test public void defaultLabelRepo() { - Environment environment = this.repository.findOne("bar", "staging", null); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getName()).isEqualTo(this.defaultUri + "application.yml"); assertVersion(environment); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java index ae75a8f6cc..827e2c1462 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java @@ -30,6 +30,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository; import org.springframework.cloud.config.server.environment.SearchPathLocator.Locations; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.core.env.StandardEnvironment; import org.springframework.test.util.ReflectionTestUtils; @@ -85,7 +86,8 @@ private PatternMatchingJGitEnvironmentRepository createRepository(String name, S @Test public void defaultRepo() { - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -94,7 +96,8 @@ public void defaultRepo() { @Test public void mappingRepo() { - Environment environment = this.repository.findOne("application", "test1-config-repo", "master"); + Environment environment = this.repository.findOne( + new RequestContext.Builder().name("application").profiles("test1-config-repo").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); String uri = getUri("*").replace("{profile}", "test1-config-repo"); assertThat(environment.getPropertySources().get(0).getName()).isEqualTo(uri + "/application.yml"); @@ -104,7 +107,8 @@ public void mappingRepo() { @Test public void otherMappingRepo() { - Environment environment = this.repository.findOne("application", "test2-config-repo", "master"); + Environment environment = this.repository.findOne( + new RequestContext.Builder().name("application").profiles("test2-config-repo").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(getUri("*").replace("{profile}", "test2-config-repo") + "/application.properties"); @@ -113,8 +117,8 @@ public void otherMappingRepo() { @Test public void locationsTwoProfiles() throws Exception { - Locations locations = this.repository.getLocations("application", "test1-config-repo,test2-config-repo", - "master"); + Locations locations = this.repository.getLocations(new RequestContext.Builder().name("application") + .profiles("test1-config-repo,test2-config-repo").label("master").build()); assertThat(locations.getLocations().length).isEqualTo(1); assertThat(new File(locations.getLocations()[0].replace("file:", "")).getCanonicalPath()) .isEqualTo(new File(getUri("*").replace("{profile}", "test2-config-repo").replace("file:", "")) @@ -123,7 +127,8 @@ public void locationsTwoProfiles() throws Exception { @Test public void locationsMissingProfile() throws Exception { - Locations locations = this.repository.getLocations("application", "not-there,another-not-there", "master"); + Locations locations = this.repository.getLocations(new RequestContext.Builder().name("application") + .profiles("not-there,another-not-there").label("master").build()); assertThat(locations.getLocations().length).isEqualTo(1); assertThat(new File(locations.getLocations()[0].replace("file:", "")).getCanonicalPath()) .isEqualTo(new File(this.repository.getUri().replace("file:", "")).getCanonicalPath()); @@ -131,8 +136,8 @@ public void locationsMissingProfile() throws Exception { @Test public void twoMappingRepos() { - Environment environment = this.repository.findOne("application", - "test1-config-repo,test2-config-repo,missing-config-repo", "master"); + Environment environment = this.repository.findOne(new RequestContext.Builder().name("application") + .profiles("test1-config-repo,test2-config-repo,missing-config-repo").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(getUri("*").replace("{profile}", "test2-config-repo") + "/application.properties"); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java index 21e0123ea2..584f73f85f 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java @@ -37,6 +37,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.config.ConfigServerProperties; import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; @@ -82,7 +83,8 @@ public void defaultRepo() throws IOException { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); } @@ -97,7 +99,8 @@ public void mappingRepo() throws IOException { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).properties(repoMapping).run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("test1-svc", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("test1-svc").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); } @@ -113,7 +116,8 @@ public void mappingRepoWithRefreshRate() throws IOException { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).properties(repoMapping).run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("test1-svc", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("test1-svc").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(30) .isEqualTo(((MultipleJGitEnvironmentRepository) repository).getRepos().get("test1").getRefreshRate()); @@ -130,7 +134,8 @@ public void mappingRepoWithProfile() throws IOException { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).properties(repoMapping).run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("test1-svc", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("test1-svc").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); } @@ -145,7 +150,8 @@ public void mappingRepoWithProfileDefaultPatterns() throws IOException { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).properties(repoMapping).run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("test1-svc", "staging,cloud", "master"); + Environment environment = repository.findOne( + new RequestContext.Builder().name("test1-svc").profiles("staging,cloud").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); } @@ -162,9 +168,11 @@ public void mappingRepoWithProfiles() throws IOException { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).properties(repoMapping).run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("test1-svc", "cloud,staging", "master"); + Environment environment = repository.findOne( + new RequestContext.Builder().name("test1-svc").profiles("cloud,staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); - environment = repository.findOne("test1-svc", "staging,cloud", "master"); + environment = repository.findOne( + new RequestContext.Builder().name("test1-svc").profiles("staging,cloud").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); } @@ -178,7 +186,8 @@ public void mappingRepoWithJustUri() throws IOException { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).properties(repoMapping).run(); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("test1-svc", "staging", "master"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("test1-svc").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java index fd6016f74c..9301b146c6 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java @@ -34,6 +34,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.core.env.StandardEnvironment; @@ -90,7 +91,8 @@ private PatternMatchingJGitEnvironmentRepository createRepository(String name, S @Test public void defaultRepo() { - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -117,7 +119,8 @@ public void defaultRepoNested() throws IOException { String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo"); this.repository.setUri(uri); this.repository.setSearchPaths(new String[] { "sub" }); - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/sub/application.yml"); @@ -126,7 +129,8 @@ public void defaultRepoNested() throws IOException { @Test public void defaultRepoBranch() { - Environment environment = this.repository.findOne("bar", "staging", "raw"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("raw").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -135,7 +139,8 @@ public void defaultRepoBranch() { @Test public void defaultRepoTag() { - Environment environment = this.repository.findOne("bar", "staging", "foo"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("foo").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -144,7 +149,8 @@ public void defaultRepoTag() { @Test public void defaultRepoTwice() { - Environment environment = this.repository.findOne("bar", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(this.repository.getUri() + "/bar.properties"); @@ -160,7 +166,8 @@ public void defaultRepoBasedir() { @Test public void mappingRepo() { - Environment environment = this.repository.findOne("test1-svc", "staging", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("test1-svc").profiles("staging").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo(getUri("*test1*") + "/test1-svc.properties"); @@ -170,7 +177,8 @@ public void mappingRepo() { @Test public void defaultLabel() { this.repository.setDefaultLabel("raw"); - Environment environment = this.repository.findOne("bar", "staging", null); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").build()); assertThat(environment.getLabel()).isEqualTo("raw"); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) @@ -180,7 +188,8 @@ public void defaultLabel() { @Test public void mappingRepoWithDefaultLabel() { - Environment environment = this.repository.findOne("test1-svc", "staging", null); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("test1-svc").profiles("staging").build()); assertThat(environment.getLabel()).isEqualTo(JGitEnvironmentProperties.MAIN_LABEL); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getName()) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java index 13a2528ac2..dfb8d71d3a 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java @@ -29,6 +29,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.environment.SearchPathLocator.Locations; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.context.ConfigurableApplicationContext; import static org.assertj.core.api.Assertions.assertThat; @@ -59,13 +60,15 @@ public void init() { @Test public void emptySearchLocations() { this.repository.setSearchLocations((String[]) null); - Environment environment = this.repository.findOne("foo", "development", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("development").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); } @Test public void vanilla() { - Environment environment = this.repository.findOne("foo", "development", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("development").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getVersion()).as("version was wrong").isEqualTo("myversion"); } @@ -73,7 +76,8 @@ public void vanilla() { @Test public void ignoresExistingProfile() { System.setProperty("spring.profiles.active", "cloud"); - Environment environment = this.repository.findOne("foo", "main", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("main").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getVersion()).as("version was wrong").isEqualTo("myversion"); } @@ -81,7 +85,8 @@ public void ignoresExistingProfile() { @Test public void prefixed() { this.repository.setSearchLocations("classpath:/test"); - Environment environment = this.repository.findOne("foo", "development", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("development").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getVersion()).as("version was wrong").isEqualTo("myversion"); // gh-1778 property sources has the same name. @@ -92,7 +97,8 @@ public void prefixed() { @Test public void prefixedYaml() { this.repository.setSearchLocations("classpath:/test"); - Environment environment = this.repository.findOne("bar", "development", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("development").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getVersion()).as("version was wrong").isEqualTo("myversion"); // gh-1778 property sources has the same name. @@ -103,7 +109,8 @@ public void prefixedYaml() { @Test public void prefixedMultiDocProperties() { this.repository.setSearchLocations("classpath:/test"); - Environment environment = this.repository.findOne("baz", "development", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("baz").profiles("development").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getVersion()).as("version was wrong").isEqualTo("myversion"); // gh-1778 property sources has the same name. @@ -114,7 +121,8 @@ public void prefixedMultiDocProperties() { @Test public void prefixedWithFile() { this.repository.setSearchLocations("file:./src/test/resources/test"); - Environment environment = this.repository.findOne("foo", "development", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("development").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getVersion()).as("version was wrong").isEqualTo("myversion"); } @@ -153,7 +161,8 @@ public void cleanBoot241Classpath() { @Disabled // FIXME: configdata public void labelled() { this.repository.setSearchLocations("classpath:/test"); - Environment environment = this.repository.findOne("foo", "development", "dev", false); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("development").label("dev").build()); assertThat(environment.getPropertySources()).hasSize(3); // position 1 because it has higher precedence than anything except the // foo-development.properties @@ -164,7 +173,8 @@ public void labelled() { @Test public void placeholdersLabel() { this.repository.setSearchLocations("classpath:/test/{label}/"); - Environment environment = this.repository.findOne("foo", "development", "dev"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("development").label("dev").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("dev_bar"); } @@ -172,7 +182,8 @@ public void placeholdersLabel() { @Test public void placeholdersProfile() { this.repository.setSearchLocations("classpath:/test/{profile}/"); - Environment environment = this.repository.findOne("foo", "dev", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("dev").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("dev_bar"); } @@ -180,7 +191,8 @@ public void placeholdersProfile() { @Test public void placeholdersProfiles() { this.repository.setSearchLocations("classpath:/test/{profile}/"); - Environment environment = this.repository.findOne("foo", "dev,mysql", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("dev,mysql").label("master").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("mysql"); } @@ -188,7 +200,8 @@ public void placeholdersProfiles() { @Test public void placeholdersApplicationAndProfile() { this.repository.setSearchLocations("classpath:/test/{profile}/{application}/"); - Environment environment = this.repository.findOne("app", "dev", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("app").profiles("dev").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("app"); } @@ -197,7 +210,8 @@ public void placeholdersApplicationAndProfile() { public void placeholdersApplicationWithPrefixAndProfile() { this.repository.setSearchLocations("classpath:/test/{profile}/{application}/"); // gh-2259 application name starts with "application" - Environment environment = this.repository.findOne("applicationxyz", "dev", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("applicationxyz").profiles("dev").label("master").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("default-app"); } @@ -205,7 +219,8 @@ public void placeholdersApplicationWithPrefixAndProfile() { @Test public void locationPlaceholdersApplication() { this.repository.setSearchLocations("classpath:/test/{application}"); - Locations locations = this.repository.getLocations("foo", "dev", "master"); + Locations locations = this.repository + .getLocations(new RequestContext.Builder().name("foo").profiles("dev").label("master").build()); assertThat(locations.getLocations().length).isEqualTo(1); assertThat(locations.getLocations()[0]).isEqualTo("classpath:/test/foo/"); } @@ -213,7 +228,8 @@ public void locationPlaceholdersApplication() { @Test public void locationPlaceholdersMultipleApplication() { this.repository.setSearchLocations("classpath:/test/{application}"); - Locations locations = this.repository.getLocations("foo,bar", "dev", "master"); + Locations locations = this.repository + .getLocations(new RequestContext.Builder().name("foo,bar").profiles("dev").label("master").build()); assertThat(locations.getLocations().length).isEqualTo(2); assertThat(locations.getLocations()[0]).isEqualTo("classpath:/test/foo/"); assertThat(locations.getLocations()[1]).isEqualTo("classpath:/test/bar/"); @@ -222,7 +238,8 @@ public void locationPlaceholdersMultipleApplication() { @Test public void locationProfilesApplication() { this.repository.setSearchLocations("classpath:/test/{profile}"); - Locations locations = this.repository.getLocations("foo", "dev,one,two", "master"); + Locations locations = this.repository + .getLocations(new RequestContext.Builder().name("foo").profiles("dev,one,two").label("master").build()); assertThat(locations.getLocations().length).isEqualTo(3); assertThat(locations.getLocations()[0]).isEqualTo("classpath:/test/dev/"); } @@ -230,7 +247,8 @@ public void locationProfilesApplication() { @Test public void placeholdersNoTrailingSlash() { this.repository.setSearchLocations("classpath:/test/{label}"); - Environment environment = this.repository.findOne("foo", "development", "dev"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("development").label("dev").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("dev_bar"); } @@ -238,7 +256,8 @@ public void placeholdersNoTrailingSlash() { @Test public void locationAddLabelLocations() { this.repository.setSearchLocations("classpath:/test/dev/"); - Environment environment = this.repository.findOne("foo", "development", "ignore"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("development").label("ignore").build()); assertThat(environment.getPropertySources()).hasSize(2); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isNotEqualTo("dev_bar"); } @@ -246,7 +265,8 @@ public void locationAddLabelLocations() { @Test public void tryToStartReactive() { this.repository.setSearchLocations("classpath:/test/reactive/"); - Environment environment = this.repository.findOne("foo", "master", "default"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("master").label("default").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("reactive"); } @@ -255,7 +275,8 @@ public void tryToStartReactive() { public void locationDontAddLabelLocations() { this.repository.setSearchLocations("classpath:/test/dev/"); this.repository.setAddLabelLocations(false); - Environment environment = this.repository.findOne("foo", "development", "ignore"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("development").label("ignore").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("dev_bar"); } @@ -263,14 +284,16 @@ public void locationDontAddLabelLocations() { @Test public void locationNoDuplicates() { this.repository.setSearchLocations("classpath:/test/{profile}", "classpath:/test/dev"); - Locations locations = this.repository.getLocations("foo", "dev", null); + Locations locations = this.repository + .getLocations(new RequestContext.Builder().name("foo").profiles("dev").build()); assertThat(locations.getLocations().length).isEqualTo(1); } @Test public void testDefaultLabel() { this.repository.setDefaultLabel("test"); - Environment environment = this.repository.findOne("foo", "default", null); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("foo").profiles("default").build()); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("test_bar"); } @@ -304,7 +327,8 @@ public void testImportWithoutPrefix() { } private void testImport() { - Environment environment = this.repository.findOne("import", "default", "master"); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("import").profiles("default").label("master").build()); // TODO should be 4, bar.yml contains 2 yaml documents assertThat(environment.getPropertySources()).hasSize(3); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("imported"); @@ -316,7 +340,9 @@ public void duplicateYamlKeys() { this.repository.setSearchLocations("classpath:/test/bad-syntax"); NativeEnvironmentRepository repo = this.repository; assertThatExceptionOfType(FailedToConstructEnvironmentException.class) - .isThrownBy(() -> repo.findOne("foo", "master", "default")).withMessage( + .isThrownBy(() -> repo + .findOne(new RequestContext.Builder().name("foo").profiles("master").label("default").build())) + .withMessage( "Could not construct context for config=foo profile=master label=default includeOrigin=false; nested exception is while constructing a mapping\n" + " in 'reader', line 1, column 1:\n" + " key: value\n" + " ^\n" + "found duplicate key key\n" + " in 'reader', line 2, column 1:\n" + " key: value\n" diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/ObservationEnvironmentRepositoryWrapperTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/ObservationEnvironmentRepositoryWrapperTests.java index 93c55a24b0..e3ac357743 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/ObservationEnvironmentRepositoryWrapperTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/ObservationEnvironmentRepositoryWrapperTests.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.support.RequestContext; import static io.micrometer.observation.tck.TestObservationRegistryAssert.assertThat; @@ -34,7 +35,7 @@ void shouldCollectMetrics() { EnvironmentRepository delegate = new MyEnvRepo(); EnvironmentRepository wrapper = ObservationEnvironmentRepositoryWrapper.wrap(registry, delegate); - wrapper.findOne("foo", "bar", "baz"); + wrapper.findOne(new RequestContext.Builder().name("foo").profiles("bar").label("baz").build()); assertThat(registry).hasSingleObservationThat().hasNameEqualTo("spring.cloud.config.environment.find") .hasBeenStarted().hasBeenStopped().hasLowCardinalityKeyValue("spring.cloud.config.environment.class", @@ -48,7 +49,7 @@ void shouldCreateRootObservationForCompositeAndChildObservationsForDelegates() { EnvironmentRepository composite = new CompositeEnvironmentRepository(Arrays.asList(delegate), registry, true); EnvironmentRepository wrapper = ObservationEnvironmentRepositoryWrapper.wrap(registry, composite); - wrapper.findOne("foo", "bar", "baz"); + wrapper.findOne(new RequestContext.Builder().name("foo").profiles("bar").label("baz").build()); assertThat(registry).hasHandledContextsThatSatisfy(contexts -> { contexts.stream().filter(context -> context.getName().equals("spring.cloud.config.environment.find") @@ -72,7 +73,7 @@ private boolean contextExists(Observation.Context context, String tagName, Strin static class MyEnvRepo implements EnvironmentRepository { @Override - public Environment findOne(String application, String profile, String label) { + public Environment findOne(RequestContext ctx) { return new Environment("foo", "bar"); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepositoryTests.java index e0da56a15b..b14ba8c2a7 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepositoryTests.java @@ -25,6 +25,7 @@ import org.springframework.boot.env.OriginTrackedMapPropertySource; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; @@ -38,7 +39,8 @@ public void originTrackedPropertySourceWithoutOriginWorks() { mockEnvironment.getPropertySources().addFirst(new OriginTrackedMapPropertySource("myorigintrackedsource", Collections.singletonMap("keyNoOrigin", "valueNoOrigin"))); PassthruEnvironmentRepository repository = new PassthruEnvironmentRepository(mockEnvironment); - Environment environment = repository.findOne("testapp", "default", "master", true); + Environment environment = repository.findOne(new RequestContext.Builder().name("testapp").profiles("default") + .label("master").includeOrigin(true).build()); assertThat(environment).isNotNull(); List propertySources = environment.getPropertySources(); assertThat(propertySources).hasSize(2); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/RedisEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/RedisEnvironmentRepositoryIntegrationTests.java index e4203eca22..a176d67835 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/RedisEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/RedisEnvironmentRepositoryIntegrationTests.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.data.redis.core.BoundHashOperations; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.test.annotation.DirtiesContext; @@ -59,8 +60,8 @@ public void test() { bound.put("name", "foo"); bound.put("tag", "myapp"); - Environment env = new RedisEnvironmentRepository(redis, new RedisEnvironmentProperties()).findOne("foo", "bar", - ""); + Environment env = new RedisEnvironmentRepository(redis, new RedisEnvironmentProperties()) + .findOne(new RequestContext.Builder().name("foo").profiles("bar").label("").build()); assertThat(env.getName()).isEqualTo("foo"); assertThat(env.getPropertySources()).isNotEmpty(); assertThat(env.getPropertySources().get(0).getSource().get("tag")).isEqualTo("myapp"); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryIntegrationTests.java index 1c0a225789..84367fcbdb 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryIntegrationTests.java @@ -40,6 +40,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.config.ConfigServerProperties; import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; @@ -80,7 +81,8 @@ public void vanilla() throws Exception { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .profiles("subversion").run("--spring.cloud.config.server.svn.uri=" + uri); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "trunk"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("trunk").build()); assertThat(environment.getPropertySources()).hasSize(2); } @@ -90,10 +92,12 @@ public void update() throws Exception { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .profiles("subversion").run("--spring.cloud.config.server.svn.uri=" + uri); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "trunk"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("trunk").build()); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("bar"); updateRepoForUpdate(uri); - environment = repository.findOne("bar", "staging", "trunk"); + environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("trunk").build()); assertThat(environment.getPropertySources().get(0).getSource().get("foo")).isEqualTo("foo"); } @@ -131,7 +135,8 @@ public void invalidLabel() { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .profiles("subversion").run("--spring.cloud.config.server.svn.uri=" + uri); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "unknownlabel"); + Environment environment = repository.findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("unknownlabel").build()); assertThat(environment.getPropertySources()).isEmpty(); }).isInstanceOf(NoSuchLabelException.class); } @@ -142,7 +147,8 @@ public void branchLabel() throws Exception { this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE) .profiles("subversion").run("--spring.cloud.config.server.svn.uri=" + uri); EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); - Environment environment = repository.findOne("bar", "staging", "demobranch"); + Environment environment = repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("demobranch").build()); assertThat(environment.getPropertySources().get(0).getName()).contains("bar.properties"); assertThat(environment.getPropertySources()).hasSize(1); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryTests.java index c64c290606..f5be10d13e 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryTests.java @@ -29,6 +29,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.EnableConfigServer; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.StandardEnvironment; @@ -94,14 +95,16 @@ public void basedirWithSpace() throws Exception { @Test public void branch() { - Environment environment = this.repository.findOne("bar", "staging", "branches/demobranch"); + Environment environment = this.repository.findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("branches/demobranch").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getName()).contains("bar.properties"); } @Test public void branch_no_folder() { - Environment environment = this.repository.findOne("bar", "staging", "demobranch", false); + Environment environment = this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("demobranch").build()); assertThat(environment.getPropertySources()).hasSize(1); assertThat(environment.getPropertySources().get(0).getName()).contains("bar.properties"); } @@ -118,7 +121,8 @@ public void vanilla_with_update() { @Test public void invalidLabel() { Assertions.assertThatThrownBy(() -> { - Environment environment = this.repository.findOne("bar", "staging", "unknownlabel"); + Environment environment = this.repository.findOne( + new RequestContext.Builder().name("bar").profiles("staging").label("unknownlabel").build()); assertThat(environment.getPropertySources()).isEmpty(); }).isInstanceOf(NoSuchLabelException.class); } @@ -132,7 +136,8 @@ public void vanilla_with_update_after_repo_delete() throws IOException { } private Environment findOne() { - return this.repository.findOne("bar", "staging", "trunk"); + return this.repository + .findOne(new RequestContext.Builder().name("bar").profiles("staging").label("trunk").build()); } @EnableAutoConfiguration diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryIntegrationTests.java index db500296d0..2c1a58af1a 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryIntegrationTests.java @@ -31,6 +31,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.server.support.RequestContext; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -58,7 +59,8 @@ public void withSslValidation() throws Exception { withTokenProvider(request)); VaultEnvironmentRepository vaultEnvironmentRepository = vaultEnvironmentRepositoryFactory .build(withEnvironmentProperties(false)); - vaultEnvironmentRepository.findOne("application", "profile", "label"); + vaultEnvironmentRepository.findOne( + new RequestContext.Builder().name("application").profiles("profile").label("label").build()); }).hasCauseInstanceOf(SSLHandshakeException.class); } @@ -71,7 +73,8 @@ public void skipSslValidation() throws Exception { VaultEnvironmentRepository vaultEnvironmentRepository = vaultEnvironmentRepositoryFactory .build(withEnvironmentProperties(true)); - Environment actual = vaultEnvironmentRepository.findOne("application", "profile", "label"); + Environment actual = vaultEnvironmentRepository + .findOne(new RequestContext.Builder().name("application").profiles("profile").label("label").build()); assertThat(actual).isNotNull(); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryTests.java index 6e2f08d9ec..82c7dc9369 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryTests.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.ObjectProvider; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.VaultKvAccessStrategy.VaultResponse; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -85,7 +86,7 @@ public void testFindOneNoDefaultKey() { VaultEnvironmentRepository repo = new VaultEnvironmentRepository(mockHttpRequest(), new EnvironmentWatch.Default(), rest, new VaultEnvironmentProperties(), mockTokenProvider()); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources().size()).as( "Properties for specified application and default application with key 'application' should be returned") @@ -130,7 +131,7 @@ public void testBackendWithSlashes() { VaultEnvironmentRepository repo = new VaultEnvironmentRepository(mockHttpRequest(), new EnvironmentWatch.Default(), rest, properties, mockTokenProvider()); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources().size()).as( "Properties for specified application and default application with key 'application' should be returned") @@ -173,7 +174,7 @@ public void testFindOneDefaultKeySetAndDifferentToApplication() { new EnvironmentWatch.Default(), rest, new VaultEnvironmentProperties(), mockTokenProvider()); repo.setDefaultKey("mydefaultkey"); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources().size()).as( "Properties for specified application and default application with key 'mydefaultkey' should be returned") @@ -225,7 +226,7 @@ public void testFindOneDefaultKeySetAndDifferentToMultipleApplications() { new EnvironmentWatch.Default(), rest, new VaultEnvironmentProperties(), mockTokenProvider()); repo.setDefaultKey("mydefaultkey"); - Environment e = repo.findOne("myapp,yourapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp,yourapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp,yourapp"); assertThat(e.getPropertySources().size()).as( "Properties for specified applications and default application with key 'mydefaultkey' should be returned") @@ -275,7 +276,7 @@ public void testFindOneDefaultKeySetAndEqualToApplication() { new EnvironmentWatch.Default(), rest, new VaultEnvironmentProperties(), mockTokenProvider()); repo.setDefaultKey("myapp"); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources().size()).as("Only properties for specified application should be returned") .isEqualTo(1); @@ -295,7 +296,7 @@ public void missingConfigToken() { VaultEnvironmentRepository repo = new VaultEnvironmentRepository(mockHttpRequest(), new EnvironmentWatch.Default(), mock(RestTemplate.class), new VaultEnvironmentProperties(), tokenProvider); - repo.findOne("myapp", null, null); + repo.findOne(new RequestContext.Builder().name("myapp").build()); }).isInstanceOf(IllegalArgumentException.class); } @@ -323,7 +324,7 @@ public void testVaultVersioning() { VaultEnvironmentRepository repo = new VaultEnvironmentRepository(mockHttpRequest(), new EnvironmentWatch.Default(), rest, vaultEnvironmentProperties, mockTokenProvider()); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources().size()).as( "Properties for specified application and default application with key 'application' should be returned") @@ -360,7 +361,7 @@ public void testVaultKV2WithPath2Key() { VaultEnvironmentRepository repo = new VaultEnvironmentRepository(mockHttpRequest(), new EnvironmentWatch.Default(), rest, vaultEnvironmentProperties, mockTokenProvider()); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources().size()).as( "Properties for specified application and default application with key 'application' should be returned") @@ -401,7 +402,7 @@ public void testNamespaceHeaderSent() { TestAccessStrategy accessStrategy = new TestAccessStrategy(rest, properties); repo.setAccessStrategy(accessStrategy); - repo.findOne("myapp", null, null); + repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(accessStrategy.headers).containsEntry(VaultEnvironmentRepository.VAULT_NAMESPACE, Collections.singletonList("mynamespace")); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryTests.java index 747604491e..4ac2bb795e 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryTests.java @@ -26,6 +26,7 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.environment.EnvironmentWatch; import org.springframework.cloud.config.server.environment.VaultEnvironmentProperties; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.util.StringUtils; import org.springframework.vault.core.VaultKeyValueOperations; import org.springframework.vault.support.VaultResponse; @@ -75,7 +76,7 @@ private void defaultKeyTest(String myPathKey, int version) { SpringVaultEnvironmentRepository repo = new SpringVaultEnvironmentRepository(mockHttpRequest(), new EnvironmentWatch.Default(), properties, keyValueTemplate); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources()).as( "Properties for specified application and default application with key 'application' should be returned") @@ -101,7 +102,7 @@ public void testBackendWithSlashes() { SpringVaultEnvironmentRepository repo = new SpringVaultEnvironmentRepository(mockHttpRequest(), new EnvironmentWatch.Default(), properties, keyValueTemplate); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources()).as( "Properties for specified application and default application with key 'application' should be returned") @@ -125,7 +126,7 @@ public void testFindOneDefaultKeySetAndDifferentToApplication() { new EnvironmentWatch.Default(), new VaultEnvironmentProperties(), keyValueTemplate); repo.setDefaultKey("mydefaultkey"); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources()).as( "Properties for specified application and default application with key 'mydefaultkey' should be returned") @@ -150,7 +151,7 @@ public void testFindOneDefaultKeySetAndDifferentToMultipleApplications() { new EnvironmentWatch.Default(), new VaultEnvironmentProperties(), keyValueTemplate); repo.setDefaultKey("mydefaultkey"); - Environment e = repo.findOne("myapp,yourapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp,yourapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp,yourapp"); assertThat(e.getPropertySources()).as( "Properties for specified applications and default application with key 'mydefaultkey' should be returned") @@ -179,7 +180,7 @@ public void testFindOneDefaultKeySetAndEqualToApplication() { new EnvironmentWatch.Default(), new VaultEnvironmentProperties(), keyValueTemplate); repo.setDefaultKey("myapp"); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources()).as("Only properties for specified application should be returned") .hasSize(1); @@ -200,7 +201,7 @@ public void testVaultVersioning() { SpringVaultEnvironmentRepository repo = new SpringVaultEnvironmentRepository(mockHttpRequest(), new EnvironmentWatch.Default(), vaultEnvironmentProperties, keyValueTemplate); - Environment e = repo.findOne("myapp", null, null); + Environment e = repo.findOne(new RequestContext.Builder().name("myapp").build()); assertThat(e.getName()).as("Name should be the same as the application argument").isEqualTo("myapp"); assertThat(e.getPropertySources()).as( "Properties for specified application and default application with key 'application' should be returned") diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/GenericResourceRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/GenericResourceRepositoryTests.java index 68dc000399..df25233fd3 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/GenericResourceRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/GenericResourceRepositoryTests.java @@ -36,6 +36,7 @@ import org.springframework.cloud.config.server.environment.NativeEnvironmentProperties; import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository; import org.springframework.cloud.config.server.environment.NativeEnvironmentRepositoryTests; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; @@ -80,33 +81,41 @@ public void init() { @Test public void locateResource() { - assertThat(this.repository.findOne("blah", "default", "master", "foo.properties")).isNotNull(); + RequestContext ctx = new RequestContext.Builder().name("blah").profiles("default").label("master") + .path("foo.properties").build(); + assertThat(this.repository.findOne(ctx)).isNotNull(); } @Test public void locateProfiledResource() { - assertThat(this.repository.findOne("blah", "local", "master", "foo.txt")).isNotNull(); + RequestContext ctx = new RequestContext.Builder().name("blah").profiles("local").label("master").path("foo.txt") + .build(); + assertThat(this.repository.findOne(ctx)).isNotNull(); } @Test public void locateProfiledResourceWithPlaceholder() { this.nativeRepository.setSearchLocations("classpath:/test/{profile}"); - assertThat(this.repository.findOne("blah", "local", "master", "foo.txt")).isNotNull(); + RequestContext ctx = new RequestContext.Builder().name("blah").profiles("local").label("master").path("foo.txt") + .build(); + assertThat(this.repository.findOne(ctx)).isNotNull(); } @Test public void locateMissingResource() { - Assertions - .assertThatThrownBy( - () -> assertThat(this.repository.findOne("blah", "default", "master", "foo.txt")).isNotNull()) + RequestContext ctx = new RequestContext.Builder().name("blah").profiles("default").label("master") + .path("foo.txt").build(); + Assertions.assertThatThrownBy(() -> assertThat(this.repository.findOne(ctx)).isNotNull()) .isInstanceOf(NoSuchResourceException.class); } @Test public void invalidPath(CapturedOutput capturedOutput) { + RequestContext ctx = new RequestContext.Builder().name("blah").profiles("local").label("master") + .path("..%2F..%2Fdata-jdbc.sql").build(); Assertions.assertThatThrownBy(() -> { this.nativeRepository.setSearchLocations("file:./src/test/resources/test/{profile}"); - this.repository.findOne("blah", "local", "master", "..%2F..%2Fdata-jdbc.sql"); + this.repository.findOne(ctx); }).isInstanceOf(NoSuchResourceException.class); Assertions.assertThat(capturedOutput.getAll()) .contains("Path contains \"../\" after call to StringUtils#cleanPath"); @@ -134,7 +143,8 @@ public void invalidPathEncodedSlash(CapturedOutput capturedOutput) { file = file.replaceFirst("\\/", "%2f"); file += "/src/test/resources/ssh/key"; this.nativeRepository.setSearchLocations("file:./"); - this.repository.findOne("blah", "local", "master", file); + this.repository.findOne( + new RequestContext.Builder().name("blah").profiles("local").label("master").path(file).build()); }).isInstanceOf(NoSuchResourceException.class); Assertions.assertThat(capturedOutput.getAll()).contains("is neither under the current location"); } @@ -142,7 +152,8 @@ public void invalidPathEncodedSlash(CapturedOutput capturedOutput) { private void testInvalidPath(String label, CapturedOutput capturedOutput) { Assertions.assertThatThrownBy(() -> { this.nativeRepository.setSearchLocations("file:./src/test/resources/test/local"); - this.repository.findOne("blah", "local", label, "foo.properties"); + this.repository.findOne(new RequestContext.Builder().name("blah").profiles("local").label(label) + .path("foo.properties").build()); }).isInstanceOf(NoSuchResourceException.class); Assertions.assertThat(capturedOutput.getAll()).contains("Location contains \"..\""); } @@ -185,7 +196,9 @@ public ClassLoader getClassLoader() { } }); - Resource resource = genericResourceRepository.findOne("app", "default", "main", "data.json"); + RequestContext ctx = new RequestContext.Builder().name("app").profiles("default").label("main") + .path("data.json").build(); + Resource resource = genericResourceRepository.findOne(ctx); assertThat(resource.getURL()).isEqualTo(new URL("https://us-east-1/test/main%2Fdata.json")); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerIntegrationTests.java index e9056f4728..50a9fc48a3 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerIntegrationTests.java @@ -35,6 +35,7 @@ import org.springframework.cloud.config.server.environment.EnvironmentRepository; import org.springframework.cloud.config.server.environment.NoSuchLabelException; import org.springframework.cloud.config.server.resource.ResourceControllerIntegrationTests.ControllerConfiguration; +import org.springframework.cloud.config.server.support.RequestContext; import org.springframework.context.annotation.Bean; import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpHeaders; @@ -84,94 +85,98 @@ public void init() { @Test public void environmentNoLabel() throws Exception { - when(this.repository.findOne("foo", "default", "master", false)).thenReturn(new Environment("foo", "default")); - when(this.resources.findOne("foo", "default", "master", "foo.txt")) - .thenReturn(new ClassPathResource("resource-controller/foo.txt")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("master") + .path("foo.txt").resolvePlaceholders(true).build(); + when(this.repository.findOne(ctx)).thenReturn(new Environment("foo", "default")); + when(this.resources.findOne(ctx)).thenReturn(new ClassPathResource("resource-controller/foo.txt")); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/master/foo.txt")) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", "default", "master", false); - verify(this.resources).findOne("foo", "default", "master", "foo.txt"); + verify(this.repository).findOne(ctx); + verify(this.resources).findOne(ctx); } @Test public void resource() throws Exception { - when(this.repository.findOne("foo", "default", "master", false)) - .thenReturn(new Environment("foo", "default", "master")); - when(this.resources.findOne("foo", "default", "master", "foo.txt")) - .thenReturn(new ClassPathResource("resource-controller/foo.txt")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("master") + .path("foo.txt").resolvePlaceholders(true).build(); + when(this.repository.findOne(ctx)).thenReturn(new Environment("foo", "default", "master")); + when(this.resources.findOne(ctx)).thenReturn(new ClassPathResource("resource-controller/foo.txt")); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/master/foo.txt")) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", "default", "master", false); - verify(this.resources).findOne("foo", "default", "master", "foo.txt"); + verify(this.repository).findOne(ctx); + verify(this.resources).findOne(ctx); } @Test public void resourceHttp() throws Exception { - when(this.repository.findOne("foo", "default", "master", false)) - .thenReturn(new Environment("foo", "default", "master")); - when(this.resources.findOne("foo", "default", "master", "foo.txt")) - .thenReturn(new ClassPathResource("resource-controller/foo.txt")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("master") + .path("foo.txt").resolvePlaceholders(true).build(); + when(this.repository.findOne(ctx)).thenReturn(new Environment("foo", "default", "master")); + when(this.resources.findOne(ctx)).thenReturn(new ClassPathResource("resource-controller/foo.txt")); ResponseEntity response = new TestRestTemplate() .getForEntity("http://localhost:" + port + "/foo/default/master/foo.txt", String.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - verify(this.repository).findOne("foo", "default", "master", false); - verify(this.resources).findOne("foo", "default", "master", "foo.txt"); + verify(this.repository).findOne(ctx); + verify(this.resources).findOne(ctx); } @Test public void resourceHttpDoesNotExist() throws Exception { - when(this.resources.findOne("foo", "default", "master", "doesNotExist.txt")) - .thenThrow(new NoSuchResourceException("Does not exist")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("master") + .path("doesNotExist.txt").resolvePlaceholders(true).build(); + when(this.resources.findOne(ctx)).thenThrow(new NoSuchResourceException("Does not exist")); ResponseEntity response = new TestRestTemplate() .getForEntity("http://localhost:" + port + "/foo/default/master/doesNotExist.txt", String.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - verify(this.resources).findOne("foo", "default", "master", "doesNotExist.txt"); + verify(this.resources).findOne(ctx); } @Test public void resourceNoLabel() throws Exception { - when(this.repository.findOne("foo", "default", null, false)) - .thenReturn(new Environment("foo", "default", "master")); - when(this.resources.findOne("foo", "default", null, "foo.txt")) - .thenReturn(new ClassPathResource("resource-controller/foo.txt")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label(null).path("foo.txt") + .resolvePlaceholders(true).build(); + when(this.repository.findOne(ctx)).thenReturn(new Environment("foo", "default", "master")); + when(this.resources.findOne(ctx)).thenReturn(new ClassPathResource("resource-controller/foo.txt")); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/foo.txt").param("useDefaultLabel", "")) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", "default", null, false); - verify(this.resources).findOne("foo", "default", null, "foo.txt"); + verify(this.repository).findOne(ctx); + verify(this.resources).findOne(ctx); } @Test public void resourceNoLabelHttp() throws Exception { - when(this.repository.findOne("foo", "default", null, false)) - .thenReturn(new Environment("foo", "default", "master")); - when(this.resources.findOne("foo", "default", null, "foo.txt")) - .thenReturn(new ClassPathResource("resource-controller/foo.txt")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label(null).path("foo.txt") + .resolvePlaceholders(true).build(); + when(this.repository.findOne(ctx)).thenReturn(new Environment("foo", "default", "master")); + when(this.resources.findOne(ctx)).thenReturn(new ClassPathResource("resource-controller/foo.txt")); ResponseEntity response = new TestRestTemplate() .getForEntity("http://localhost:" + port + "/foo/default/foo.txt?useDefaultLabel", String.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - verify(this.repository).findOne("foo", "default", null, false); - verify(this.resources).findOne("foo", "default", null, "foo.txt"); + verify(this.repository).findOne(ctx); + verify(this.resources).findOne(ctx); } @Test public void binaryResourceNoLabel() throws Exception { - when(this.repository.findOne("foo", "default", null)).thenReturn(new Environment("foo", "default", "master")); - when(this.resources.findOne("foo", "default", null, "foo.txt")) - .thenReturn(new ClassPathResource("resource-controller/foo.txt")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label(null).path("foo.txt") + .build(); + when(this.repository.findOne(ctx)).thenReturn(new Environment("foo", "default", "master")); + when(this.resources.findOne(ctx)).thenReturn(new ClassPathResource("resource-controller/foo.txt")); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/foo.txt").param("useDefaultLabel", "") .header(HttpHeaders.ACCEPT, MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE)) .andExpect(MockMvcResultMatchers.status().isOk()); - verify(this.repository).findOne("foo", "default", null); - verify(this.resources).findOne("foo", "default", null, "foo.txt"); + verify(this.repository).findOne(ctx); + verify(this.resources).findOne(ctx); } @Test public void resourceWithMissingLabel() throws Exception { - when(this.resources.findOne("foo", "default", "missing", "foo.txt")) - .thenThrow(new NoSuchLabelException("Planned")); + RequestContext ctx = new RequestContext.Builder().name("foo").profiles("default").label("missing") + .path("foo.txt").resolvePlaceholders(true).build(); + when(this.resources.findOne(ctx)).thenThrow(new NoSuchLabelException("Planned")); this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/missing/foo.txt")) .andExpect(MockMvcResultMatchers.status().isNotFound()); }