@Override public boolean containsProperty(String key) { if (this.propertySources != null) { for (PropertySource<?> propertySource : this.propertySources) { if (propertySource.containsProperty(key)) { return true; } } } return false; }
@Override public boolean containsProperty(String name) { for (PropertySource<?> propertySource : this.propertySources) { if (propertySource.containsProperty(name)) { return true; } } return false; }
@Override public boolean containsProperty(String key) { if (this.propertySources != null) { for (PropertySource<?> propertySource : this.propertySources) { if (propertySource.containsProperty(key)) { return true; } } } return false; }
@Override public boolean containsProperty(String name) { for (PropertySource<?> propertySource : this.propertySources) { if (propertySource.containsProperty(name)) { return true; } } return false; }
private List<Descriptor> getDescriptors(String propertyName) { return getPropertySources() .filter((source) -> source.containsProperty(propertyName)) .map((source) -> Descriptor.get(source, propertyName)) .collect(Collectors.toList()); }
@Override public boolean containsProperty(String name) { if ("LOGGING_CONFIG".equals(name)) { return true; } else { return super.containsProperty(name); } }
@Test public void withUnderscore() { envMap.put("a_key", "a_value"); assertThat(ps.containsProperty("a_key"), equalTo(true)); assertThat(ps.containsProperty("a.key"), equalTo(true)); assertThat(ps.getProperty("a_key"), equalTo((Object)"a_value")); assertThat( ps.getProperty("a.key"), equalTo((Object)"a_value")); }
@Test public void normalWithoutPeriod() { envMap.put("akey", "avalue"); assertThat(ps.containsProperty("akey"), equalTo(true)); assertThat(ps.getProperty("akey"), equalTo((Object)"avalue")); }
@Test public void normalWithPeriod() { envMap.put("a.key", "a.value"); assertThat(ps.containsProperty("a.key"), equalTo(true)); assertThat(ps.getProperty("a.key"), equalTo((Object)"a.value")); }
/** * Creates {@link RedisSentinelConfiguration} looking up values in given {@link PropertySource}. * * <pre> * <code> * spring.redis.sentinel.master=myMaster * spring.redis.sentinel.nodes=127.0.0.1:23679,127.0.0.1:23680,127.0.0.1:23681 * </code> * </pre> * * @param propertySource must not be {@literal null}. * @since 1.5 */ public RedisSentinelConfiguration(PropertySource<?> propertySource) { notNull(propertySource, "PropertySource must not be null!"); this.sentinels = new LinkedHashSet<>(); if (propertySource.containsProperty(REDIS_SENTINEL_MASTER_CONFIG_PROPERTY)) { this.setMaster(propertySource.getProperty(REDIS_SENTINEL_MASTER_CONFIG_PROPERTY).toString()); } if (propertySource.containsProperty(REDIS_SENTINEL_NODES_CONFIG_PROPERTY)) { appendSentinels( commaDelimitedListToSet(propertySource.getProperty(REDIS_SENTINEL_NODES_CONFIG_PROPERTY).toString())); } }
/** * Creates {@link RedisClusterConfiguration} looking up values in given {@link PropertySource}. * * <pre> * <code> * spring.redis.cluster.nodes=127.0.0.1:23679,127.0.0.1:23680,127.0.0.1:23681 * spring.redis.cluster.max-redirects=3 * </code> * </pre> * * @param propertySource must not be {@literal null}. */ public RedisClusterConfiguration(PropertySource<?> propertySource) { notNull(propertySource, "PropertySource must not be null!"); this.clusterNodes = new LinkedHashSet<>(); if (propertySource.containsProperty(REDIS_CLUSTER_NODES_CONFIG_PROPERTY)) { appendClusterNodes( commaDelimitedListToSet(propertySource.getProperty(REDIS_CLUSTER_NODES_CONFIG_PROPERTY).toString())); } if (propertySource.containsProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY)) { this.maxRedirects = NumberUtils.parseNumber( propertySource.getProperty(REDIS_CLUSTER_MAX_REDIRECTS_CONFIG_PROPERTY).toString(), Integer.class); } }
@Test public void none() { assertThat(ps.containsProperty("a.key"), equalTo(false)); assertThat(ps.getProperty("a.key"), equalTo(null)); }
@Test public void withDefaultNonOptionArgsNameAndNonOptionArgsPresent() { OptionParser parser = new OptionParser(); parser.accepts("o1").withRequiredArg(); parser.accepts("o2"); OptionSet optionSet = parser.parse("--o1=v1", "noa1", "--o2", "noa2"); PropertySource<?> ps = new JOptCommandLinePropertySource(optionSet); assertThat(ps.containsProperty("nonOptionArgs"), is(true)); assertThat(ps.containsProperty("o1"), is(true)); assertThat(ps.containsProperty("o2"), is(true)); String nonOptionArgs = (String)ps.getProperty("nonOptionArgs"); assertThat(nonOptionArgs, equalTo("noa1,noa2")); }
@Test public void withNoArgs() { PropertySource<?> ps = new SimpleCommandLinePropertySource(); assertThat(ps.containsProperty("foo"), is(false)); assertThat(ps.getProperty("foo"), nullValue()); }
@Test @SuppressWarnings("serial") public void withSecurityConstraints() throws Exception { envMap = new HashMap<String, Object>() { @Override public boolean containsKey(Object key) { throw new UnsupportedOperationException(); } @Override public Set<String> keySet() { return new HashSet<>(super.keySet()); } }; envMap.put("A_KEY", "a_value"); ps = new SystemEnvironmentPropertySource("sysEnv", envMap) { @Override protected boolean isSecurityManagerPresent() { return true; } }; assertThat(ps.containsProperty("A_KEY"), equalTo(true)); assertThat(ps.getProperty("A_KEY"), equalTo((Object)"a_value")); }
@Test public void withNoArg() { OptionParser parser = new OptionParser(); parser.accepts("o1"); parser.accepts("o2"); OptionSet options = parser.parse("--o1"); PropertySource<?> ps = new JOptCommandLinePropertySource(options); assertThat(ps.containsProperty("o1"), is(true)); assertThat(ps.containsProperty("o2"), is(false)); assertThat((String)ps.getProperty("o1"), equalTo("")); assertThat(ps.getProperty("o2"), nullValue()); }
envMap.put("A_HYPHEN-KEY", "a_hyphen_value"); assertThat(ps.containsProperty("A_KEY"), equalTo(true)); assertThat(ps.containsProperty("A.KEY"), equalTo(true)); assertThat(ps.containsProperty("A-KEY"), equalTo(true)); assertThat(ps.containsProperty("a_key"), equalTo(true)); assertThat(ps.containsProperty("a.key"), equalTo(true)); assertThat(ps.containsProperty("a-key"), equalTo(true)); assertThat(ps.containsProperty("A_LONG_KEY"), equalTo(true)); assertThat(ps.containsProperty("A.LONG.KEY"), equalTo(true)); assertThat(ps.containsProperty("A-LONG-KEY"), equalTo(true)); assertThat(ps.containsProperty("A.LONG-KEY"), equalTo(true)); assertThat(ps.containsProperty("A-LONG.KEY"), equalTo(true)); assertThat(ps.containsProperty("A_long_KEY"), equalTo(true)); assertThat(ps.containsProperty("A.long.KEY"), equalTo(true)); assertThat(ps.containsProperty("A-long-KEY"), equalTo(true)); assertThat(ps.containsProperty("A.long-KEY"), equalTo(true)); assertThat(ps.containsProperty("A-long.KEY"), equalTo(true)); assertThat(ps.containsProperty("A_DOT.KEY"), equalTo(true)); assertThat(ps.containsProperty("A-DOT.KEY"), equalTo(true)); assertThat(ps.containsProperty("A_dot.KEY"), equalTo(true)); assertThat(ps.containsProperty("A-dot.KEY"), equalTo(true)); assertThat(ps.containsProperty("A_HYPHEN-KEY"), equalTo(true)); assertThat(ps.containsProperty("A.HYPHEN-KEY"), equalTo(true)); assertThat(ps.containsProperty("A_hyphen-KEY"), equalTo(true)); assertThat(ps.containsProperty("A.hyphen-KEY"), equalTo(true));
@Test public void withOptionalArg_andArgIsMissing() { OptionParser parser = new OptionParser(); parser.accepts("foo").withOptionalArg(); OptionSet options = parser.parse("--foo"); PropertySource<?> ps = new JOptCommandLinePropertySource(options); assertThat(ps.containsProperty("foo"), is(true)); assertThat((String)ps.getProperty("foo"), equalTo("")); }
private Map<String, PropertyValueDescriptor> getPropertySourceDescriptors( String propertyName) { Map<String, PropertyValueDescriptor> propertySources = new LinkedHashMap<>(); PlaceholdersResolver resolver = getResolver(); getPropertySourcesAsMap().forEach((sourceName, source) -> propertySources .put(sourceName, source.containsProperty(propertyName) ? describeValueOf(propertyName, source, resolver) : null)); return propertySources; }
private void mergeDefaultProperties(MutablePropertySources environment, MutablePropertySources bootstrap) { String name = DEFAULT_PROPERTIES; if (bootstrap.contains(name)) { PropertySource<?> source = bootstrap.get(name); if (!environment.contains(name)) { environment.addLast(source); } else { PropertySource<?> target = environment.get(name); if (target instanceof MapPropertySource) { Map<String, Object> targetMap = ((MapPropertySource) target) .getSource(); if (target != source) { if (source instanceof MapPropertySource) { Map<String, Object> map = ((MapPropertySource) source) .getSource(); for (String key : map.keySet()) { if (!target.containsProperty(key)) { targetMap.put(key, map.get(key)); } } } } } } } mergeAdditionalPropertySources(environment, bootstrap); }