Package org.apache.wicket.spring.test
Class ApplicationContextMock
- java.lang.Object
-
- org.apache.wicket.spring.test.ApplicationContextMock
-
- All Implemented Interfaces:
Serializable
,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.MessageSource
,org.springframework.core.env.EnvironmentCapable
,org.springframework.core.io.ResourceLoader
,org.springframework.core.io.support.ResourcePatternResolver
public class ApplicationContextMock extends Object implements org.springframework.context.ApplicationContext, 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. OnlygetBean(String)
,getBean(String, Class)
, andgetBeansOfType(Class)
are implemented so far. Any other method throwsUnsupportedOperationException
.- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ApplicationContextMock()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsBean(String name)
boolean
containsBeanDefinition(String beanName)
boolean
containsLocalBean(String arg0)
<A extends Annotation>
AfindAnnotationOnBean(String beanName, Class<A> annotationType)
<A extends Annotation>
AfindAnnotationOnBean(String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
String[]
getAliases(String name)
String
getApplicationName()
org.springframework.beans.factory.config.AutowireCapableBeanFactory
getAutowireCapableBeanFactory()
<T> T
getBean(Class<T> requiredType)
<T> T
getBean(Class<T> requiredType, Object... objects)
Object
getBean(String name)
<T> T
getBean(String name, Class<T> requiredType)
Object
getBean(String name, Object... args)
int
getBeanDefinitionCount()
String[]
getBeanDefinitionNames()
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)
<T> Map<String,T>
getBeansOfType(Class<T> type)
<T> Map<String,T>
getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
Map<String,Object>
getBeansWithAnnotation(Class<? extends Annotation> annotationType)
ClassLoader
getClassLoader()
String
getDisplayName()
org.springframework.core.env.Environment
getEnvironment()
String
getId()
String
getMessage(String code, Object[] args, String defaultMessage, Locale locale)
String
getMessage(String code, Object[] args, Locale locale)
String
getMessage(org.springframework.context.MessageSourceResolvable resolvable, Locale locale)
org.springframework.context.ApplicationContext
getParent()
org.springframework.beans.factory.BeanFactory
getParentBeanFactory()
org.springframework.core.io.Resource
getResource(String location)
org.springframework.core.io.Resource[]
getResources(String locationPattern)
long
getStartupDate()
Class<?>
getType(String name)
Class<?>
getType(String name, boolean allowFactoryBeanInit)
boolean
isPrototype(String name)
boolean
isSingleton(String name)
boolean
isTypeMatch(String name, Class targetType)
boolean
isTypeMatch(String s, org.springframework.core.ResolvableType resolvableType)
void
publishEvent(Object o)
void
publishEvent(org.springframework.context.ApplicationEvent event)
void
putBean(Object bean)
puts bean with into the context.void
putBean(String name, Object bean)
puts bean with the given name into the context
-
-
-
Constructor Detail
-
ApplicationContextMock
public ApplicationContextMock()
-
-
Method Detail
-
putBean
public void putBean(String name, Object bean)
puts bean with the given name into the context- Parameters:
name
-bean
-
-
putBean
public void putBean(Object bean)
puts bean with into the context. bean object's class name will be used as the bean name.- Parameters:
bean
-
-
getBean
public Object getBean(String name) throws org.springframework.beans.BeansException
- Specified by:
getBean
in interfaceorg.springframework.beans.factory.BeanFactory
- Throws:
org.springframework.beans.BeansException
-
getBean
public Object getBean(String name, Object... args) throws org.springframework.beans.BeansException
- Specified by:
getBean
in interfaceorg.springframework.beans.factory.BeanFactory
- 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
- Throws:
org.springframework.beans.BeansException
- See Also:
BeanFactory.getBean(java.lang.String, java.lang.Class)
-
getBeansOfType
public <T> Map<String,T> getBeansOfType(Class<T> type) throws org.springframework.beans.BeansException
- Specified by:
getBeansOfType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Throws:
org.springframework.beans.BeansException
- See Also:
ListableBeanFactory.getBeansOfType(java.lang.Class)
-
getBean
public <T> T getBean(Class<T> requiredType) throws org.springframework.beans.BeansException
- Specified by:
getBean
in interfaceorg.springframework.beans.factory.BeanFactory
- 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
- Throws:
org.springframework.beans.BeansException
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(Class<T> aClass)
- Specified by:
getBeanProvider
in interfaceorg.springframework.beans.factory.BeanFactory
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(org.springframework.core.ResolvableType resolvableType)
- Specified by:
getBeanProvider
in interfaceorg.springframework.beans.factory.BeanFactory
-
getBeansWithAnnotation
public Map<String,Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws org.springframework.beans.BeansException
- Specified by:
getBeansWithAnnotation
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Throws:
org.springframework.beans.BeansException
-
findAnnotationOnBean
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
- Specified by:
findAnnotationOnBean
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
findAnnotationOnBean
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType, boolean allowFactoryBeanInit) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
- Specified by:
findAnnotationOnBean
in interfaceorg.springframework.beans.factory.ListableBeanFactory
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getParent
public org.springframework.context.ApplicationContext getParent()
- Specified by:
getParent
in interfaceorg.springframework.context.ApplicationContext
-
getDisplayName
public String getDisplayName()
- Specified by:
getDisplayName
in interfaceorg.springframework.context.ApplicationContext
-
getStartupDate
public long getStartupDate()
- Specified by:
getStartupDate
in interfaceorg.springframework.context.ApplicationContext
-
publishEvent
public void publishEvent(org.springframework.context.ApplicationEvent event)
- Specified by:
publishEvent
in interfaceorg.springframework.context.ApplicationEventPublisher
-
publishEvent
public void publishEvent(Object o)
- Specified by:
publishEvent
in interfaceorg.springframework.context.ApplicationEventPublisher
-
containsBeanDefinition
public boolean containsBeanDefinition(String beanName)
- Specified by:
containsBeanDefinition
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanDefinitionCount
public int getBeanDefinitionCount()
- Specified by:
getBeanDefinitionCount
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanDefinitionNames
public String[] getBeanDefinitionNames()
- Specified by:
getBeanDefinitionNames
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(Class<T> aClass, boolean b)
- Specified by:
getBeanProvider
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
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
-
getBeanNamesForType
public String[] getBeanNamesForType(org.springframework.core.ResolvableType resolvableType)
- Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
public String[] getBeanNamesForType(org.springframework.core.ResolvableType resolvableType, boolean includeNonSingletons, boolean allowEagerInit)
- Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
public String[] getBeanNamesForType(Class type)
- Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
public String[] getBeanNamesForType(Class type, boolean includeNonSingletons, boolean allowEagerInit)
- Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
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
- Throws:
org.springframework.beans.BeansException
-
getBeanNamesForAnnotation
public String[] getBeanNamesForAnnotation(Class<? extends Annotation> aClass)
- Specified by:
getBeanNamesForAnnotation
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
containsBean
public boolean containsBean(String name)
- Specified by:
containsBean
in interfaceorg.springframework.beans.factory.BeanFactory
-
isSingleton
public boolean isSingleton(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.BeanFactory
- 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
- 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
- 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
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getParentBeanFactory
public org.springframework.beans.factory.BeanFactory getParentBeanFactory()
- Specified by:
getParentBeanFactory
in interfaceorg.springframework.beans.factory.HierarchicalBeanFactory
- See Also:
HierarchicalBeanFactory.getParentBeanFactory()
-
getMessage
public String getMessage(String code, Object[] args, String defaultMessage, Locale locale)
- Specified by:
getMessage
in interfaceorg.springframework.context.MessageSource
-
getMessage
public String getMessage(String code, Object[] args, Locale locale) throws org.springframework.context.NoSuchMessageException
- Specified by:
getMessage
in interfaceorg.springframework.context.MessageSource
- 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
- 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
- Throws:
IOException
-
getResource
public org.springframework.core.io.Resource getResource(String location)
- Specified by:
getResource
in interfaceorg.springframework.core.io.ResourceLoader
-
getAutowireCapableBeanFactory
public org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException
- Specified by:
getAutowireCapableBeanFactory
in interfaceorg.springframework.context.ApplicationContext
- Throws:
IllegalStateException
-
containsLocalBean
public boolean containsLocalBean(String arg0)
- Specified by:
containsLocalBean
in interfaceorg.springframework.beans.factory.HierarchicalBeanFactory
-
getClassLoader
public ClassLoader getClassLoader()
- Specified by:
getClassLoader
in interfaceorg.springframework.core.io.ResourceLoader
-
getId
public String getId()
- Specified by:
getId
in interfaceorg.springframework.context.ApplicationContext
-
getApplicationName
public String getApplicationName()
- Specified by:
getApplicationName
in interfaceorg.springframework.context.ApplicationContext
-
isPrototype
public boolean isPrototype(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
- Specified by:
isPrototype
in interfaceorg.springframework.beans.factory.BeanFactory
- 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
- 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
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getEnvironment
public org.springframework.core.env.Environment getEnvironment()
- Specified by:
getEnvironment
in interfaceorg.springframework.core.env.EnvironmentCapable
-
-