java.lang.Object
org.springframework.core.io.DefaultResourceLoader
org.springframework.context.support.AbstractApplicationContext
org.apache.wicket.spring.test.ApplicationContextMock
- All Implemented Interfaces:
Closeable
,Serializable
,AutoCloseable
,org.springframework.beans.factory.BeanFactory
,org.springframework.beans.factory.HierarchicalBeanFactory
,org.springframework.beans.factory.ListableBeanFactory
,org.springframework.context.ApplicationContext
,org.springframework.context.ApplicationEventPublisher
,org.springframework.context.ConfigurableApplicationContext
,org.springframework.context.Lifecycle
,org.springframework.context.MessageSource
,org.springframework.core.env.EnvironmentCapable
,org.springframework.core.io.ResourceLoader
,org.springframework.core.io.support.ResourcePatternResolver
public class ApplicationContextMock
extends org.springframework.context.support.AbstractApplicationContext
implements Serializable
Mock application context object. This mock context allows easy creation of unit tests by allowing
the user to put bean instances into the context.
- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.core.io.DefaultResourceLoader
org.springframework.core.io.DefaultResourceLoader.ClassPathContextResource
-
Field Summary
Fields inherited from class org.springframework.context.support.AbstractApplicationContext
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAME
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
Fields inherited from interface org.springframework.context.ConfigurableApplicationContext
APPLICATION_STARTUP_BEAN_NAME, CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SHUTDOWN_HOOK_THREAD_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAME
Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
boolean
containsBean
(String name) boolean
containsBeanDefinition
(String beanName) boolean
containsLocalBean
(String name) <A extends Annotation>
AfindAnnotationOnBean
(String beanName, Class<A> annotationType) String[]
getAliases
(String name) org.springframework.beans.factory.config.AutowireCapableBeanFactory
<T> T
<T> T
<T> T
int
String[]
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
String[]
getBeanNamesForAnnotation
(Class<? extends Annotation> aClass) String[]
getBeanNamesForType
(Class type) String[]
getBeanNamesForType
(Class type, boolean includeNonSingletons, boolean allowEagerInit) String[]
getBeanNamesForType
(org.springframework.core.ResolvableType resolvableType) String[]
getBeanNamesForType
(org.springframework.core.ResolvableType resolvableType, boolean includeNonSingletons, boolean allowEagerInit) <T> org.springframework.beans.factory.ObjectProvider<T>
getBeanProvider
(Class<T> aClass) <T> org.springframework.beans.factory.ObjectProvider<T>
getBeanProvider
(Class<T> aClass, boolean b) <T> org.springframework.beans.factory.ObjectProvider<T>
getBeanProvider
(org.springframework.core.ResolvableType resolvableType) <T> org.springframework.beans.factory.ObjectProvider<T>
getBeanProvider
(org.springframework.core.ResolvableType resolvableType, boolean b) getBeansOfType
(Class<T> type) getBeansOfType
(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) getBeansWithAnnotation
(Class<? extends Annotation> annotationType) getMessage
(String code, Object[] args, String defaultMessage, Locale locale) getMessage
(String code, Object[] args, Locale locale) getMessage
(org.springframework.context.MessageSourceResolvable resolvable, Locale locale) org.springframework.context.ApplicationContext
org.springframework.beans.factory.BeanFactory
org.springframework.core.io.Resource
getResource
(String location) org.springframework.core.io.Resource[]
getResources
(String locationPattern) long
Class<?>
Class<?>
boolean
isPrototype
(String name) boolean
isSingleton
(String name) boolean
isTypeMatch
(String name, Class targetType) boolean
isTypeMatch
(String s, org.springframework.core.ResolvableType resolvableType) void
void
publishEvent
(org.springframework.context.ApplicationEvent event) void
puts bean with into the context. bean object's class name will be used as the bean name.<T> void
puts bean with the given name into the contextprotected void
Methods inherited from class org.springframework.context.support.AbstractApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, assertBeanFactoryActive, cancelRefresh, close, createEnvironment, destroyBeans, doClose, findAllAnnotationsOnBean, findAnnotationOnBean, finishBeanFactoryInitialization, finishRefresh, getApplicationListeners, getApplicationName, getApplicationStartup, getBeanFactoryPostProcessors, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getResourcePatternResolver, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, initPropertySources, invokeBeanFactoryPostProcessors, isActive, isRunning, obtainFreshBeanFactory, onClose, onRefresh, postProcessBeanFactory, prepareBeanFactory, prepareRefresh, publishEvent, refresh, registerBeanPostProcessors, registerListeners, registerShutdownHook, removeApplicationListener, resetCommonCaches, setApplicationStartup, setDisplayName, setEnvironment, setId, setParent, start, stop, toString
Methods inherited from class org.springframework.core.io.DefaultResourceLoader
addProtocolResolver, clearResourceCaches, getClassLoader, getProtocolResolvers, getResourceByPath, getResourceCache, setClassLoader
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.context.ConfigurableApplicationContext
addProtocolResolver, setClassLoader
Methods inherited from interface org.springframework.core.io.ResourceLoader
getClassLoader
-
Constructor Details
-
ApplicationContextMock
public ApplicationContextMock()
-
-
Method Details
-
putBean
puts bean with the given name into the context- Parameters:
name
-bean
-
-
putBean
puts bean with into the context. bean object's class name will be used as the bean name.- Parameters:
bean
-
-
getBean
- Specified by:
getBean
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getBean
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
-
getBean
- Specified by:
getBean
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getBean
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
-
getBean
public <T> T getBean(String name, Class<T> requiredType) throws org.springframework.beans.BeansException - Specified by:
getBean
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getBean
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
-
getBeansOfType
public <T> Map<String,T> getBeansOfType(Class<T> type) throws org.springframework.beans.BeansException - Specified by:
getBeansOfType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeansOfType
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
-
getBean
- Specified by:
getBean
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getBean
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
-
getBean
public <T> T getBean(Class<T> requiredType, Object... objects) throws org.springframework.beans.BeansException - Specified by:
getBean
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getBean
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
-
getBeanProvider
- Specified by:
getBeanProvider
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getBeanProvider
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(org.springframework.core.ResolvableType resolvableType) - Specified by:
getBeanProvider
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getBeanProvider
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeansWithAnnotation
public Map<String,Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws org.springframework.beans.BeansException - Specified by:
getBeansWithAnnotation
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeansWithAnnotation
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
-
findAnnotationOnBean
- Specified by:
findAnnotationOnBean
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
findAnnotationOnBean
in classorg.springframework.context.support.AbstractApplicationContext
-
getParent
- Specified by:
getParent
in interfaceorg.springframework.context.ApplicationContext
- Overrides:
getParent
in classorg.springframework.context.support.AbstractApplicationContext
-
getDisplayName
- Specified by:
getDisplayName
in interfaceorg.springframework.context.ApplicationContext
- Overrides:
getDisplayName
in classorg.springframework.context.support.AbstractApplicationContext
-
getStartupDate
- Specified by:
getStartupDate
in interfaceorg.springframework.context.ApplicationContext
- Overrides:
getStartupDate
in classorg.springframework.context.support.AbstractApplicationContext
-
publishEvent
- Specified by:
publishEvent
in interfaceorg.springframework.context.ApplicationEventPublisher
- Overrides:
publishEvent
in classorg.springframework.context.support.AbstractApplicationContext
-
publishEvent
- Specified by:
publishEvent
in interfaceorg.springframework.context.ApplicationEventPublisher
- Overrides:
publishEvent
in classorg.springframework.context.support.AbstractApplicationContext
-
containsBeanDefinition
- Specified by:
containsBeanDefinition
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
containsBeanDefinition
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanDefinitionCount
- Specified by:
getBeanDefinitionCount
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeanDefinitionCount
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanDefinitionNames
- Specified by:
getBeanDefinitionNames
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeanDefinitionNames
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(Class<T> aClass, boolean b) - Specified by:
getBeanProvider
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeanProvider
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(org.springframework.core.ResolvableType resolvableType, boolean b) - Specified by:
getBeanProvider
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeanProvider
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanNamesForType
- Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeanNamesForType
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanNamesForType
public String[] getBeanNamesForType(org.springframework.core.ResolvableType resolvableType, boolean includeNonSingletons, boolean allowEagerInit) - Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeanNamesForType
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanNamesForType
- Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeanNamesForType
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanNamesForType
public String[] getBeanNamesForType(Class type, boolean includeNonSingletons, boolean allowEagerInit) - Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeanNamesForType
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeansOfType
public <T> Map<String,T> getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws org.springframework.beans.BeansException - Specified by:
getBeansOfType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeansOfType
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
-
getBeanNamesForAnnotation
- Specified by:
getBeanNamesForAnnotation
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Overrides:
getBeanNamesForAnnotation
in classorg.springframework.context.support.AbstractApplicationContext
-
containsBean
- Specified by:
containsBean
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
containsBean
in classorg.springframework.context.support.AbstractApplicationContext
-
isSingleton
public boolean isSingleton(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException - Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
isSingleton
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getType
public Class<?> getType(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException - Specified by:
getType
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getType
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getType
public Class<?> getType(String name, boolean allowFactoryBeanInit) throws org.springframework.beans.factory.NoSuchBeanDefinitionException - Specified by:
getType
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getType
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getAliases
public String[] getAliases(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException - Specified by:
getAliases
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
getAliases
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getParentBeanFactory
- Specified by:
getParentBeanFactory
in interfaceorg.springframework.beans.factory.HierarchicalBeanFactory
- Overrides:
getParentBeanFactory
in classorg.springframework.context.support.AbstractApplicationContext
-
getMessage
- Specified by:
getMessage
in interfaceorg.springframework.context.MessageSource
- Overrides:
getMessage
in classorg.springframework.context.support.AbstractApplicationContext
-
getMessage
public String getMessage(String code, Object[] args, Locale locale) throws org.springframework.context.NoSuchMessageException - Specified by:
getMessage
in interfaceorg.springframework.context.MessageSource
- Overrides:
getMessage
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.context.NoSuchMessageException
-
getMessage
public String getMessage(org.springframework.context.MessageSourceResolvable resolvable, Locale locale) throws org.springframework.context.NoSuchMessageException - Specified by:
getMessage
in interfaceorg.springframework.context.MessageSource
- Overrides:
getMessage
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.context.NoSuchMessageException
-
getResources
public org.springframework.core.io.Resource[] getResources(String locationPattern) throws IOException - Specified by:
getResources
in interfaceorg.springframework.core.io.support.ResourcePatternResolver
- Overrides:
getResources
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
IOException
-
refreshBeanFactory
protected void refreshBeanFactory() throws org.springframework.beans.BeansException, IllegalStateException- Specified by:
refreshBeanFactory
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
IllegalStateException
-
closeBeanFactory
- Specified by:
closeBeanFactory
in classorg.springframework.context.support.AbstractApplicationContext
-
getBeanFactory
public org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException- Specified by:
getBeanFactory
in interfaceorg.springframework.context.ConfigurableApplicationContext
- Specified by:
getBeanFactory
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
IllegalStateException
-
getResource
- Specified by:
getResource
in interfaceorg.springframework.core.io.ResourceLoader
- Overrides:
getResource
in classorg.springframework.core.io.DefaultResourceLoader
-
getAutowireCapableBeanFactory
public org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException- Specified by:
getAutowireCapableBeanFactory
in interfaceorg.springframework.context.ApplicationContext
- Overrides:
getAutowireCapableBeanFactory
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
IllegalStateException
-
containsLocalBean
- Specified by:
containsLocalBean
in interfaceorg.springframework.beans.factory.HierarchicalBeanFactory
- Overrides:
containsLocalBean
in classorg.springframework.context.support.AbstractApplicationContext
-
isPrototype
public boolean isPrototype(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException - Specified by:
isPrototype
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
isPrototype
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
isTypeMatch
public boolean isTypeMatch(String s, org.springframework.core.ResolvableType resolvableType) throws org.springframework.beans.factory.NoSuchBeanDefinitionException - Specified by:
isTypeMatch
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
isTypeMatch
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
isTypeMatch
public boolean isTypeMatch(String name, Class targetType) throws org.springframework.beans.factory.NoSuchBeanDefinitionException - Specified by:
isTypeMatch
in interfaceorg.springframework.beans.factory.BeanFactory
- Overrides:
isTypeMatch
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-