Browse Source
Since GenericPropertiesContextLoader was deprecated in Spring Framework 5.3, we have decided to remove it in Spring Framework 6.0. Closes gh-28911pull/28912/head
Sam Brannen
2 years ago
10 changed files with 1 additions and 434 deletions
@ -1,74 +0,0 @@
@@ -1,74 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2020 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.test.context.support; |
||||
|
||||
import java.util.Properties; |
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader; |
||||
import org.springframework.context.support.GenericApplicationContext; |
||||
import org.springframework.test.context.MergedContextConfiguration; |
||||
import org.springframework.util.ObjectUtils; |
||||
|
||||
/** |
||||
* Concrete implementation of {@link AbstractGenericContextLoader} that reads |
||||
* bean definitions from Java {@link Properties} resources. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 2.5 |
||||
* @deprecated as of 5.3, in favor of Spring's common bean definition formats |
||||
* and/or custom loader implementations |
||||
*/ |
||||
@Deprecated |
||||
public class GenericPropertiesContextLoader extends AbstractGenericContextLoader { |
||||
|
||||
/** |
||||
* Creates a new {@link org.springframework.beans.factory.support.PropertiesBeanDefinitionReader}. |
||||
* @return a new PropertiesBeanDefinitionReader |
||||
* @see org.springframework.beans.factory.support.PropertiesBeanDefinitionReader |
||||
*/ |
||||
@Override |
||||
protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) { |
||||
return new org.springframework.beans.factory.support.PropertiesBeanDefinitionReader(context); |
||||
} |
||||
|
||||
/** |
||||
* Returns "{@code -context.properties}". |
||||
*/ |
||||
@Override |
||||
protected String getResourceSuffix() { |
||||
return "-context.properties"; |
||||
} |
||||
|
||||
/** |
||||
* Ensure that the supplied {@link MergedContextConfiguration} does not |
||||
* contain {@link MergedContextConfiguration#getClasses() classes}. |
||||
* @since 4.0.4 |
||||
* @see AbstractGenericContextLoader#validateMergedContextConfiguration |
||||
*/ |
||||
@Override |
||||
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) { |
||||
if (mergedConfig.hasClasses()) { |
||||
String msg = String.format( |
||||
"Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, " |
||||
+ "but %s does not support annotated classes.", mergedConfig.getTestClass().getName(), |
||||
ObjectUtils.nullSafeToString(mergedConfig.getClasses()), getClass().getSimpleName()); |
||||
logger.error(msg); |
||||
throw new IllegalStateException(msg); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.test.context.configuration; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.testfixture.beans.Pet; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.ContextLoader; |
||||
import org.springframework.test.context.junit4.PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests which verify that the same custom {@link ContextLoader} can |
||||
* be used at all levels within a test class hierarchy when the |
||||
* {@code loader} is <i>inherited</i> (i.e., not explicitly declared) via |
||||
* {@link ContextConfiguration @ContextConfiguration}. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 3.0 |
||||
* @see PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests |
||||
* @see ContextConfigurationWithPropertiesExtendingPropertiesTests |
||||
*/ |
||||
@ContextConfiguration |
||||
public class ContextConfigurationWithPropertiesExtendingPropertiesAndInheritedLoaderTests extends |
||||
PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests { |
||||
|
||||
@Autowired |
||||
private Pet dog; |
||||
|
||||
@Autowired |
||||
private String testString2; |
||||
|
||||
|
||||
@Test |
||||
public void verifyExtendedAnnotationAutowiredFields() { |
||||
assertThat(this.dog).as("The dog field should have been autowired.").isNotNull(); |
||||
assertThat(this.dog.getName()).isEqualTo("Fido"); |
||||
|
||||
assertThat(this.testString2).as("The testString2 field should have been autowired.").isNotNull(); |
||||
assertThat(this.testString2).isEqualTo("Test String #2"); |
||||
} |
||||
|
||||
} |
@ -1,61 +0,0 @@
@@ -1,61 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2020 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.test.context.configuration; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.testfixture.beans.Pet; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.ContextLoader; |
||||
import org.springframework.test.context.junit4.PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests which verify that the same custom {@link ContextLoader} can |
||||
* be used at all levels within a test class hierarchy when the |
||||
* {@code loader} is explicitly declared via {@link ContextConfiguration |
||||
* @ContextConfiguration}. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 3.0 |
||||
* @see PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests |
||||
* @see ContextConfigurationWithPropertiesExtendingPropertiesAndInheritedLoaderTests |
||||
*/ |
||||
@SuppressWarnings("deprecation") |
||||
@ContextConfiguration(loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) |
||||
public class ContextConfigurationWithPropertiesExtendingPropertiesTests extends |
||||
PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests { |
||||
|
||||
@Autowired |
||||
private Pet dog; |
||||
|
||||
@Autowired |
||||
private String testString2; |
||||
|
||||
|
||||
@Test |
||||
public void verifyExtendedAnnotationAutowiredFields() { |
||||
assertThat(this.dog).as("The dog field should have been autowired.").isNotNull(); |
||||
assertThat(this.dog.getName()).isEqualTo("Fido"); |
||||
|
||||
assertThat(this.testString2).as("The testString2 field should have been autowired.").isNotNull(); |
||||
assertThat(this.testString2).isEqualTo("Test String #2"); |
||||
} |
||||
|
||||
} |
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2020 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.test.context.junit4; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.testfixture.beans.Pet; |
||||
import org.springframework.test.context.BootstrapWith; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.ContextLoader; |
||||
import org.springframework.test.context.support.DefaultTestContextBootstrapper; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests which verify that a subclass of {@link DefaultTestContextBootstrapper} |
||||
* can specify a custom <em>default ContextLoader class</em> that overrides the standard |
||||
* default class name. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 3.0 |
||||
*/ |
||||
@RunWith(SpringRunner.class) |
||||
@BootstrapWith(CustomDefaultContextLoaderClassSpringRunnerTests.PropertiesBasedTestContextBootstrapper.class) |
||||
@ContextConfiguration("PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties") |
||||
public class CustomDefaultContextLoaderClassSpringRunnerTests { |
||||
|
||||
@Autowired |
||||
private Pet cat; |
||||
|
||||
@Autowired |
||||
private String testString; |
||||
|
||||
|
||||
@Test |
||||
public void verifyAnnotationAutowiredFields() { |
||||
assertThat(this.cat).as("The cat field should have been autowired.").isNotNull(); |
||||
assertThat(this.cat.getName()).isEqualTo("Garfield"); |
||||
|
||||
assertThat(this.testString).as("The testString field should have been autowired.").isNotNull(); |
||||
assertThat(this.testString).isEqualTo("Test String"); |
||||
} |
||||
|
||||
|
||||
public static class PropertiesBasedTestContextBootstrapper extends DefaultTestContextBootstrapper { |
||||
|
||||
@Override |
||||
@SuppressWarnings("deprecation") |
||||
protected Class<? extends ContextLoader> getDefaultContextLoaderClass(Class<?> testClass) { |
||||
return org.springframework.test.context.support.GenericPropertiesContextLoader.class; |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,77 +0,0 @@
@@ -1,77 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.test.context.junit4; |
||||
|
||||
import java.util.Properties; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.testfixture.beans.Pet; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* <p> |
||||
* JUnit 4 based test class, which verifies the expected functionality of |
||||
* {@link SpringRunner} in conjunction with support for application contexts |
||||
* loaded from Java {@link Properties} files. Specifically, the |
||||
* {@link ContextConfiguration#loader() loader} attribute of {@code ContextConfiguration} |
||||
* and the |
||||
* {@link org.springframework.test.context.support.GenericPropertiesContextLoader#getResourceSuffix() |
||||
* resourceSuffix} property of {@code GenericPropertiesContextLoader} are tested. |
||||
* </p> |
||||
* <p> |
||||
* Since no {@link ContextConfiguration#locations() locations} are explicitly defined, the |
||||
* {@code resourceSuffix} is set to "-context.properties", and since default |
||||
* resource locations will be detected by default, this test class's dependencies will be |
||||
* injected via {@link Autowired annotation-based autowiring} from beans defined in the |
||||
* {@link ApplicationContext} loaded from the default classpath resource: " |
||||
* {@code /org/springframework/test/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties} |
||||
* ". |
||||
* </p> |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 2.5 |
||||
* @see org.springframework.test.context.support.GenericPropertiesContextLoader |
||||
* @see SpringJUnit4ClassRunnerAppCtxTests |
||||
*/ |
||||
@RunWith(SpringRunner.class) |
||||
@SuppressWarnings("deprecation") |
||||
@ContextConfiguration(loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) |
||||
public class PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests { |
||||
|
||||
@Autowired |
||||
private Pet cat; |
||||
|
||||
@Autowired |
||||
private String testString; |
||||
|
||||
|
||||
@Test |
||||
public void verifyAnnotationAutowiredFields() { |
||||
assertThat(this.cat).as("The cat field should have been autowired.").isNotNull(); |
||||
assertThat(this.cat.getName()).isEqualTo("Garfield"); |
||||
|
||||
assertThat(this.testString).as("The testString field should have been autowired.").isNotNull(); |
||||
assertThat(this.testString).isEqualTo("Test String"); |
||||
} |
||||
|
||||
} |
@ -1,47 +0,0 @@
@@ -1,47 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2020 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.test.context.support; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import org.springframework.test.context.MergedContextConfiguration; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
||||
|
||||
/** |
||||
* Unit tests for {@link GenericPropertiesContextLoader}. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 4.0.4 |
||||
*/ |
||||
@SuppressWarnings("deprecation") |
||||
class GenericPropertiesContextLoaderTests { |
||||
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0]; |
||||
|
||||
|
||||
@Test |
||||
void configMustNotContainAnnotatedClasses() throws Exception { |
||||
GenericPropertiesContextLoader loader = new GenericPropertiesContextLoader(); |
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, |
||||
new Class<?>[] { getClass() }, EMPTY_STRING_ARRAY, loader); |
||||
assertThatIllegalStateException() |
||||
.isThrownBy(() -> loader.loadContext(mergedConfig)) |
||||
.withMessageContaining("does not support annotated classes"); |
||||
} |
||||
|
||||
} |
@ -1,5 +0,0 @@
@@ -1,5 +0,0 @@
|
||||
cat.(class)=org.springframework.beans.testfixture.beans.Pet |
||||
cat.$0=Garfield |
||||
|
||||
testString.(class)=java.lang.String |
||||
testString.$0=Test String |
Loading…
Reference in new issue