diff --git a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/test/context/GeodeContextCustomizer.java b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/test/context/GeodeContextCustomizer.java new file mode 100644 index 0000000..bc39bc8 --- /dev/null +++ b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/test/context/GeodeContextCustomizer.java @@ -0,0 +1,49 @@ +/* + * Copyright 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.data.gemfire.tests.integration.test.context; + +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.data.gemfire.tests.extensions.spring.context.annotation.DependencyOfBeanFactoryPostProcessor; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport.TestContextCacheLifecycleListenerAdapter; +import org.springframework.lang.NonNull; +import org.springframework.test.context.ContextCustomizer; +import org.springframework.test.context.MergedContextConfiguration; + +/** + * Spring {@link ContextCustomizer} implementation used to register the {@link ConfigurableApplicationContext} + * with the {@link TestContextCacheLifecycleListenerAdapter} as an {@link ApplicationEventPublisher}. + * + * @author John Blum + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.test.context.ContextCustomizer + * @since 0.0.23 + */ +public class GeodeContextCustomizer implements ContextCustomizer { + + /** + * @inheritDoc + */ + @Override + public void customizeContext(@NonNull ConfigurableApplicationContext applicationContext, + @NonNull MergedContextConfiguration mergedConfig) { + + applicationContext.addBeanFactoryPostProcessor(new DependencyOfBeanFactoryPostProcessor()); + + TestContextCacheLifecycleListenerAdapter.getInstance().setApplicationEventPublisher(applicationContext); + } +} diff --git a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/test/context/GeodeContextCustomizerFactory.java b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/test/context/GeodeContextCustomizerFactory.java new file mode 100644 index 0000000..40a98d1 --- /dev/null +++ b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/test/context/GeodeContextCustomizerFactory.java @@ -0,0 +1,50 @@ +/* + * Copyright 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.data.gemfire.tests.integration.test.context; + +import java.util.List; + +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.lang.NonNull; +import org.springframework.test.context.ContextConfigurationAttributes; +import org.springframework.test.context.ContextCustomizer; +import org.springframework.test.context.ContextCustomizerFactory; +import org.springframework.test.context.TestContext; + +/** + * Spring {@link ContextCustomizerFactory} implementation to create a {@link GeodeContextCustomizer} + * used to customize the Spring {@link ConfigurableApplicationContext} created by + * the Spring {@link TestContext} framework. + * + * @author John Blum + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.data.gemfire.tests.integration.test.context.GeodeContextCustomizer + * @see org.springframework.test.context.ContextCustomizer + * @see org.springframework.test.context.ContextCustomizerFactory + * @since 0.0.23 + */ +public class GeodeContextCustomizerFactory implements ContextCustomizerFactory { + + /** + * @inheritDoc + */ + @Override + public @NonNull ContextCustomizer createContextCustomizer(@NonNull Class testClass, + @NonNull List configAttributes) { + + return new GeodeContextCustomizer(); + } +} diff --git a/spring-data-geode-test/src/main/resources/META-INF/spring.factories b/spring-data-geode-test/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..5bba770 --- /dev/null +++ b/spring-data-geode-test/src/main/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +# STDG TestExecutionListeners for the Spring TestContext Framework + +org.springframework.test.context.ContextCustomizerFactory=\ + org.springframework.data.gemfire.tests.integration.test.context.GeodeContextCustomizerFactory