-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[Spring] Share application context #1848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
a176c00
5b564d3
d77e00e
37ff9ea
35fb721
48fa98c
8b6afda
6337a7a
2b2af1c
c8e1010
88ac994
0833a49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,6 @@ | |
import java.util.Set; | ||
|
||
import static io.cucumber.spring.CucumberTestContext.SCOPE_CUCUMBER_GLUE; | ||
import static io.cucumber.spring.FixBootstrapUtils.createBootstrapContext; | ||
import static io.cucumber.spring.FixBootstrapUtils.resolveTestContextBootstrapper; | ||
import static java.util.Arrays.asList; | ||
|
||
/** | ||
|
@@ -65,6 +63,8 @@ | |
@API(status = API.Status.STABLE) | ||
public final class SpringFactory implements ObjectFactory { | ||
|
||
private static final Object monitor = new Object(); | ||
|
||
private ConfigurableListableBeanFactory beanFactory; | ||
private CucumberTestContextManager testContextManager; | ||
|
||
|
@@ -129,21 +129,24 @@ private static boolean hasAnnotation(Annotation annotation, Collection<Class<? e | |
|
||
@Override | ||
public void start() { | ||
if (stepClassWithSpringContext != null) { | ||
testContextManager = new CucumberTestContextManager(stepClassWithSpringContext); | ||
} else { | ||
if (beanFactory == null) { | ||
beanFactory = createFallbackContext(); | ||
synchronized (monitor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also explained the why of it all. |
||
if (stepClassWithSpringContext != null) { | ||
testContextManager = new CucumberTestContextManager(stepClassWithSpringContext); | ||
} else { | ||
if (beanFactory == null) { | ||
beanFactory = createFallbackContext(); | ||
} | ||
} | ||
} | ||
notifyContextManagerAboutTestClassStarted(); | ||
if (beanFactory == null || isNewContextCreated()) { | ||
beanFactory = testContextManager.getBeanFactory(); | ||
for (Class<?> stepClass : stepClasses) { | ||
registerStepClassBeanDefinition(beanFactory, stepClass); | ||
notifyContextManagerAboutTestClassStarted(); | ||
if (beanFactory == null || isNewContextCreated()) { | ||
beanFactory = testContextManager.getBeanFactory(); | ||
for (Class<?> stepClass : stepClasses) { | ||
registerStepClassBeanDefinition(beanFactory, stepClass); | ||
mpkorstanje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
GlueCodeContext.getInstance().start(); | ||
} | ||
GlueCodeContext.getInstance().start(); | ||
|
||
} | ||
|
||
@SuppressWarnings("resource") | ||
|
@@ -183,9 +186,9 @@ private boolean isNewContextCreated() { | |
private void registerStepClassBeanDefinition(ConfigurableListableBeanFactory beanFactory, Class<?> stepClass) { | ||
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; | ||
BeanDefinition beanDefinition = BeanDefinitionBuilder | ||
.genericBeanDefinition(stepClass) | ||
.setScope(SCOPE_CUCUMBER_GLUE) | ||
.getBeanDefinition(); | ||
.genericBeanDefinition(stepClass) | ||
.setScope(SCOPE_CUCUMBER_GLUE) | ||
.getBeanDefinition(); | ||
registry.registerBeanDefinition(stepClass.getName(), beanDefinition); | ||
} | ||
|
||
|
@@ -233,9 +236,7 @@ private static boolean annotatedWithSupportedSpringRootTestAnnotations(Annotatio | |
static class CucumberTestContextManager extends TestContextManager { | ||
|
||
CucumberTestContextManager(Class<?> testClass) { | ||
// Does the same as TestContextManager(Class<?>) but creates a | ||
// DefaultCacheAwareContextLoaderDelegate that uses a thread local contextCache. | ||
super(resolveTestContextBootstrapper(createBootstrapContext(testClass))); | ||
super(testClass); | ||
registerGlueCodeScope(getContext()); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the
FixBootstrapUtils
. Wasn't needed any more.