Add GeodeContextCustomizer and factory used to customize the Spring ApplicationContext setup during Integration Tests involving Apache Geode.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<ContextConfigurationAttributes> configAttributes) {
|
||||
|
||||
return new GeodeContextCustomizer();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user