Commit ce1e41dc authored by Stephane Nicoll's avatar Stephane Nicoll

Remove deprecated code

This code removes code deprecated in 1.4 with the exception of code that
requires an update to Spring Framework 5.

Closes gh-6971
parent d514cc3d
......@@ -197,11 +197,6 @@ public class ManagementServerProperties implements SecurityPrerequisite {
this.roles = roles;
}
@Deprecated
public void setRole(String role) {
this.roles = Collections.singletonList(role);
}
public List<String> getRoles() {
return this.roles;
}
......
......@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.endpoint;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
......@@ -50,17 +49,6 @@ public class InfoEndpoint extends AbstractEndpoint<Map<String, Object>> {
this.infoContributors = infoContributors;
}
/**
* Constructor provided for backward compatibility.
* @param info a map (which is added to the info)
* @param infoContributors the info contributors to use
* @deprecated as of 1.4 in favor of {@link #InfoEndpoint(List)}
*/
@Deprecated
public InfoEndpoint(Map<String, Object> info, InfoContributor... infoContributors) {
this(createContributors(info, infoContributors));
}
private static List<InfoContributor> createContributors(Map<String, Object> info,
InfoContributor[] infoContributors) {
List<InfoContributor> result = new ArrayList<InfoContributor>(
......@@ -75,20 +63,8 @@ public class InfoEndpoint extends AbstractEndpoint<Map<String, Object>> {
for (InfoContributor contributor : this.infoContributors) {
contributor.contribute(builder);
}
builder.withDetails(getAdditionalInfo());
Info build = builder.build();
return build.getDetails();
}
/**
* Return additional information to include in the output.
* @return additional information
* @deprecated as of 1.4 in favor of defining an additional {@link InfoContributor}
* bean.
*/
@Deprecated
protected Map<String, Object> getAdditionalInfo() {
return Collections.emptyMap();
}
}
/*
* Copyright 2012-2015 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
*
* http://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.boot.actuate.system;
import java.io.File;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;
/**
* An {@link ApplicationListener} that saves application PID into file. This application
* listener will be triggered exactly once per JVM, and the file name can be overridden at
* runtime with a System property or environment variable named "PIDFILE" (or "pidfile")
* or using a {@code spring.pid.file} property in the Spring {@link Environment}.
* <p>
* If PID file can not be created no exception is reported. This behavior can be changed
* by assigning {@code true} to System property or environment variable named
* {@code PID_FAIL_ON_WRITE_ERROR} (or "pid_fail_on_write_error") or to
* {@code spring.pid.fail-on-write-error} property in the Spring {@link Environment}.
* <p>
* Note: access to the Spring {@link Environment} is only possible when the
* {@link #setTriggerEventType(Class) triggerEventType} is set to
* {@link ApplicationEnvironmentPreparedEvent} or {@link ApplicationPreparedEvent}.
*
* @author Jakub Kubrynski
* @author Dave Syer
* @author Phillip Webb
* @author Tomasz Przybyla
* @since 1.2.0
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.system.ApplicationPidFileWriter}
*/
@Deprecated
public class ApplicationPidFileWriter
extends org.springframework.boot.system.ApplicationPidFileWriter {
/**
* Create a new {@link ApplicationPidFileWriter} instance using the filename
* 'application.pid'.
*/
public ApplicationPidFileWriter() {
super();
}
/**
* Create a new {@link ApplicationPidFileWriter} instance with a specified filename.
* @param filename the name of file containing pid
*/
public ApplicationPidFileWriter(String filename) {
super(filename);
}
/**
* Create a new {@link ApplicationPidFileWriter} instance with a specified file.
* @param file the file containing pid
*/
public ApplicationPidFileWriter(File file) {
super(file);
}
}
/*
* Copyright 2012-2015 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
*
* http://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.boot.actuate.system;
import java.io.File;
import org.springframework.context.ApplicationListener;
/**
* An {@link ApplicationListener} that saves embedded server port and management port into
* file. This application listener will be triggered whenever the servlet container
* starts, and the file name can be overridden at runtime with a System property or
* environment variable named "PORTFILE" or "portfile".
*
* @author David Liu
* @author Phillip Webb
* @author Andy Wilkinson
* @since 1.2.0
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.system.EmbeddedServerPortFileWriter}
*/
@Deprecated
public class EmbeddedServerPortFileWriter
extends org.springframework.boot.system.EmbeddedServerPortFileWriter {
/**
* Create a new {@link EmbeddedServerPortFileWriter} instance using the filename
* 'application.port'.
*/
public EmbeddedServerPortFileWriter() {
super();
}
/**
* Create a new {@link EmbeddedServerPortFileWriter} instance with a specified
* filename.
* @param filename the name of file containing port
*/
public EmbeddedServerPortFileWriter(String filename) {
super(filename);
}
/**
* Create a new {@link EmbeddedServerPortFileWriter} instance with a specified file.
* @param file the file containing port
*/
public EmbeddedServerPortFileWriter(File file) {
super(file);
}
}
/*
* Copyright 2012-2015 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
*
* http://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.
*/
/**
* General actuator system support classes.
*/
package org.springframework.boot.actuate.system;
......@@ -163,15 +163,6 @@
"description": "Enable git info.",
"defaultValue": true
},
{
"name": "management.security.role",
"type": "java.lang.String",
"description": "Roles required to access the management endpoint.",
"defaultValue": "ADMIN",
"deprecation": {
"replacement": "management.security.roles"
}
},
{
"name": "spring.git.properties",
"type": "java.lang.String",
......
......@@ -73,13 +73,6 @@ public class ManagementServerPropertiesAutoConfigurationTests {
assertThat(properties.getContextPath()).isEqualTo("");
}
@Test
@Deprecated
public void managementRoleSetRolesProperly() {
ManagementServerProperties properties = load("management.security.role=FOO");
assertThat(properties.getSecurity().getRoles()).containsOnly("FOO");
}
@Test
public void managementRolesSetMultipleRoles() {
ManagementServerProperties properties = load(
......
/*
* Copyright 2012-2016 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
*
* http://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.boot.actuate.endpoint;
import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link InfoEndpoint}.
*
* @author Dave Syer
*/
@Deprecated
public class InfoEndpointCompatibilityTests {
@Test
public void invoke() throws Exception {
Map<String, Object> actual = getEndpointBean().invoke();
assertThat(actual.get("key1")).isEqualTo("value1");
assertThat(actual.get("foo")).isEqualTo("bar");
}
private InfoEndpoint getEndpointBean() {
return new InfoEndpoint(Collections.<String, Object>singletonMap("foo", "bar"),
infoContributor());
}
private InfoContributor infoContributor() {
return new InfoContributor() {
@Override
public void contribute(Info.Builder builder) {
builder.withDetail("key1", "value1");
}
};
}
}
......@@ -29,7 +29,6 @@ import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
/**
* Configuration properties to configure Jackson.
......@@ -147,17 +146,6 @@ public class JacksonProperties {
return this.generator;
}
@Deprecated
@DeprecatedConfigurationProperty(reason = "ObjectMapper.setSerializationInclusion was deprecated in Jackson 2.7", replacement = "spring.jackson.default-property-inclusion")
public JsonInclude.Include getSerializationInclusion() {
return getDefaultPropertyInclusion();
}
@Deprecated
public void setSerializationInclusion(JsonInclude.Include serializationInclusion) {
setDefaultPropertyInclusion(serializationInclusion);
}
public JsonInclude.Include getDefaultPropertyInclusion() {
return this.defaultPropertyInclusion;
}
......
......@@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
/**
* Configuration properties for ActiveMQ.
......@@ -74,27 +73,6 @@ public class ActiveMQProperties {
this.inMemory = inMemory;
}
/**
* Get if pooling is enabled.
* @return if pooling is enabled
* @deprecated as of 1.4 in favor of "spring.activemq.pool.enabled"
*/
@Deprecated
@DeprecatedConfigurationProperty(replacement = "spring.activemq.pool.enabled")
public boolean isPooled() {
return getPool().isEnabled();
}
/**
* Set if pooling is enabled.
* @param pooled the pooling enabled value
* @deprecated as of 1.4 in favor of "spring.activemq.pool.enabled"
*/
@Deprecated
public void setPooled(boolean pooled) {
getPool().setEnabled(pooled);
}
public String getUser() {
return this.user;
}
......
......@@ -23,7 +23,6 @@ import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.util.StringUtils;
......@@ -149,17 +148,6 @@ public class JpaProperties {
@NestedConfigurationProperty
private final Naming naming = new Naming();
@Deprecated
@DeprecatedConfigurationProperty(replacement = "spring.jpa.hibernate.naming.strategy")
public String getNamingStrategy() {
return getNaming().getStrategy();
}
@Deprecated
public void setNamingStrategy(String namingStrategy) {
getNaming().setStrategy(namingStrategy);
}
public String getDdlAuto() {
return this.ddlAuto;
}
......
/*
* Copyright 2012-2016 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
*
* http://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.boot.autoconfigure.test;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
/**
* Import and apply the selected auto-configuration classes for testing purposes. Applies
* the same ordering rules as {@code @EnableAutoConfiguration} but restricts the
* auto-configuration classes to the specified set, rather than consulting
* {@code spring.factories}.
*
* @author Phillip Webb
* @since 1.3.0
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.autoconfigure.ImportAutoConfiguration}
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@org.springframework.boot.autoconfigure.ImportAutoConfiguration({})
@Deprecated
public @interface ImportAutoConfiguration {
/**
* The auto-configuration classes that should be imported.
* @return the classes to import
*/
@AliasFor(annotation = org.springframework.boot.autoconfigure.ImportAutoConfiguration.class, attribute = "value")
Class<?>[] value();
}
/*
* Copyright 2012-2016 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
*
* http://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.
*/
/**
* Test utilities related to auto-configuration.
* @deprecated as of 1.4 in favor of the {@code spring-boot-test-autoconfigure} module
*/
package org.springframework.boot.autoconfigure.test;
......@@ -66,7 +66,6 @@ import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletCon
import org.springframework.boot.context.embedded.undertow.UndertowBuilderCustomizer;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.EnvironmentAware;
......@@ -673,29 +672,6 @@ public class ServerProperties
this.minSpareThreads = minSpareThreads;
}
/**
* Get the max http header size.
* @return the max http header size.
* @deprecated as of 1.4 in favor of
* {@link ServerProperties#getMaxHttpHeaderSize()}
*/
@Deprecated
@DeprecatedConfigurationProperty(replacement = "server.max-http-header-size")
public int getMaxHttpHeaderSize() {
return this.maxHttpHeaderSize;
}
/**
* Set the max http header size.
* @param maxHttpHeaderSize the max http header size.
* @deprecated as of 1.4 in favor of
* {@link ServerProperties#setMaxHttpHeaderSize(int)}
*/
@Deprecated
public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
this.maxHttpHeaderSize = maxHttpHeaderSize;
}
public Accesslog getAccesslog() {
return this.accesslog;
}
......
......@@ -80,19 +80,6 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
}
@Test
public void testMixedRepositoryConfigurationWithDeprecatedEntityScan()
throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
this.context.register(MixedConfigurationWithDeprecatedEntityScan.class,
BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CountryRepository.class)).isNotNull();
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
}
@Test
public void testJpaRepositoryConfigurationWithMongoTemplate() throws Exception {
this.context = new AnnotationConfigApplicationContext();
......@@ -103,18 +90,6 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
}
@Test
public void testJpaRepositoryConfigurationWithMongoTemplateAndDeprecatedEntityScan()
throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
this.context.register(JpaConfigurationWithDeprecatedEntityScan.class,
BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
}
@Test
public void testJpaRepositoryConfigurationWithMongoOverlap() throws Exception {
this.context = new AnnotationConfigApplicationContext();
......@@ -162,25 +137,6 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
}
@Configuration
@TestAutoConfigurationPackage(MongoAutoConfigurationTests.class)
@EnableMongoRepositories(basePackageClasses = Country.class)
@org.springframework.boot.orm.jpa.EntityScan(basePackageClasses = City.class)
@EnableJpaRepositories(basePackageClasses = CityRepository.class)
@SuppressWarnings("deprecation")
protected static class MixedConfigurationWithDeprecatedEntityScan {
}
@Configuration
@TestAutoConfigurationPackage(MongoAutoConfigurationTests.class)
@org.springframework.boot.orm.jpa.EntityScan(basePackageClasses = City.class)
@EnableJpaRepositories(basePackageClasses = CityRepository.class)
@SuppressWarnings("deprecation")
protected static class JpaConfigurationWithDeprecatedEntityScan {
}
// In this one the Jpa repositories and the auto-configuration packages overlap, so
// Mongo will try and configure the same repositories
@Configuration
......
......@@ -368,7 +368,7 @@ public class JacksonAutoConfigurationTests {
public void customSerializationInclusion() {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.serialization-inclusion:non_null");
"spring.jackson.default-property-inclusion:non_null");
this.context.refresh();
ObjectMapper objectMapper = this.context
.getBean(Jackson2ObjectMapperBuilder.class).build();
......
......@@ -54,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Eddú Meléndez
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jackson.serialization-inclusion=non_null")
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jackson.default-property-inclusion=non_null")
@DirtiesContext
public class JerseyAutoConfigurationCustomObjectMapperProviderTests {
......
......@@ -56,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jackson.serialization-inclusion:non-null")
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jackson.default-property-inclusion:non-null")
@DirtiesContext
public class JerseyAutoConfigurationObjectMapperProviderTests {
......
......@@ -88,7 +88,7 @@ public class HibernateJpaAutoConfigurationTests
public void testCustomNamingStrategy() throws Exception {
HibernateVersion.setRunning(HibernateVersion.V4);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jpa.hibernate.namingStrategy:"
"spring.jpa.hibernate.naming.strategy:"
+ "org.hibernate.cfg.EJB3NamingStrategy");
setupTestConfiguration();
this.context.refresh();
......
......@@ -296,7 +296,6 @@ content into your application; rather pick only the properties that you need.
spring.jackson.parser.*= # Jackson on/off features for parsers.
spring.jackson.property-naming-strategy= # One of the constants on Jackson's PropertyNamingStrategy. Can also be a fully-qualified class name of a PropertyNamingStrategy subclass.
spring.jackson.serialization.*= # Jackson on/off features that affect the way Java objects are serialized.
spring.jackson.serialization-inclusion= # Controls the inclusion of properties during serialization. Configured with one of the values in Jackson's JsonInclude.Include enumeration.
spring.jackson.time-zone= # Time zone used when formatting dates. For instance `America/Los_Angeles`
# JERSEY ({sc-spring-boot-autoconfigure}/jersey/JerseyProperties.{sc-ext}[JerseyProperties])
......
......@@ -1266,7 +1266,7 @@ Jackson which map onto properties in the environment:
|`spring.jackson.serialization.<feature_name>=true\|false`
|`com.fasterxml.jackson.annotation.JsonInclude.Include`
|`spring.jackson.serialization-inclusion=always\|non_null\|non_absent\|non_default\|non_empty`
|`spring.jackson.default-property-inclusion=always\|non_null\|non_absent\|non_default\|non_empty`
|===
For example, to enable pretty print, set `spring.jackson.serialization.indent_output=true`.
......
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.test.context.ContextConfiguration;
/**
* {@link ApplicationContextInitializer} that can be used with the
* {@link ContextConfiguration#initializers()} to trigger loading of
* {@literal application.properties}.
*
* @author Phillip Webb
* @see ConfigFileApplicationListener
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.context.ConfigFileApplicationContextInitializer}
*/
@Deprecated
public class ConfigFileApplicationContextInitializer extends
org.springframework.boot.test.context.ConfigFileApplicationContextInitializer {
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
/**
* Test utilities for setting environment values.
*
* @author Dave Syer
* @author Stephane Nicoll
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.util.EnvironmentTestUtils}
*/
@Deprecated
public abstract class EnvironmentTestUtils {
/**
* Add additional (high priority) values to an {@link Environment} owned by an
* {@link ApplicationContext}. Name-value pairs can be specified with colon (":") or
* equals ("=") separators.
* @param context the context with an environment to modify
* @param pairs the name:value pairs
*/
public static void addEnvironment(ConfigurableApplicationContext context,
String... pairs) {
org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment(context,
pairs);
}
/**
* Add additional (high priority) values to an {@link Environment}. Name-value pairs
* can be specified with colon (":") or equals ("=") separators.
* @param environment the environment to modify
* @param pairs the name:value pairs
*/
public static void addEnvironment(ConfigurableEnvironment environment,
String... pairs) {
org.springframework.boot.test.util.EnvironmentTestUtils
.addEnvironment(environment, pairs);
}
/**
* Add additional (high priority) values to an {@link Environment}. Name-value pairs
* can be specified with colon (":") or equals ("=") separators.
* @param environment the environment to modify
* @param name the property source name
* @param pairs the name:value pairs
*/
public static void addEnvironment(String name, ConfigurableEnvironment environment,
String... pairs) {
org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment(name,
environment, pairs);
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
/**
* Test class annotation signifying that the tests are "integration tests" and therefore
* require full startup in the same way as a production application. Normally used in
* conjunction with {@code @SpringApplicationConfiguration}.
* <p>
* If your test also uses {@code @WebAppConfiguration} consider using the
* {@link WebIntegrationTest} instead.
*
* @author Dave Syer
* @see WebIntegrationTest
* @deprecated as of 1.4 in favor of {@link SpringBootTest}
*/
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
// Leave out the ServletTestExecutionListener because it only deals with Mock* servlet
// stuff. A real embedded application will not need the mocks.
@TestExecutionListeners(listeners = { IntegrationTestPropertiesListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class })
@Deprecated
public @interface IntegrationTest {
/**
* Properties in form {@literal key=value} that should be added to the Spring
* {@link Environment} before the test runs.
* @return the environment properties
*/
String[] value() default {};
}
/*
* Copyright 2013-2016 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
*
* http://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.boot.test;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.test.util.ReflectionTestUtils;
/**
* Manipulate the TestContext to merge properties from {@code @IntegrationTest}.
*
* @author Dave Syer
* @author Phillip Webb
* @since 1.2.0
* @deprecated as of 1.4 as no longer used by {@code @IntegrationTest}.
*/
@Deprecated
public class IntegrationTestPropertiesListener extends AbstractTestExecutionListener {
@Override
public void prepareTestInstance(TestContext testContext) throws Exception {
Class<?> testClass = testContext.getTestClass();
AnnotationAttributes annotationAttributes = AnnotatedElementUtils
.getMergedAnnotationAttributes(testClass,
IntegrationTest.class.getName());
if (annotationAttributes != null) {
addPropertySourceProperties(testContext,
annotationAttributes.getStringArray("value"));
}
}
private void addPropertySourceProperties(TestContext testContext,
String[] properties) {
try {
MergedContextConfiguration configuration = (MergedContextConfiguration) ReflectionTestUtils
.getField(testContext, "mergedContextConfiguration");
new MergedContextConfigurationProperties(configuration).add(properties);
}
catch (RuntimeException ex) {
throw ex;
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.util.ReflectionTestUtils;
/**
* Provides access to {@link MergedContextConfiguration} properties.
*
* @author Phillip Webb
* @deprecated as of 1.4 along with {@link IntegrationTestPropertiesListener}
*/
@Deprecated
class MergedContextConfigurationProperties {
private final MergedContextConfiguration configuration;
MergedContextConfigurationProperties(MergedContextConfiguration configuration) {
this.configuration = configuration;
}
public void add(String[] properties, String... additional) {
Set<String> merged = new LinkedHashSet<String>(
(Arrays.asList(this.configuration.getPropertySourceProperties())));
merged.addAll(Arrays.asList(properties));
merged.addAll(Arrays.asList(additional));
addIntegrationTestProperty(merged);
ReflectionTestUtils.setField(this.configuration, "propertySourceProperties",
merged.toArray(new String[merged.size()]));
}
/**
* Add an "IntegrationTest" property to ensure that there is something to
* differentiate regular tests and {@code @IntegrationTest} tests. Without this
* property a cached context could be returned that hadn't started the embedded
* servlet container.
* @param propertySourceProperties the property source properties
*/
private void addIntegrationTestProperty(Set<String> propertySourceProperties) {
propertySourceProperties.add(WebIntegrationTest.class.getName() + "=true");
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
/**
* JUnit {@code @Rule} to capture output from System.out and System.err.
*
* @author Phillip Webb
* @author Andy Wilkinson
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.rule.OutputCapture}
*/
@Deprecated
public class OutputCapture extends org.springframework.boot.test.rule.OutputCapture {
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.test.context.SpringBootContextLoader;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.AliasFor;
import org.springframework.test.context.ContextConfiguration;
/**
* Class-level annotation that is used to determine how to load and configure an
* {@code ApplicationContext} for integration tests.
* <p>
* Similar to the standard {@link ContextConfiguration @ContextConfiguration} but uses
* Spring Boot's {@link SpringApplicationContextLoader}.
*
* @author Dave Syer
* @author Sam Brannen
* @see SpringBootContextLoader
* @see ContextConfiguration
* @deprecated as of 1.4 in favor of {@link SpringBootTest} or direct use of
* {@link SpringBootContextLoader}.
*/
@ContextConfiguration(loader = SpringApplicationContextLoader.class)
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Deprecated
public @interface SpringApplicationConfiguration {
/**
* The context configuration classes.
* @see ContextConfiguration#classes()
* @return the context configuration classes
*/
@AliasFor("classes")
Class<?>[] value() default {};
/**
* The context configuration locations.
* @see ContextConfiguration#locations()
* @return the context configuration locations
*/
@AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
String[] locations() default {};
/**
* The context configuration classes.
* @see ContextConfiguration#classes()
* @return the context configuration classes
*/
@AliasFor("value")
Class<?>[] classes() default {};
/**
* The context configuration initializers.
* @see ContextConfiguration#initializers()
* @return the context configuration initializers
*/
@AliasFor(annotation = ContextConfiguration.class, attribute = "initializers")
Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers() default {};
/**
* Should context locations be inherited.
* @see ContextConfiguration#inheritLocations()
* @return {@code true} if context locations should be inherited
*/
@AliasFor(annotation = ContextConfiguration.class, attribute = "inheritLocations")
boolean inheritLocations() default true;
/**
* Should initializers be inherited.
* @see ContextConfiguration#inheritInitializers()
* @return {@code true} if context initializers should be inherited
*/
@AliasFor(annotation = ContextConfiguration.class, attribute = "inheritInitializers")
boolean inheritInitializers() default true;
/**
* The name of the context hierarchy level.
* @see ContextConfiguration#name()
* @return the name of the context hierarchy level
*/
@AliasFor(annotation = ContextConfiguration.class, attribute = "name")
String name() default "";
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.springframework.core.io.ResourceLoader;
import org.springframework.mock.web.MockServletContext;
/**
* {@link MockServletContext} implementation for Spring Boot. Respects well-known Spring
* Boot resource locations and uses an empty directory for "/" if no locations can be
* found.
*
* @author Phillip Webb
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.mock.web.SpringBootMockServletContext}
*/
@Deprecated
public class SpringBootMockServletContext
extends org.springframework.boot.test.mock.web.SpringBootMockServletContext {
public SpringBootMockServletContext(String resourceBasePath) {
super(resourceBasePath);
}
public SpringBootMockServletContext(String resourceBasePath,
ResourceLoader resourceLoader) {
super(resourceBasePath, resourceLoader);
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.config.RequestConfig.Builder;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.protocol.HttpContext;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.InterceptingClientHttpRequestFactory;
import org.springframework.http.client.support.BasicAuthorizationInterceptor;
import org.springframework.util.ClassUtils;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
/**
* Convenient subclass of {@link RestTemplate} that is suitable for integration tests.
* They are fault tolerant, and optionally can carry Basic authentication headers. If
* Apache Http Client 4.3.2 or better is available (recommended) it will be used as the
* client, and by default configured to ignore cookies and redirects.
*
* @author Dave Syer
* @author Phillip Webb
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.web.client.TestRestTemplate}
*/
@Deprecated
public class TestRestTemplate extends RestTemplate {
/**
* Create a new {@link TestRestTemplate} instance.
* @param httpClientOptions client options to use if the Apache HTTP Client is used
*/
public TestRestTemplate(HttpClientOption... httpClientOptions) {
this(null, null, httpClientOptions);
}
/**
* Create a new {@link TestRestTemplate} instance with the specified credentials.
* @param username the username to use (or {@code null})
* @param password the password (or {@code null})
* @param httpClientOptions client options to use if the Apache HTTP Client is used
*/
public TestRestTemplate(String username, String password,
HttpClientOption... httpClientOptions) {
if (ClassUtils.isPresent("org.apache.http.client.config.RequestConfig", null)) {
setRequestFactory(
new CustomHttpComponentsClientHttpRequestFactory(httpClientOptions));
}
addAuthentication(username, password);
setErrorHandler(new DefaultResponseErrorHandler() {
@Override
public void handleError(ClientHttpResponse response) throws IOException {
}
});
}
private void addAuthentication(String username, String password) {
if (username == null) {
return;
}
List<ClientHttpRequestInterceptor> interceptors = Collections
.<ClientHttpRequestInterceptor>singletonList(
new BasicAuthorizationInterceptor(username, password));
setRequestFactory(new InterceptingClientHttpRequestFactory(getRequestFactory(),
interceptors));
}
/**
* Options used to customize the Apache Http Client if it is used.
*/
public enum HttpClientOption {
/**
* Enable cookies.
*/
ENABLE_COOKIES,
/**
* Enable redirects.
*/
ENABLE_REDIRECTS
}
/**
* {@link HttpComponentsClientHttpRequestFactory} to apply customizations.
*/
protected static class CustomHttpComponentsClientHttpRequestFactory
extends HttpComponentsClientHttpRequestFactory {
private final String cookieSpec;
private final boolean enableRedirects;
public CustomHttpComponentsClientHttpRequestFactory(
HttpClientOption[] httpClientOptions) {
Set<HttpClientOption> options = new HashSet<TestRestTemplate.HttpClientOption>(
Arrays.asList(httpClientOptions));
this.cookieSpec = (options.contains(HttpClientOption.ENABLE_COOKIES)
? CookieSpecs.STANDARD : CookieSpecs.IGNORE_COOKIES);
this.enableRedirects = options.contains(HttpClientOption.ENABLE_REDIRECTS);
}
@Override
protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
HttpClientContext context = HttpClientContext.create();
context.setRequestConfig(getRequestConfig());
return context;
}
protected RequestConfig getRequestConfig() {
Builder builder = RequestConfig.custom().setCookieSpec(this.cookieSpec)
.setAuthenticationEnabled(false)
.setRedirectsEnabled(this.enableRedirects);
return builder.build();
}
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.test.context.ContextLoader;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.TestContextBootstrapper;
import org.springframework.test.context.support.DefaultTestContextBootstrapper;
import org.springframework.test.context.web.WebDelegatingSmartContextLoader;
import org.springframework.test.context.web.WebMergedContextConfiguration;
/**
* {@link TestContextBootstrapper} for Spring Boot web integration tests.
*
* @author Phillip Webb
* @since 1.2.1
* @deprecated as of 1.4 along with {@link WebIntegrationTest}
*/
@Deprecated
class WebAppIntegrationTestContextBootstrapper extends DefaultTestContextBootstrapper {
@Override
protected Class<? extends ContextLoader> getDefaultContextLoaderClass(
Class<?> testClass) {
if (AnnotationUtils.findAnnotation(testClass, WebIntegrationTest.class) != null) {
return WebDelegatingSmartContextLoader.class;
}
return super.getDefaultContextLoaderClass(testClass);
}
@Override
protected MergedContextConfiguration processMergedContextConfiguration(
MergedContextConfiguration mergedConfig) {
WebIntegrationTest annotation = AnnotationUtils
.findAnnotation(mergedConfig.getTestClass(), WebIntegrationTest.class);
if (annotation != null) {
mergedConfig = new WebMergedContextConfiguration(mergedConfig, null);
MergedContextConfigurationProperties properties = new MergedContextConfigurationProperties(
mergedConfig);
if (annotation.randomPort()) {
properties.add(annotation.value(), "server.port:0");
}
else {
properties.add(annotation.value());
}
}
return mergedConfig;
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.core.env.Environment;
import org.springframework.test.context.BootstrapWith;
/**
* Test class annotation signifying that the tests are "web integration tests" and
* therefore require full startup in the same way as a production application (listening
* on normal ports). Normally used in conjunction with
* {@code @SpringApplicationConfiguration},
* <p>
* This annotation can be used as an alternative to {@code @IntegrationTest} and
* {@code @WebAppConfiguration}.
*
* @author Phillip Webb
* @since 1.2.1
* @see IntegrationTest
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.context.SpringBootTest} with
* {@code webEnvironment=RANDOM_PORT} or {@code webEnvironment=DEFINED_PORT}.
*/
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@BootstrapWith(WebAppIntegrationTestContextBootstrapper.class)
@Deprecated
public @interface WebIntegrationTest {
/**
* Properties in form {@literal key=value} that should be added to the Spring
* {@link Environment} before the test runs.
* @return properties to add to the context
*/
String[] value() default {};
/**
* Convenience attribute that can be used to set a {@code server.port=0}
* {@link Environment} property which usually triggers listening on a random port.
* Often used in conjunction with a {@link LocalServerPort} injected field on the
* test.
* @return if a random port should be used
*/
boolean randomPort() default false;
}
/*
* Copyright 2012-2016 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
*
* http://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.
*/
/**
* Classes and utilities that are useful when unit-testing Spring Boot applications.
*/
package org.springframework.boot.test;
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ConfigFileApplicationContextInitializer}.
*
* @author Phillip Webb
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@ContextConfiguration(classes = ConfigFileApplicationContextInitializerTests.Config.class, initializers = ConfigFileApplicationContextInitializer.class)
@Deprecated
@SuppressWarnings("deprecation")
public class ConfigFileApplicationContextInitializerTests {
@Autowired
private Environment environment;
@Test
public void initializerPopulatesEnvironment() {
assertThat(this.environment.getProperty("foo")).isEqualTo("bucket");
}
@Configuration
public static class Config {
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.StandardEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link EnvironmentTestUtils}.
*
* @author Stephane Nicoll
*/
@Deprecated
public class EnvironmentTestUtilsTests {
private final ConfigurableEnvironment environment = new StandardEnvironment();
@Test
public void addSimplePairEqual() {
testAddSimplePair("my.foo", "bar", "=");
}
@Test
public void addSimplePairColon() {
testAddSimplePair("my.foo", "bar", ":");
}
@Test
public void addSimplePairEqualWithEqualInValue() {
testAddSimplePair("my.foo", "b=ar", "=");
}
@Test
public void addSimplePairEqualWithColonInValue() {
testAddSimplePair("my.foo", "b:ar", "=");
}
@Test
public void addSimplePairColonWithColonInValue() {
testAddSimplePair("my.foo", "b:ar", ":");
}
@Test
public void addSimplePairColonWithEqualInValue() {
testAddSimplePair("my.foo", "b=ar", ":");
}
@Test
public void addPairNoValue() {
String propertyName = "my.foo+bar";
assertThat(this.environment.containsProperty(propertyName)).isFalse();
EnvironmentTestUtils.addEnvironment(this.environment, propertyName);
assertThat(this.environment.containsProperty(propertyName)).isTrue();
assertThat(this.environment.getProperty(propertyName)).isEqualTo("");
}
private void testAddSimplePair(String key, String value, String delimiter) {
assertThat(this.environment.containsProperty(key)).isFalse();
EnvironmentTestUtils.addEnvironment(this.environment, key + delimiter + value);
assertThat(this.environment.getProperty(key)).isEqualTo(value);
}
@Test
public void testConfigHasHigherPrecedence() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("my.foo", "bar");
MapPropertySource source = new MapPropertySource("sample", map);
this.environment.getPropertySources().addFirst(source);
assertThat(this.environment.getProperty("my.foo")).isEqualTo("bar");
EnvironmentTestUtils.addEnvironment(this.environment, "my.foo=bar2");
assertThat(this.environment.getProperty("my.foo")).isEqualTo("bar2");
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SpringApplicationContextLoader} with active profiles. See gh-1469.
*
* @author Phillip Webb
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration
@IntegrationTest("spring.config.name=enableother")
@ActiveProfiles("override")
@Deprecated
@SuppressWarnings("deprecation")
public class SpringApplicationConfigurationActiveProfileTests {
@Autowired
private ApplicationContext context;
@Test
public void profiles() throws Exception {
assertThat(this.context.getEnvironment().getActiveProfiles())
.containsExactly("override");
}
@Configuration
protected static class Config {
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SpringApplicationContextLoader} (detectDefaultConfigurationClasses).
*
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration
@Deprecated
@SuppressWarnings("deprecation")
public class SpringApplicationConfigurationDefaultConfigurationTests {
@Autowired
private Config config;
@Test
public void nestedConfigClasses() {
assertThat(this.config).isNotNull();
}
@Configuration
protected static class Config {
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SpringApplicationContextLoader} (detectDefaultConfigurationClasses).
*
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration(locations = "classpath:test.groovy")
@Deprecated
@SuppressWarnings("deprecation")
public class SpringApplicationConfigurationGroovyConfigurationTests {
@Autowired
private String foo;
@Test
public void groovyConfigLoaded() {
assertThat(this.foo).isNotNull();
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SpringApplicationContextLoader} finding groovy config.
*
* @author Phillip Webb
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration
@Deprecated
@SuppressWarnings("deprecation")
public class SpringApplicationConfigurationGroovyConventionConfigurationTests {
@Autowired
private String foo;
@Test
public void groovyConfigLoaded() {
assertThat(this.foo).isEqualTo("World");
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfigurationJmxTests.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for disabling JMX by default
*
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration(Config.class)
@IntegrationTest
@Deprecated
public class SpringApplicationConfigurationJmxTests {
@Value("${spring.jmx.enabled}")
private boolean jmx;
@Test
public void disabledByDefault() {
assertThat(this.jmx).isFalse();
}
@Configuration
protected static class Config {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfigurationMixedConfigurationTests.Config;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SpringApplicationContextLoader}.
*
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration(classes = Config.class, locations = "classpath:test.groovy")
@Deprecated
public class SpringApplicationConfigurationMixedConfigurationTests {
@Autowired
private String foo;
@Autowired
private Config config;
@Test
public void mixedConfigClasses() {
assertThat(this.foo).isNotNull();
assertThat(this.config).isNotNull();
}
@Configuration
protected static class Config {
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SpringApplicationContextLoader} finding XML config.
*
* @author Phillip Webb
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration
@Deprecated
@SuppressWarnings("deprecation")
public class SpringApplicationConfigurationXmlConventionConfigurationTests {
@Autowired
private String foo;
@Test
public void xmlConfigLoaded() {
assertThat(this.foo).isEqualTo("World");
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import java.util.Map;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestContextManager;
import org.springframework.test.context.support.TestPropertySourceUtils;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SpringApplicationContextLoader}
*
* @author Stephane Nicoll
*/
@Deprecated
@SuppressWarnings("deprecation")
public class SpringApplicationContextLoaderTests {
@Test
public void environmentPropertiesSimple() throws Exception {
Map<String, Object> config = getEnvironmentProperties(SimpleConfig.class);
assertKey(config, "key", "myValue");
assertKey(config, "anotherKey", "anotherValue");
}
@Test
public void environmentPropertiesOverrideDefaults() throws Exception {
Map<String, Object> config = getEnvironmentProperties(OverrideConfig.class);
assertKey(config, "server.port", "2345");
}
@Test
public void environmentPropertiesAppend() throws Exception {
Map<String, Object> config = getEnvironmentProperties(AppendConfig.class);
assertKey(config, "key", "myValue");
assertKey(config, "otherKey", "otherValue");
}
@Test
public void environmentPropertiesSeparatorInValue() throws Exception {
Map<String, Object> config = getEnvironmentProperties(SameSeparatorInValue.class);
assertKey(config, "key", "my=Value");
assertKey(config, "anotherKey", "another:Value");
}
@Test
public void environmentPropertiesAnotherSeparatorInValue() throws Exception {
Map<String, Object> config = getEnvironmentProperties(
AnotherSeparatorInValue.class);
assertKey(config, "key", "my:Value");
assertKey(config, "anotherKey", "another=Value");
}
@Test
@Ignore
public void environmentPropertiesNewLineInValue() throws Exception {
// gh-4384
Map<String, Object> config = getEnvironmentProperties(NewLineInValue.class);
assertKey(config, "key", "myValue");
assertKey(config, "variables", "foo=FOO\n bar=BAR");
}
private Map<String, Object> getEnvironmentProperties(Class<?> testClass)
throws Exception {
TestContext context = new ExposedTestContextManager(testClass)
.getExposedTestContext();
new IntegrationTestPropertiesListener().prepareTestInstance(context);
MergedContextConfiguration config = (MergedContextConfiguration) ReflectionTestUtils
.getField(context, "mergedContextConfiguration");
return TestPropertySourceUtils
.convertInlinedPropertiesToMap(config.getPropertySourceProperties());
}
private void assertKey(Map<String, Object> actual, String key, Object value) {
assertThat(actual.containsKey(key)).as("Key '" + key + "' not found").isTrue();
assertThat(actual.get(key)).isEqualTo(value);
}
@IntegrationTest({ "key=myValue", "anotherKey:anotherValue" })
@ContextConfiguration(classes = Config.class)
static class SimpleConfig {
}
@IntegrationTest({ "server.port=2345" })
@ContextConfiguration(classes = Config.class)
static class OverrideConfig {
}
@IntegrationTest({ "key=myValue", "otherKey=otherValue" })
@ContextConfiguration(classes = Config.class)
static class AppendConfig {
}
@IntegrationTest({ "key=my=Value", "anotherKey:another:Value" })
@ContextConfiguration(classes = Config.class)
static class SameSeparatorInValue {
}
@IntegrationTest({ "key=my:Value", "anotherKey:another=Value" })
@ContextConfiguration(classes = Config.class)
static class AnotherSeparatorInValue {
}
@IntegrationTest({ "key=myValue", "variables=foo=FOO\n bar=BAR" })
@ContextConfiguration(classes = Config.class)
static class NewLineInValue {
}
@Configuration
static class Config {
}
/**
* {@link TestContextManager} which exposes the {@link TestContext}.
*/
private static class ExposedTestContextManager extends TestContextManager {
ExposedTestContextManager(Class<?> testClass) {
super(testClass);
}
public final TestContext getExposedTestContext() {
return super.getTestContext();
}
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import javax.annotation.PostConstruct;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationIntegrationTestPropertyLocationTests.MoreConfig;
import org.springframework.boot.test.SpringApplicationIntegrationTestTests.Config;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link IntegrationTest} with {@link TestPropertySource} locations.
*
* @author Phillip Webb
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration({ Config.class, MoreConfig.class })
@WebAppConfiguration
@IntegrationTest({ "server.port=0", "value1=123" })
@TestPropertySource(properties = "value2=456", locations = "classpath:/test-property-source-annotation.properties")
@Deprecated
public class SpringApplicationIntegrationTestPropertyLocationTests {
@Autowired
private Environment environment;
@Test
public void loadedProperties() throws Exception {
assertThat(this.environment.getProperty("value1")).isEqualTo("123");
assertThat(this.environment.getProperty("value2")).isEqualTo("456");
assertThat(this.environment.getProperty("property-source-location"))
.isEqualTo("baz");
}
@Configuration
static class MoreConfig {
@Value("${value1}")
private String value1;
@Value("${value2}")
private String value2;
@Value("${property-source-location}")
private String annotationReferenced;
@PostConstruct
void checkValues() {
assertThat(this.value1).isEqualTo("123");
assertThat(this.value2).isEqualTo("456");
assertThat(this.annotationReferenced).isEqualTo("baz");
}
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import javax.servlet.ServletContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.test.SpringApplicationIntegrationTestTests.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link IntegrationTest}
*
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration(Config.class)
@WebAppConfiguration
@IntegrationTest({ "server.port=0", "value=123" })
@Deprecated
public class SpringApplicationIntegrationTestTests {
@LocalServerPort
private int port = 0;
@Value("${value}")
private int value = 0;
@Autowired
private WebApplicationContext context;
@Autowired
private ServletContext servletContext;
@Test
public void runAndTestHttpEndpoint() {
assertThat(this.port).isNotEqualTo(8080).isNotEqualTo(0);
String body = new RestTemplate()
.getForObject("http://localhost:" + this.port + "/", String.class);
assertThat(body).isEqualTo("Hello World");
}
@Test
public void annotationAttributesOverridePropertiesFile() throws Exception {
assertThat(this.value).isEqualTo(123);
}
@Test
public void validateWebApplicationContextIsSet() {
assertThat(this.context).isSameAs(
WebApplicationContextUtils.getWebApplicationContext(this.servletContext));
}
@Configuration
@EnableWebMvc
@RestController
protected static class Config {
@Value("${server.port:8080}")
private int port = 8080;
@Bean
public DispatcherServlet dispatcherServlet() {
return new DispatcherServlet();
}
@Bean
public EmbeddedServletContainerFactory embeddedServletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setPort(this.port);
return factory;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceholder() {
return new PropertySourcesPlaceholderConfigurer();
}
@RequestMapping("/")
public String home() {
return "Hello World";
}
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import javax.servlet.ServletContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationMockMvcTests.Config;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* Tests for {@link WebAppConfiguration} with {@link MockMvc}.
*
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration(classes = Config.class)
@WebAppConfiguration
@Deprecated
public class SpringApplicationMockMvcTests {
@Autowired
private WebApplicationContext context;
@Autowired
private ServletContext servletContext;
private MockMvc mvc;
@Before
public void setUp() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
}
@Test
public void testMockHttpEndpoint() throws Exception {
this.mvc.perform(get("/")).andExpect(status().isOk())
.andExpect(content().string("Hello World"));
}
@Test
public void validateWebApplicationContextIsSet() {
assertThat(this.context).isSameAs(
WebApplicationContextUtils.getWebApplicationContext(this.servletContext));
}
@Configuration
@EnableWebMvc
@RestController
protected static class Config {
@RequestMapping("/")
public String home() {
return "Hello World";
}
}
}
/*
* Copyright 2012-2015 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
*
* http://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.boot.test;
import javax.servlet.ServletContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationMockServletTests.Config;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link WebAppConfiguration} using {@link SpringApplicationContextLoader} with
* a plain mock Servlet environment.
*
*
* @author Andy Wilkinson
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Config.class, loader = SpringApplicationContextLoader.class)
@WebAppConfiguration
@Deprecated
public class SpringApplicationMockServletTests {
@Autowired
private WebApplicationContext context;
@Autowired
private ServletContext servletContext;
@Test
public void webApplicationContextIsSetOnServletContext() {
assertThat(this.context).isSameAs(
WebApplicationContextUtils.getWebApplicationContext(this.servletContext));
}
@Configuration
protected static class Config {
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import javax.servlet.ServletContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.test.SpringApplicationWebIntegrationTestTests.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link IntegrationTest}
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration(Config.class)
@WebIntegrationTest({ "server.port=0", "value=123" })
public class SpringApplicationWebIntegrationTestTests {
@LocalServerPort
private int port = 0;
@Value("${value}")
private int value = 0;
@Autowired
private WebApplicationContext context;
@Autowired
private ServletContext servletContext;
@Test
public void runAndTestHttpEndpoint() {
assertThat(this.port).isNotEqualTo(8080).isNotEqualTo(0);
String body = new RestTemplate()
.getForObject("http://localhost:" + this.port + "/", String.class);
assertThat(body).isEqualTo("Hello World");
}
@Test
public void annotationAttributesOverridePropertiesFile() throws Exception {
assertThat(this.value).isEqualTo(123);
}
@Test
public void validateWebApplicationContextIsSet() {
assertThat(this.context).isSameAs(
WebApplicationContextUtils.getWebApplicationContext(this.servletContext));
}
@Configuration
@EnableWebMvc
@RestController
protected static class Config {
@Value("${server.port:8080}")
private int port = 8080;
@Bean
public DispatcherServlet dispatcherServlet() {
return new DispatcherServlet();
}
@Bean
public EmbeddedServletContainerFactory embeddedServletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setPort(this.port);
return factory;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceholder() {
return new PropertySourcesPlaceholderConfigurer();
}
@RequestMapping("/")
public String home() {
return "Hello World";
}
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import java.io.File;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import javax.servlet.ServletContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.context.ServletContextAware;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.nullValue;
/**
* Tests for {@link SpringBootMockServletContext}.
*
* @author Phillip Webb
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringApplicationConfiguration(SpringBootMockServletContextTests.Config.class)
@WebAppConfiguration("src/test/webapp")
@Deprecated
@SuppressWarnings("deprecation")
public class SpringBootMockServletContextTests implements ServletContextAware {
private ServletContext servletContext;
@Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
@Test
public void getResourceLocation() throws Exception {
testResource("/inwebapp", "src/test/webapp");
testResource("/inmetainfresources", "/META-INF/resources");
testResource("/inresources", "/resources");
testResource("/instatic", "/static");
testResource("/inpublic", "/public");
}
private void testResource(String path, String expectedLocation)
throws MalformedURLException {
URL resource = this.servletContext.getResource(path);
assertThat(resource).isNotNull();
assertThat(resource.getPath()).contains(expectedLocation);
}
// gh-2654
@Test
public void getRootUrlExistsAndIsEmpty() throws Exception {
SpringBootMockServletContext context = new SpringBootMockServletContext(
"src/test/doesntexist") {
@Override
protected String getResourceLocation(String path) {
// Don't include the Spring Boot defaults for this test
return getResourceBasePathLocation(path);
};
};
URL resource = context.getResource("/");
assertThat(resource).isNotEqualTo(nullValue());
File file = new File(URLDecoder.decode(resource.getPath(), "UTF-8"));
assertThat(file).exists().isDirectory();
String[] contents = file.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !(".".equals(name) || "..".equals(name));
}
});
assertThat(contents).isNotEqualTo(nullValue());
assertThat(contents.length).isEqualTo(0);
}
@Configuration
static class Config {
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.test;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for the deprecated {@link TestRestTemplate}.
*
* @author Dave Syer
*/
@Deprecated
public class TestRestTemplateTests {
@Test
public void canCreateTemplateFromOwnOptions() {
TestRestTemplate template = new TestRestTemplate(
TestRestTemplate.HttpClientOption.ENABLE_REDIRECTS);
assertThat(template).isNotNull();
}
}
......@@ -141,30 +141,6 @@ public class ConfigurationMetadataProperty implements Serializable {
return this.hints;
}
/**
* The list of well-defined values, if any. If no extra {@link ValueProvider provider}
* is specified, these values are to be considered a closed-set of the available
* values for this item.
* @return the value hints
* @see #getHints()
*/
@Deprecated
public List<ValueHint> getValueHints() {
return this.hints.getValueHints();
}
/**
* The value providers that are applicable to this item. Only one
* {@link ValueProvider} is enabled for an item: the first in the list that is
* supported should be used.
* @return the value providers
* @see #getHints()
*/
@Deprecated
public List<ValueProvider> getValueProviders() {
return this.hints.getValueProviders();
}
/**
* The {@link Deprecation} for this property, if any.
* @return the deprecation
......
......@@ -540,9 +540,6 @@ public class SpringApplication {
if (this.bannerMode == Banner.Mode.OFF) {
return null;
}
if (printBannerViaDeprecatedMethod(environment)) {
return null;
}
ResourceLoader resourceLoader = this.resourceLoader != null ? this.resourceLoader
: new DefaultResourceLoader(getClassLoader());
SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(
......@@ -553,26 +550,6 @@ public class SpringApplication {
return bannerPrinter.print(environment, this.mainApplicationClass, System.out);
}
private boolean printBannerViaDeprecatedMethod(Environment environment) {
this.printedCustomBannerViaDeprecatedMethod = true;
printBanner(environment);
return this.printedCustomBannerViaDeprecatedMethod;
}
/**
* Print a custom banner message to the console, optionally extracting its location or
* content from the Environment (banner.location and banner.charset). The defaults are
* banner.location=classpath:banner.txt, banner.charset=UTF-8. If the banner file does
* not exist or cannot be printed, a simple default is created.
* @param environment the environment
* @see #setBannerMode
* @deprecated as of 1.4 in favor of @{@link #setBanner(Banner)}
*/
@Deprecated
protected void printBanner(Environment environment) {
this.printedCustomBannerViaDeprecatedMethod = false;
}
/**
* Strategy method used to create the {@link ApplicationContext}. By default this
* method will respect any explicitly set application context or application context
......
......@@ -28,14 +28,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySources;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
......@@ -68,8 +66,6 @@ public class PropertiesConfigurationFactory<T>
private boolean exceptionIfInvalid = true;
private Properties properties;
private PropertySources propertySources;
private final T target;
......@@ -161,17 +157,6 @@ public class PropertiesConfigurationFactory<T>
this.messageSource = messageSource;
}
/**
* Set the properties.
* @param properties the properties
* @deprecated as of 1.4 in favor of {@link #setPropertySources(PropertySources)
* setPropertySources} that contains a {@link PropertiesPropertySource}.
*/
@Deprecated
public void setProperties(Properties properties) {
this.properties = properties;
}
/**
* Set the property sources.
* @param propertySources the property sources
......@@ -241,16 +226,12 @@ public class PropertiesConfigurationFactory<T>
}
public void bindPropertiesToTarget() throws BindException {
Assert.state(this.properties != null || this.propertySources != null,
"Properties or propertySources should not be null");
Assert.state(this.propertySources != null,
"PropertySources should not be null");
try {
if (this.logger.isTraceEnabled()) {
if (this.properties != null) {
this.logger.trace(String.format("Properties:%n%s", this.properties));
}
else {
this.logger.trace("Property Sources: " + this.propertySources);
}
this.logger.trace("Property Sources: " + this.propertySources);
}
this.hasBeenBound = true;
doBindPropertiesToTarget();
......@@ -281,7 +262,7 @@ public class PropertiesConfigurationFactory<T>
customizeBinder(dataBinder);
Iterable<String> relaxedTargetNames = getRelaxedTargetNames();
Set<String> names = getNames(relaxedTargetNames);
PropertyValues propertyValues = getPropertyValues(names, relaxedTargetNames);
PropertyValues propertyValues = getPropertySourcesPropertyValues(names, relaxedTargetNames);
dataBinder.bind(propertyValues);
if (this.validator != null) {
validate(dataBinder);
......@@ -321,14 +302,6 @@ public class PropertiesConfigurationFactory<T>
return names;
}
private PropertyValues getPropertyValues(Set<String> names,
Iterable<String> relaxedTargetNames) {
if (this.properties != null) {
return new MutablePropertyValues(this.properties);
}
return getPropertySourcesPropertyValues(names, relaxedTargetNames);
}
private PropertyValues getPropertySourcesPropertyValues(Set<String> names,
Iterable<String> relaxedTargetNames) {
PropertyNamePatternsMatcher includes = getPropertyNamePatternsMatcher(names,
......
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.embedded;
import javax.servlet.Filter;
import javax.servlet.ServletContext;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.web.filter.DelegatingFilterProxy;
/**
* A {@link ServletContextInitializer} to register {@link DelegatingFilterProxy}s in a
* Servlet 3.0+ container. Similar to the {@link ServletContext#addFilter(String, Filter)
* registration} features provided by {@link ServletContext} but with a Spring Bean
* friendly design.
* <p>
* The bean name of the actual delegate {@link Filter} should be specified using the
* {@code targetBeanName} constructor argument. Unlike the {@link FilterRegistrationBean},
* referenced filters are not instantiated early. In fact, if the delegate filter bean is
* marked {@code @Lazy} it won't be instantiated at all until the filter is called.
* <p>
* Registrations can be associated with {@link #setUrlPatterns URL patterns} and/or
* servlets (either by {@link #setServletNames name} or via a
* {@link #setServletRegistrationBeans ServletRegistrationBean}s. When no URL pattern or
* servlets are specified the filter will be associated to '/*'. The targetBeanName will
* be used as the filter name if not otherwise specified.
*
* @author Phillip Webb
* @since 1.3.0
* @see ServletContextInitializer
* @see ServletContext#addFilter(String, Filter)
* @see FilterRegistrationBean
* @see DelegatingFilterProxy
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean}
*/
@Deprecated
public class DelegatingFilterProxyRegistrationBean
extends org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean
implements org.springframework.boot.context.embedded.ServletContextInitializer {
public DelegatingFilterProxyRegistrationBean(String targetBeanName,
ServletRegistrationBean... servletRegistrationBeans) {
super(targetBeanName, servletRegistrationBeans);
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.embedded;
import org.springframework.http.HttpStatus;
/**
* Simple container-independent abstraction for servlet error pages. Roughly equivalent to
* the {@literal <error-page>} element traditionally found in web.xml.
*
* @author Dave Syer
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.servlet.ErrorPage}
*/
@Deprecated
public class ErrorPage extends org.springframework.boot.web.servlet.ErrorPage {
public ErrorPage(Class<? extends Throwable> exception, String path) {
super(exception, path);
}
public ErrorPage(HttpStatus status, String path) {
super(status, path);
}
public ErrorPage(String path) {
super(path);
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.embedded;
import javax.servlet.Filter;
import javax.servlet.ServletContext;
import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean;
import org.springframework.boot.web.servlet.ServletContextInitializer;
/**
* A {@link ServletContextInitializer} to register {@link Filter}s in a Servlet 3.0+
* container. Similar to the {@link ServletContext#addFilter(String, Filter) registration}
* features provided by {@link ServletContext} but with a Spring Bean friendly design.
* <p>
* The {@link #setFilter(Filter) Filter} must be specified before calling
* {@link #onStartup(ServletContext)}. Registrations can be associated with
* {@link #setUrlPatterns URL patterns} and/or servlets (either by {@link #setServletNames
* name} or via a {@link #setServletRegistrationBeans ServletRegistrationBean}s. When no
* URL pattern or servlets are specified the filter will be associated to '/*'. The filter
* name will be deduced if not specified.
*
* @author Phillip Webb
* @see ServletContextInitializer
* @see ServletContext#addFilter(String, Filter)
* @see DelegatingFilterProxyRegistrationBean
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.servlet.FilterRegistrationBean}
*/
@Deprecated
public class FilterRegistrationBean
extends org.springframework.boot.web.servlet.FilterRegistrationBean
implements org.springframework.boot.context.embedded.ServletContextInitializer {
public FilterRegistrationBean() {
super();
}
public FilterRegistrationBean(Filter filter,
ServletRegistrationBean... servletRegistrationBeans) {
super(filter, servletRegistrationBeans);
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.embedded;
import javax.servlet.MultipartConfigElement;
/**
* Factory that can be used to create a {@link MultipartConfigElement}. Size values can be
* set using traditional {@literal long} values which are set in bytes or using more
* readable {@literal String} variants that accept KB or MB suffixes, for example:
*
* <pre class="code">
* factory.setMaxFileSize(&quot;10Mb&quot;);
* factory.setMaxRequestSize(&quot;100Kb&quot;);
* </pre>
*
* @author Phillip Webb
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.servlet.MultipartConfigFactory}
*/
@Deprecated
public class MultipartConfigFactory
extends org.springframework.boot.web.servlet.MultipartConfigFactory {
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.embedded;
import javax.servlet.ServletContext;
import org.springframework.web.SpringServletContainerInitializer;
import org.springframework.web.WebApplicationInitializer;
/**
* Interface used to configure a Servlet 3.0+ {@link ServletContext context}
* programmatically. Unlike {@link WebApplicationInitializer}, classes that implement this
* interface (and do not implement {@link WebApplicationInitializer}) will <b>not</b> be
* detected by {@link SpringServletContainerInitializer} and hence will not be
* automatically bootstrapped by the Servlet container.
* <p>
* This interface is primarily designed to allow {@link ServletContextInitializer}s to be
* managed by Spring and not the Servlet container.
* <p>
* For configuration examples see {@link WebApplicationInitializer}.
*
* @author Phillip Webb
* @see WebApplicationInitializer
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.servlet.ServletContextInitializer}
*/
@Deprecated
public interface ServletContextInitializer
extends org.springframework.boot.web.servlet.ServletContextInitializer {
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.embedded;
import java.util.EventListener;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionListener;
import org.springframework.boot.web.servlet.ServletContextInitializer;
/**
* A {@link ServletContextInitializer} to register {@link EventListener}s in a Servlet
* 3.0+ container. Similar to the {@link ServletContext#addListener(EventListener)
* registration} features provided by {@link ServletContext} but with a Spring Bean
* friendly design.
*
* This bean can be used to register the following types of listener:
* <ul>
* <li>{@link ServletContextAttributeListener}</li>
* <li>{@link ServletRequestListener}</li>
* <li>{@link ServletRequestAttributeListener}</li>
* <li>{@link HttpSessionAttributeListener}</li>
* <li>{@link HttpSessionListener}</li>
* <li>{@link ServletContextListener}</li>
* </ul>
*
* @param <T> the type of listener
* @author Dave Syer
* @author Phillip Webb
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.servlet.ServletListenerRegistrationBean}
*/
@Deprecated
public class ServletListenerRegistrationBean<T extends EventListener>
extends org.springframework.boot.web.servlet.ServletListenerRegistrationBean<T>
implements org.springframework.boot.context.embedded.ServletContextInitializer {
public ServletListenerRegistrationBean() {
super();
}
public ServletListenerRegistrationBean(T listener) {
super(listener);
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.embedded;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import org.springframework.boot.web.servlet.ServletContextInitializer;
/**
* A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+
* container. Similar to the {@link ServletContext#addServlet(String, Servlet)
* registration} features provided by {@link ServletContext} but with a Spring Bean
* friendly design.
* <p>
* The {@link #setServlet(Servlet) servlet} must be specified before calling
* {@link #onStartup}. URL mapping can be configured used {@link #setUrlMappings} or
* omitted when mapping to '/*' (unless
* {@link #ServletRegistrationBean(Servlet, boolean, String...) alwaysMapUrl} is set to
* {@code false}). The servlet name will be deduced if not specified.
*
* @author Phillip Webb
* @see ServletContextInitializer
* @see ServletContext#addServlet(String, Servlet)
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.servlet.ServletRegistrationBean}
*/
@Deprecated
public class ServletRegistrationBean
extends org.springframework.boot.web.servlet.ServletRegistrationBean
implements org.springframework.boot.context.embedded.ServletContextInitializer {
public ServletRegistrationBean() {
super();
}
public ServletRegistrationBean(Servlet servlet, boolean alwaysMapUrl,
String... urlMappings) {
super(servlet, alwaysMapUrl, urlMappings);
}
public ServletRegistrationBean(Servlet servlet, String... urlMappings) {
super(servlet, urlMappings);
}
}
......@@ -606,17 +606,6 @@ public class TomcatEmbeddedServletContainerFactory
this.contextValves = new ArrayList<Valve>(contextValves);
}
/**
* Returns a mutable collection of the {@link Valve}s that will be applied to the
* Tomcat {@link Context}.
* @return the contextValves the valves that will be applied
* @deprecated as of 1.4 in favor of {@link #getContextValves()}
*/
@Deprecated
public Collection<Valve> getValves() {
return getContextValves();
}
/**
* Returns a mutable collection of the {@link Valve}s that will be applied to the
* Tomcat {@link Context}.
......
......@@ -90,63 +90,6 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine
private boolean started = false;
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
* @param manager the deployment manager
* @param contextPath the root context path
* @param port the port to listen on (not used)
* @param autoStart if the server should be started
* @param compression compression configuration
* @deprecated as of 1.4 in favor of
* {@link #UndertowEmbeddedServletContainer(Undertow.Builder, DeploymentManager, String, boolean, Compression)}
*/
@Deprecated
public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager,
String contextPath, int port, boolean autoStart, Compression compression) {
this(builder, manager, contextPath, false, autoStart, compression);
}
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
* @param manager the deployment manager
* @param contextPath the root context path
* @param port the port to listen on (not used)
* @param useForwardHeaders if x-forward headers should be used
* @param autoStart if the server should be started
* @param compression compression configuration
* @deprecated as of 1.4 in favor of
* {@link #UndertowEmbeddedServletContainer(Undertow.Builder, DeploymentManager, String, boolean, boolean, Compression)}
*/
@Deprecated
public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager,
String contextPath, int port, boolean useForwardHeaders, boolean autoStart,
Compression compression) {
this(builder, manager, contextPath, useForwardHeaders, autoStart, compression);
}
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
* @param manager the deployment manager
* @param contextPath the root context path
* @param port the port to listen on (not used)
* @param useForwardHeaders if x-forward headers should be used
* @param autoStart if the server should be started
* @param compression compression configuration
* @param serverHeader string to be used in HTTP header
* @deprecated as of 1.4 in favor of
* {@link #UndertowEmbeddedServletContainer(Undertow.Builder, DeploymentManager, String, boolean, boolean, Compression, String)}
*/
@Deprecated
public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager,
String contextPath, int port, boolean useForwardHeaders, boolean autoStart,
Compression compression, String serverHeader) {
this(builder, manager, contextPath, useForwardHeaders, autoStart, compression,
serverHeader);
}
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
......
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.web;
import javax.servlet.Filter;
import org.springframework.boot.web.servlet.ErrorPageRegistrar;
import org.springframework.boot.web.servlet.ErrorPageRegistry;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
/**
* A Servlet {@link Filter} that provides an {@link ErrorPageRegistry} for non-embedded
* applications (i.e. deployed WAR files). It registers error pages and handles
* application errors by filtering requests and forwarding to the error pages instead of
* letting the container handle them. Error pages are a feature of the servlet spec but
* there is no Java API for registering them in the spec. This filter works around that by
* accepting error page registrations from Spring Boot's {@link ErrorPageRegistrar} (any
* beans of that type in the context will be applied to this container).
*
* @author Dave Syer
* @author Phillip Webb
* @author Andy Wilkinson
* @since 1.4.0
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.support.ErrorPageFilter}
*/
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
@Deprecated
public class ErrorPageFilter extends org.springframework.boot.web.support.ErrorPageFilter
implements NonEmbeddedServletContainerFactory {
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.web;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.ErrorPageRegistry;
/**
* Marker interface for {@link EmbeddedServletContainerFactory} types that are actually
* safe to run in a non-embedded container.
*
* @author Dave Syer
* @deprecated as of 1.4 in favor of {@link ErrorPageRegistry}
*/
@Deprecated
public interface NonEmbeddedServletContainerFactory {
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.web;
import org.springframework.core.Ordered;
import org.springframework.web.filter.CharacterEncodingFilter;
/**
* {@link CharacterEncodingFilter} that also implements {@link Ordered}.
*
* @author Phillip Webb
* @since 1.2.1
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.filter.OrderedCharacterEncodingFilter}
*/
@Deprecated
public class OrderedCharacterEncodingFilter
extends org.springframework.boot.web.filter.OrderedCharacterEncodingFilter {
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.web;
import org.springframework.core.Ordered;
import org.springframework.web.filter.HiddenHttpMethodFilter;
/**
* {@link HiddenHttpMethodFilter} that also implements {@link Ordered}.
*
* @author Phillip Webb
* @since 1.2.4
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.filter.OrderedHiddenHttpMethodFilter}
*/
@Deprecated
public class OrderedHiddenHttpMethodFilter
extends org.springframework.boot.web.filter.OrderedHiddenHttpMethodFilter {
/**
* The default order is high to ensure the filter is applied before Spring Security.
*/
public static final int DEFAULT_ORDER = org.springframework.boot.web.filter.OrderedHiddenHttpMethodFilter.DEFAULT_ORDER;
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.web;
import org.springframework.core.Ordered;
import org.springframework.web.filter.HttpPutFormContentFilter;
/**
* {@link HttpPutFormContentFilter} that also implements {@link Ordered}.
*
* @author Joao Pedro Evangelista
* @since 1.3.0
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter}
*/
@Deprecated
public class OrderedHttpPutFormContentFilter
extends org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter {
/**
* Higher order to ensure the filter is applied before Spring Security.
*/
public static final int DEFAULT_ORDER = org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter.DEFAULT_ORDER;
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.web;
import org.springframework.core.Ordered;
import org.springframework.web.filter.RequestContextFilter;
/**
* {@link RequestContextFilter} that also implements {@link Ordered}.
*
* @author Phillip Webb
* @since 1.3.0
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.filter.OrderedRequestContextFilter}
*/
@Deprecated
public class OrderedRequestContextFilter
extends org.springframework.boot.web.filter.OrderedRequestContextFilter {
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.web;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.EmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.core.env.Environment;
/**
* {@link ApplicationContextInitializer} that sets {@link Environment} properties for the
* ports that {@link EmbeddedServletContainer} servers are actually listening on. The
* property {@literal "local.server.port"} can be injected directly into tests using
* {@link Value @Value} or obtained via the {@link Environment}.
* <p>
* If the {@link EmbeddedWebApplicationContext} has a
* {@link EmbeddedWebApplicationContext#setNamespace(String) namespace} set, it will be
* used to construct the property name. For example, the "management" actuator context
* will have the property name {@literal "local.management.port"}.
* <p>
* Properties are automatically propagated up to any parent context.
*
* @author Dave Syer
* @author Phillip Webb
* @since 1.3.0
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer}
*/
@Deprecated
public class ServerPortInfoApplicationContextInitializer extends
org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer {
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.web;
import javax.servlet.ServletContext;
import org.springframework.context.ApplicationContextInitializer;
/**
* {@link ApplicationContextInitializer} for setting the servlet context.
*
* @author Dave Syer
* @author Phillip Webb
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.support.ServletContextApplicationContextInitializer}
*/
@Deprecated
public class ServletContextApplicationContextInitializer extends
org.springframework.boot.web.support.ServletContextApplicationContextInitializer {
public ServletContextApplicationContextInitializer(ServletContext servletContext,
boolean addApplicationContextAttribute) {
super(servletContext, addApplicationContextAttribute);
}
public ServletContextApplicationContextInitializer(ServletContext servletContext) {
super(servletContext);
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.context.web;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.web.WebApplicationInitializer;
/**
* An opinionated {@link WebApplicationInitializer} to run a {@link SpringApplication}
* from a traditional WAR deployment. Binds {@link Servlet}, {@link Filter} and
* {@link ServletContextInitializer} beans from the application context to the servlet
* container.
* <p>
* To configure the application either override the
* {@link #configure(SpringApplicationBuilder)} method (calling
* {@link SpringApplicationBuilder#sources(Object...)}) or make the initializer itself a
* {@code @Configuration}. If you are using {@link SpringBootServletInitializer} in
* combination with other {@link WebApplicationInitializer WebApplicationInitializers} you
* might also want to add an {@code @Ordered} annotation to configure a specific startup
* order.
* <p>
* Note that a WebApplicationInitializer is only needed if you are building a war file and
* deploying it. If you prefer to run an embedded container then you won't need this at
* all.
*
* @author Dave Syer
* @author Phillip Webb
* @author Andy Wilkinson
* @see #configure(SpringApplicationBuilder)
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.web.support.SpringBootServletInitializer}
*/
@Deprecated
public abstract class SpringBootServletInitializer
extends org.springframework.boot.web.support.SpringBootServletInitializer {
}
/*
* Copyright 2012-2014 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
*
* http://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.
*/
/**
* Spring {@link org.springframework.context.ApplicationContext} support relating to web
* deployment.
*/
package org.springframework.boot.context.web;
......@@ -135,18 +135,4 @@ public final class FailureAnalyzers {
return true;
}
/**
* Analyze and report the specified {@code failure}.
* @param failure the failure to analyze
* @param classLoader the classloader to use
* @param context the context to use
* @return {@code true} if the failure was handled
* @deprecated as of 1.4.1 in favor of {@link #analyzeAndReport(Throwable)}
*/
@Deprecated
public static boolean analyzeAndReport(Throwable failure, ClassLoader classLoader,
ConfigurableApplicationContext context) {
return new FailureAnalyzers(context, classLoader).analyzeAndReport(failure);
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.orm.jpa;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.AliasFor;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
/**
* Configures the {@link LocalContainerEntityManagerFactoryBean} to scan for entity
* classes in the classpath. This annotation provides an alternative to manually setting
* {@link LocalContainerEntityManagerFactoryBean#setPackagesToScan(String...)} and is
* particularly useful if you want to configure entity scanning in a type-safe way, or if
* your {@link LocalContainerEntityManagerFactoryBean} is auto-configured.
* <p>
* A {@link LocalContainerEntityManagerFactoryBean} must be configured within your Spring
* ApplicationContext in order to use entity scanning. Furthermore, any existing
* {@code packagesToScan} setting will be replaced.
* <p>
* One of {@link #basePackageClasses()}, {@link #basePackages()} or its alias
* {@link #value()} may be specified to define specific packages to scan. If specific
* packages are not defined scanning will occur from the package of the class with this
* annotation.
*
* @author Phillip Webb
* @deprecated as of 1.4 in favor of
* {@code org.springframework.boot.autoconfigure.domain.EntityScan} or explicit
* configuration of the {@link LocalContainerEntityManagerFactoryBean} (either
* {@link LocalContainerEntityManagerFactoryBean#setPackagesToScan(String...) directly} or
* using the {@link EntityManagerFactoryBuilder.Builder#packages(Class...)
* EntityManagerFactoryBuilder}).
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(EntityScanRegistrar.class)
@Deprecated
public @interface EntityScan {
/**
* Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
* declarations e.g.: {@code @EntityScan("org.my.pkg")} instead of
* {@code @EntityScan(basePackages="org.my.pkg")}.
* @return the base packages to scan
*/
@AliasFor("basePackages")
String[] value() default {};
/**
* Base packages to scan for annotated entities. {@link #value()} is an alias for (and
* mutually exclusive with) this attribute.
* <p>
* Use {@link #basePackageClasses()} for a type-safe alternative to String-based
* package names.
* @return the base packages to scan
*/
@AliasFor("value")
String[] basePackages() default {};
/**
* Type-safe alternative to {@link #basePackages()} for specifying the packages to
* scan for annotated entities. The package of each class specified will be scanned.
* <p>
* Consider creating a special no-op marker class or interface in each package that
* serves no purpose other than being referenced by this attribute.
* @return classes from the base packages to scan
*/
Class<?>[] basePackageClasses() default {};
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.orm.jpa;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* {@link ImportBeanDefinitionRegistrar} used by {@link EntityScan}.
*
* @author Phillip Webb
* @author Oliver Gierke
* @deprecated as of 1.4 along with {@link EntityScan}
*/
@Deprecated
class EntityScanRegistrar implements ImportBeanDefinitionRegistrar {
private static final String BEAN_NAME = "entityScanBeanPostProcessor";
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
BeanDefinitionRegistry registry) {
Set<String> packagesToScan = getPackagesToScan(importingClassMetadata);
if (!registry.containsBeanDefinition(BEAN_NAME)) {
addEntityScanBeanPostProcessor(registry, packagesToScan);
}
else {
updateEntityScanBeanPostProcessor(registry, packagesToScan);
}
}
private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
AnnotationAttributes attributes = AnnotationAttributes
.fromMap(metadata.getAnnotationAttributes(EntityScan.class.getName()));
String[] basePackages = attributes.getAliasedStringArray("basePackages",
EntityScan.class, metadata.getClassName());
Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
Set<String> packagesToScan = new LinkedHashSet<String>();
packagesToScan.addAll(Arrays.asList(basePackages));
for (Class<?> basePackageClass : basePackageClasses) {
packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
}
if (packagesToScan.isEmpty()) {
return Collections
.singleton(ClassUtils.getPackageName(metadata.getClassName()));
}
return packagesToScan;
}
private void addEntityScanBeanPostProcessor(BeanDefinitionRegistry registry,
Set<String> packagesToScan) {
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(EntityScanBeanPostProcessor.class);
beanDefinition.getConstructorArgumentValues()
.addGenericArgumentValue(toArray(packagesToScan));
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
// We don't need this one to be post processed otherwise it can cause a
// cascade of bean instantiation that we would rather avoid.
beanDefinition.setSynthetic(true);
registry.registerBeanDefinition(BEAN_NAME, beanDefinition);
}
private void updateEntityScanBeanPostProcessor(BeanDefinitionRegistry registry,
Set<String> packagesToScan) {
BeanDefinition definition = registry.getBeanDefinition(BEAN_NAME);
ValueHolder constructorArguments = definition.getConstructorArgumentValues()
.getGenericArgumentValue(String[].class);
Set<String> mergedPackages = new LinkedHashSet<String>();
mergedPackages.addAll(Arrays.asList((String[]) constructorArguments.getValue()));
mergedPackages.addAll(packagesToScan);
constructorArguments.setValue(toArray(mergedPackages));
}
private String[] toArray(Set<String> set) {
return set.toArray(new String[set.size()]);
}
/**
* {@link BeanPostProcessor} to set
* {@link LocalContainerEntityManagerFactoryBean#setPackagesToScan(String...)} based
* on an {@link EntityScan} annotation.
*/
static class EntityScanBeanPostProcessor
implements BeanPostProcessor, SmartInitializingSingleton, Ordered {
private final String[] packagesToScan;
private boolean processed;
EntityScanBeanPostProcessor(String[] packagesToScan) {
this.packagesToScan = packagesToScan;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
if (bean instanceof LocalContainerEntityManagerFactoryBean) {
LocalContainerEntityManagerFactoryBean factoryBean = (LocalContainerEntityManagerFactoryBean) bean;
factoryBean.setPackagesToScan(this.packagesToScan);
this.processed = true;
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
@Override
public void afterSingletonsInstantiated() {
Assert.state(this.processed,
"Unable to configure "
+ "LocalContainerEntityManagerFactoryBean from @EntityScan, "
+ "ensure an appropriate bean is registered.");
}
@Override
public int getOrder() {
return 0;
}
}
}
/*
* Copyright 2012-2015 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
*
* http://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.boot.yaml;
import java.util.Collections;
import java.util.Properties;
import java.util.Set;
import org.springframework.beans.factory.config.YamlProcessor.DocumentMatcher;
import org.springframework.beans.factory.config.YamlProcessor.MatchStatus;
import org.springframework.util.StringUtils;
/**
* Matches a document containing a given key and where the value of that key is an array
* containing one of the given values, or where one of the values matches one of the given
* values (interpreted as regexes).
*
* @author Dave Syer
* @deprecated as of 1.4.1 in favor of exact String-based matching
*/
@Deprecated
public class ArrayDocumentMatcher implements DocumentMatcher {
private final String key;
private final String[] patterns;
public ArrayDocumentMatcher(final String key, final String... patterns) {
this.key = key;
this.patterns = patterns;
}
@Override
public MatchStatus matches(Properties properties) {
if (!properties.containsKey(this.key)) {
return MatchStatus.ABSTAIN;
}
Set<String> values = StringUtils
.commaDelimitedListToSet(properties.getProperty(this.key));
if (values.isEmpty()) {
values = Collections.singleton("");
}
for (String pattern : this.patterns) {
for (String value : values) {
if (value.matches(pattern)) {
return MatchStatus.FOUND;
}
}
}
return MatchStatus.NOT_FOUND;
}
}
/*
* Copyright 2012-2014 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
*
* http://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.boot.yaml;
import java.util.Properties;
import org.springframework.beans.factory.config.YamlProcessor.DocumentMatcher;
import org.springframework.beans.factory.config.YamlProcessor.MatchStatus;
/**
* A {@link DocumentMatcher} that matches the default profile implicitly but not
* explicitly (i.e. matches if "spring.profiles" is not found and not otherwise).
*
* @author Dave Syer
* @deprecated since 1.4.1 as it is no longer used
*/
@Deprecated
public class DefaultProfileDocumentMatcher implements DocumentMatcher {
@Override
public MatchStatus matches(Properties properties) {
if (!properties.containsKey("spring.profiles")) {
return MatchStatus.FOUND;
}
return MatchStatus.NOT_FOUND;
}
}
......@@ -12,7 +12,7 @@ org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\
org.springframework.boot.context.ContextIdApplicationContextInitializer,\
org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\
org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer
org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer
# Application Listeners
org.springframework.context.ApplicationListener=\
......
......@@ -129,22 +129,6 @@ public class BannerTests {
assertThat(this.context.containsBean("springBootBanner")).isFalse();
}
@Test
public void testDeprecatePrintBanner() throws Exception {
SpringApplication application = new SpringApplication(Config.class) {
@Override
protected void printBanner(Environment environment) {
System.out.println("I printed a deprecated banner");
};
};
application.setWebEnvironment(false);
this.context = application.run();
assertThat(this.out.toString()).contains("I printed a deprecated banner");
assertThat(this.context.containsBean("springBootBanner")).isFalse();
}
static class DummyBanner implements Banner {
@Override
......
......@@ -81,7 +81,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.isA;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
......@@ -165,25 +164,6 @@ public class SpringApplicationTests {
new SpringApplication(InaccessibleConfiguration.class).run();
}
@Test
@Deprecated
public void disableBannerWithMode() throws Exception {
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
application.setWebEnvironment(false);
application.setBannerMode(Banner.Mode.OFF);
this.context = application.run();
verify(application, never()).printBanner((Environment) anyObject());
}
@Test
@Deprecated
public void disableBannerViaBannerModeProperty() throws Exception {
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
application.setWebEnvironment(false);
this.context = application.run("--spring.main.banner-mode=off");
verify(application, never()).printBanner((Environment) anyObject());
}
@Test
public void customBanner() throws Exception {
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
......
......@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.junit.Test;
......@@ -27,6 +28,7 @@ import org.springframework.context.support.StaticMessageSource;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.validation.Validator;
......@@ -95,10 +97,12 @@ public class PropertiesConfigurationFactoryMapTests {
return bindFoo(values);
}
@Deprecated
private Foo bindFoo(final String values) throws Exception {
this.factory.setProperties(PropertiesLoaderUtils
.loadProperties(new ByteArrayResource(values.getBytes())));
Properties properties = PropertiesLoaderUtils
.loadProperties(new ByteArrayResource(values.getBytes()));
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("test", properties));
this.factory.setPropertySources(propertySources);
this.factory.afterPropertiesSet();
return this.factory.getObject();
}
......
......@@ -43,8 +43,6 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(Parameterized.class)
public class PropertiesConfigurationFactoryParameterizedTests {
private final boolean usePropertySource;
private String targetName;
private PropertiesConfigurationFactory<Foo> factory = new PropertiesConfigurationFactory<Foo>(
......@@ -52,14 +50,11 @@ public class PropertiesConfigurationFactoryParameterizedTests {
@Parameters
public static Object[] parameters() {
return new Object[] { new Object[] { false, false }, new Object[] { false, true },
new Object[] { true, false }, new Object[] { true, true } };
return new Object[] { new Object[] { false }, new Object[] { true } };
}
public PropertiesConfigurationFactoryParameterizedTests(boolean ignoreUnknownFields,
boolean usePropertySource) {
public PropertiesConfigurationFactoryParameterizedTests(boolean ignoreUnknownFields) {
this.factory.setIgnoreUnknownFields(ignoreUnknownFields);
this.usePropertySource = usePropertySource;
}
@Test
......@@ -102,18 +97,12 @@ public class PropertiesConfigurationFactoryParameterizedTests {
return bindFoo(values);
}
@Deprecated
private Foo bindFoo(final String values) throws Exception {
Properties properties = PropertiesLoaderUtils
.loadProperties(new ByteArrayResource(values.getBytes()));
if (this.usePropertySource) {
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("test", properties));
this.factory.setPropertySources(propertySources);
}
else {
this.factory.setProperties(properties);
}
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("test", properties));
this.factory.setPropertySources(propertySources);
this.factory.afterPropertiesSet();
return this.factory.getObject();
......
......@@ -18,6 +18,7 @@ package org.springframework.boot.bind;
import java.io.IOException;
import java.util.Collections;
import java.util.Properties;
import javax.validation.Validation;
import javax.validation.constraints.NotNull;
......@@ -28,6 +29,7 @@ import org.springframework.beans.NotWritablePropertyException;
import org.springframework.boot.context.config.RandomValuePropertySource;
import org.springframework.context.support.StaticMessageSource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.env.SystemEnvironmentPropertySource;
import org.springframework.core.io.ByteArrayResource;
......@@ -56,6 +58,7 @@ public class PropertiesConfigurationFactoryTests {
@Test
public void testValidPropertiesLoadsWithDash() throws Exception {
this.ignoreUnknownFields = false;
Foo foo = createFoo("na-me: blah\nbar: blah");
assertThat(foo.bar).isEqualTo("blah");
assertThat(foo.name).isEqualTo("blah");
......@@ -210,10 +213,12 @@ public class PropertiesConfigurationFactoryTests {
return bindFoo(values);
}
@Deprecated
private Foo bindFoo(final String values) throws Exception {
this.factory.setProperties(PropertiesLoaderUtils
.loadProperties(new ByteArrayResource(values.getBytes())));
Properties properties = PropertiesLoaderUtils
.loadProperties(new ByteArrayResource(values.getBytes()));
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("test", properties));
this.factory.setPropertySources(propertySources);
this.factory.afterPropertiesSet();
return this.factory.getObject();
}
......
/*
* Copyright 2012-2016 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
*
* http://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.boot.orm.jpa;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.junit.Test;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link EntityManagerFactoryBuilder}.
*
* @author Dave Syer
*/
@Deprecated
public class EntityManagerFactoryBuilderTests {
private Map<String, Object> properties = new LinkedHashMap<String, Object>();
private DataSource dataSource1 = mock(DataSource.class);
private DataSource dataSource2 = mock(DataSource.class);
@Test
public void entityManagerFactoryPropertiesNotOverwritingDefaults() {
EntityManagerFactoryBuilder factory = new EntityManagerFactoryBuilder(
new HibernateJpaVendorAdapter(), this.properties, null);
LocalContainerEntityManagerFactoryBean result1 = factory
.dataSource(this.dataSource1)
.properties(Collections.singletonMap("foo", "spam")).build();
assertThat(result1.getJpaPropertyMap().isEmpty()).isFalse();
assertThat(this.properties.isEmpty()).isTrue();
}
@Test
public void multipleEntityManagerFactoriesDoNotOverwriteEachOther() {
EntityManagerFactoryBuilder factory = new EntityManagerFactoryBuilder(
new HibernateJpaVendorAdapter(), this.properties, null);
LocalContainerEntityManagerFactoryBean result1 = factory
.dataSource(this.dataSource1)
.properties(Collections.singletonMap("foo", "spam")).build();
assertThat(result1.getJpaPropertyMap().isEmpty()).isFalse();
LocalContainerEntityManagerFactoryBean result2 = factory
.dataSource(this.dataSource2).build();
assertThat(result2.getJpaPropertyMap().isEmpty()).isTrue();
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.orm.jpa;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link EntityScan}.
*
* @author Phillip Webb
* @author Stephane Nicoll
*/
@Deprecated
public class EntityScanTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private AnnotationConfigApplicationContext context;
@After
public void closeContext() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void simpleValue() throws Exception {
this.context = new AnnotationConfigApplicationContext(ValueConfig.class);
assertSetPackagesToScan("com.mycorp.entity");
}
@Test
public void simpleValueAsm() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.registerBeanDefinition("valueConfig",
new RootBeanDefinition(ValueConfig.class.getName()));
this.context.refresh();
assertSetPackagesToScan("com.mycorp.entity");
}
@Test
public void needsEntityManageFactory() throws Exception {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to configure "
+ "LocalContainerEntityManagerFactoryBean from @EntityScan, "
+ "ensure an appropriate bean is registered.");
this.context = new AnnotationConfigApplicationContext(MissingEntityManager.class);
}
@Test
public void userDeclaredBeanPostProcessorWithEntityManagerDependencyDoesNotPreventConfigurationOfPackagesToScan() {
this.context = new AnnotationConfigApplicationContext(
BeanPostProcessorConfiguration.class, BaseConfig.class);
assertSetPackagesToScan("com.mycorp.entity");
}
private void assertSetPackagesToScan(String... expected) {
String[] actual = this.context
.getBean(TestLocalContainerEntityManagerFactoryBean.class)
.getPackagesToScan();
assertThat(actual).isEqualTo(expected);
}
@Configuration
static class BaseConfig {
@Bean
public TestLocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
return new TestLocalContainerEntityManagerFactoryBean();
}
}
@EntityScan("com.mycorp.entity")
@SuppressWarnings("deprecation")
static class ValueConfig extends BaseConfig {
}
@Configuration
@EntityScan("com.mycorp.entity")
@SuppressWarnings("deprecation")
static class MissingEntityManager {
}
@Configuration
@EntityScan("com.mycorp.entity")
@SuppressWarnings("deprecation")
static class BeanPostProcessorConfiguration {
protected final EntityManagerFactory entityManagerFactory;
BeanPostProcessorConfiguration(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
@Bean
public BeanPostProcessor beanPostProcessor() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean,
String beanName) throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
};
}
}
private static class TestLocalContainerEntityManagerFactoryBean
extends LocalContainerEntityManagerFactoryBean {
private String[] packagesToScan;
@Override
protected EntityManagerFactory createNativeEntityManagerFactory()
throws PersistenceException {
return mock(EntityManagerFactory.class);
}
@Override
public void setPackagesToScan(String... packagesToScan) {
this.packagesToScan = packagesToScan;
}
public String[] getPackagesToScan() {
return this.packagesToScan;
}
}
}
/*
* Copyright 2012-2016 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
*
* http://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.boot.yaml;
import java.io.IOException;
import java.util.Properties;
import org.junit.Test;
import org.springframework.beans.factory.config.YamlProcessor.MatchStatus;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ArrayDocumentMatcher}.
*
* @author Dave Syer
*/
@Deprecated
public class ArrayDocumentMatcherTests {
@Test
public void testMatchesSingleValue() throws IOException {
ArrayDocumentMatcher matcher = new ArrayDocumentMatcher("foo", "bar");
assertThat(matcher.matches(getProperties("foo: bar")))
.isEqualTo(MatchStatus.FOUND);
}
@Test
public void testDoesNotMatchesIndexedArray() throws IOException {
ArrayDocumentMatcher matcher = new ArrayDocumentMatcher("foo", "bar");
assertThat(matcher.matches(getProperties("foo[0]: bar\nfoo[1]: spam")))
.isEqualTo(MatchStatus.ABSTAIN);
}
@Test
public void testMatchesCommaSeparatedArray() throws IOException {
ArrayDocumentMatcher matcher = new ArrayDocumentMatcher("foo", "bar");
assertThat(matcher.matches(getProperties("foo: bar,spam")))
.isEqualTo(MatchStatus.FOUND);
}
private Properties getProperties(String values) throws IOException {
return PropertiesLoaderUtils
.loadProperties(new ByteArrayResource(values.getBytes()));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment