/** * Add the properties from the underlying map to the environment using the specified * property source type. * @param environment the environment that needs to be modified * @param type the type of {@link PropertySource} to be added. See {@link Type} */ public void applyTo(ConfigurableEnvironment environment, Type type) { applyTo(environment, type, type.applySuffix("test")); }
/** * Add the properties from the underlying map to the environment. The default property * source used is {@link MapPropertySource}. * @param environment the environment that needs to be modified */ public void applyTo(ConfigurableEnvironment environment) { applyTo(environment, Type.MAP); }
/** * Return a new {@link TestPropertyValues} with the underlying map populated with the * given property pairs. Name-value pairs can be specified with colon (":") or equals * ("=") separators. * @param pairs the name-value pairs for properties that need to be added to the * environment * @return the new instance */ public static TestPropertyValues of(String... pairs) { return of(Stream.of(pairs)); }
private void load(Class<?>[] configs, String... environment) { this.context.register(configs); EnvironmentTestUtils.addEnvironment(this.context, environment); this.context.refresh(); }
/** * Builder method to add more properties. * @param pairs the property pairs to add * @return a new {@link TestPropertyValues} instance */ public TestPropertyValues and(String... pairs) { return and(Arrays.stream(pairs).map(Pair::parse)); }
/** * Return a new {@link TestPropertyValues} with the underlying map populated with the * given property pairs. Name-value pairs can be specified with colon (":") or equals * ("=") separators. * @param pairs the name-value pairs for properties that need to be added to the * environment * @return the new instance */ public static TestPropertyValues of(Stream<String> pairs) { if (pairs == null) { return empty(); } return empty().and(pairs.map(Pair::parse)); }
private TestPropertyValues and(Stream<Pair> pairs) { Map<String, Object> properties = new LinkedHashMap<>(this.properties); pairs.filter(Objects::nonNull).forEach((pair) -> pair.addTo(properties)); return new TestPropertyValues(properties); }
/** * Add the properties to the {@link System#getProperties() system properties} for the * duration of the {@code call}, restoring previous values when the call completes. * @param <T> the result type * @param call the call to make * @return the result of the call */ public <T> T applyToSystemProperties(Callable<T> call) { try (SystemPropertiesHandler handler = new SystemPropertiesHandler()) { return call.call(); } catch (Exception ex) { rethrow(ex); throw new IllegalStateException("Original cause not rethrown", ex); } }
public static Pair parse(String pair) { int index = getSeparatorIndex(pair); String name = (index > 0) ? pair.substring(0, index) : pair; String value = (index > 0) ? pair.substring(index + 1) : ""; return of(name.trim(), value.trim()); }
SystemPropertiesHandler() { this.previous = apply(TestPropertyValues.this.properties); }
/** * Create a new {@link AbstractApplicationContextRunner} instance. * @param contextFactory the factory used to create the actual context */ protected AbstractApplicationContextRunner(Supplier<C> contextFactory) { this(contextFactory, Collections.emptyList(), TestPropertyValues.empty(), TestPropertyValues.empty(), null, null, Collections.emptyList()); }
private static Pair of(String name, String value) { if (StringUtils.isEmpty(name) && StringUtils.isEmpty(value)) { return null; } return new Pair(name, value); }
/** * Add the properties from the underlying map to the environment owned by an * {@link ApplicationContext}. * @param context the context with an environment to modify */ public void applyTo(ConfigurableApplicationContext context) { applyTo(context.getEnvironment()); }
private void load(Class<?> config, String... environment) { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(applicationContext, environment); applicationContext.register(config); applicationContext.register(Web3jAutoConfiguration.class); applicationContext.refresh(); this.context = applicationContext; }
/** * Add the specified {@link Environment} property pairs. Key-value pairs can be * specified with colon (":") or equals ("=") separators. Override matching keys that * might have been specified previously. * @param pairs the key-value pairs for properties that need to be added to the * environment * @return a new instance with the updated property values * @see TestPropertyValues * @see #withSystemProperties(String...) */ public SELF withPropertyValues(String... pairs) { return newInstance(this.contextFactory, this.initializers, this.environmentProperties.and(pairs), this.systemProperties, this.classLoader, this.parent, this.configurations); }
private void loadContext(Class<?> configuration, String... environment) { EnvironmentTestUtils.addEnvironment(applicationContext, environment); applicationContext.register(configuration); applicationContext.register(MemcachedCacheAutoConfiguration.class); applicationContext.register(CacheAutoConfiguration.class); applicationContext.refresh(); }
/** * Add the specified {@link System} property pairs. Key-value pairs can be specified * with colon (":") or equals ("=") separators. System properties are added before the * context is {@link #run(ContextConsumer) run} and restored when the context is * closed. * @param pairs the key-value pairs for properties that need to be added to the system * @return a new instance with the updated system properties * @see TestPropertyValues * @see #withSystemProperties(String...) */ public SELF withSystemProperties(String... pairs) { return newInstance(this.contextFactory, this.initializers, this.environmentProperties, this.systemProperties.and(pairs), this.classLoader, this.parent, this.configurations); }
private void loadContext(Class<?> configuration, String... environment) { EnvironmentTestUtils.addEnvironment(context, environment); context.register(configuration); context.register(MemcachedCacheAutoConfiguration.class); context.register(CacheAutoConfiguration.class); context.register(MemcachedCacheStatisticsAutoConfiguration.class); context.refresh(); }