Clean up all GemfireBeanFactoryLocator references to BeanFactories used in tests.

This commit is contained in:
John Blum
2018-05-28 22:47:24 -07:00
parent 400bcec902
commit 8a082ea642
4 changed files with 54 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.boot.data.geode.security.auth.cloud;
import java.io.IOException;
import java.util.Properties;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.boot.SpringApplication;
@@ -29,6 +30,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
import org.springframework.data.gemfire.config.annotation.EnableLocator;
import org.springframework.data.gemfire.config.annotation.EnableLogging;
import org.springframework.data.gemfire.support.GemfireBeanFactoryLocatorProxy;
import org.springframework.test.context.junit4.SpringRunner;
/**
@@ -76,6 +78,12 @@ public class AutoConfiguredCloudSecurityContextIntegrationTests
public static void startGemFireServer() throws IOException {
startGemFireServer(GemFireServerConfiguration.class, "-Dspring.profiles.active=security-cloud");
loadVcapApplicationProperties();
GemfireBeanFactoryLocatorProxy.clean();
}
@AfterClass
public static void cleanUpBeanFactoryLocatorReferences() {
GemfireBeanFactoryLocatorProxy.clean();
}
@SpringBootApplication

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.data.geode.security.auth.local;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.boot.SpringApplication;
@@ -27,6 +28,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
import org.springframework.data.gemfire.config.annotation.EnableLogging;
import org.springframework.data.gemfire.support.GemfireBeanFactoryLocatorProxy;
import org.springframework.data.gemfire.tests.integration.config.ClientServerIntegrationTestsConfiguration;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@@ -64,10 +66,18 @@ public class AutoConfiguredLocalSecurityContextIntegrationTests
@BeforeClass
public static void startGemFireServer() throws IOException {
GemfireBeanFactoryLocatorProxy.clean();
startGemFireServer(GemFireServerConfiguration.class,
"-Dspring.profiles.active=security-local-server");
}
@AfterClass
public static void cleanUpBeanFactoryLocatorReferences() {
GemfireBeanFactoryLocatorProxy.clean();
}
@SpringBootApplication
@EnableLogging(logLevel = GEMFIRE_LOG_LEVEL)
@Import(ClientServerIntegrationTestsConfiguration.class)

View File

@@ -20,12 +20,15 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.apache.geode.cache.GemFireCache;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.config.annotation.EnableSecurity;
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;
import org.springframework.data.gemfire.support.GemfireBeanFactoryLocatorProxy;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -49,6 +52,12 @@ public class SecurityManagerProxyIntegrationTests {
private static final String GEMFIRE_LOG_LEVEL = "error";
@BeforeClass
@AfterClass
public static void cleanUpBeanFactoryLocatorReferences() {
GemfireBeanFactoryLocatorProxy.clean();
}
@Autowired
private org.apache.geode.security.SecurityManager mockSecurityManager;

View File

@@ -1,11 +1,36 @@
/*
* Copyright 2018 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.data.gemfire.support;
import org.springframework.beans.factory.BeanFactory;
/**
* The GemfireBeanFactoryLocatorProxy class...
* The {@link GemfireBeanFactoryLocatorProxy} class is an extension of {@link GemfireBeanFactoryLocator}
* used to clean up all Spring {@link BeanFactory} references.
*
* @author John Blum
* @see org.springframework.beans.factory.BeanFactory
* @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
* @since 1.0.0
*/
public class GemfireBeanFactoryLocatorProxy {
// TODO: remove this class once and refactor the SDG GemfireBeanFactoryLocator!
public class GemfireBeanFactoryLocatorProxy extends GemfireBeanFactoryLocator {
public static void clean() {
BEAN_FACTORIES.clear();
}
}