Class ApplicationContextMock

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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    boolean
     
    boolean
     
    boolean
     
    <A extends Annotation>
    A
    findAnnotationOnBean(String beanName, Class<A> annotationType)
     
     
    org.springframework.beans.factory.config.AutowireCapableBeanFactory
     
    <T> T
    getBean(Class<T> requiredType)
     
    <T> T
    getBean(Class<T> requiredType, Object... objects)
     
     
    <T> T
    getBean(String name, Class<T> requiredType)
     
    getBean(String name, Object... args)
     
    int
     
     
    org.springframework.beans.factory.config.ConfigurableListableBeanFactory
     
     
     
    getBeanNamesForType(Class type, boolean includeNonSingletons, boolean allowEagerInit)
     
    getBeanNamesForType(org.springframework.core.ResolvableType resolvableType)
     
    getBeanNamesForType(org.springframework.core.ResolvableType resolvableType, boolean includeNonSingletons, boolean allowEagerInit)
     
    <T> org.springframework.beans.factory.ObjectProvider<T>
     
    <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>
     
    <T> Map<String,T>
    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
     
     
    getType(String name, boolean allowFactoryBeanInit)
     
    boolean
     
    boolean
     
    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
    putBean(String name, T bean)
    puts bean with the given name into the context
    protected 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

  • Method Details

    • putBean

      public <T> void putBean(String name, T 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 interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getBean in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      org.springframework.beans.BeansException
    • getBean

      public Object getBean(String name, Object... args) throws org.springframework.beans.BeansException
      Specified by:
      getBean in interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getBean in class org.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 interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getBean in class org.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 interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeansOfType in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      org.springframework.beans.BeansException
    • getBean

      public <T> T getBean(Class<T> requiredType) throws org.springframework.beans.BeansException
      Specified by:
      getBean in interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getBean in class org.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 interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getBean in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      org.springframework.beans.BeansException
    • getBeanProvider

      public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(Class<T> aClass)
      Specified by:
      getBeanProvider in interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getBeanProvider in class org.springframework.context.support.AbstractApplicationContext
    • getBeanProvider

      public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(org.springframework.core.ResolvableType resolvableType)
      Specified by:
      getBeanProvider in interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getBeanProvider in class org.springframework.context.support.AbstractApplicationContext
    • getBeansWithAnnotation

      public Map<String,Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws org.springframework.beans.BeansException
      Specified by:
      getBeansWithAnnotation in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeansWithAnnotation in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      org.springframework.beans.BeansException
    • findAnnotationOnBean

      public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
      Specified by:
      findAnnotationOnBean in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      findAnnotationOnBean in class org.springframework.context.support.AbstractApplicationContext
    • getParent

      public org.springframework.context.ApplicationContext getParent()
      Specified by:
      getParent in interface org.springframework.context.ApplicationContext
      Overrides:
      getParent in class org.springframework.context.support.AbstractApplicationContext
    • getDisplayName

      Specified by:
      getDisplayName in interface org.springframework.context.ApplicationContext
      Overrides:
      getDisplayName in class org.springframework.context.support.AbstractApplicationContext
    • getStartupDate

      public long getStartupDate()
      Specified by:
      getStartupDate in interface org.springframework.context.ApplicationContext
      Overrides:
      getStartupDate in class org.springframework.context.support.AbstractApplicationContext
    • publishEvent

      public void publishEvent(org.springframework.context.ApplicationEvent event)
      Specified by:
      publishEvent in interface org.springframework.context.ApplicationEventPublisher
      Overrides:
      publishEvent in class org.springframework.context.support.AbstractApplicationContext
    • publishEvent

      public void publishEvent(Object o)
      Specified by:
      publishEvent in interface org.springframework.context.ApplicationEventPublisher
      Overrides:
      publishEvent in class org.springframework.context.support.AbstractApplicationContext
    • containsBeanDefinition

      public boolean containsBeanDefinition(String beanName)
      Specified by:
      containsBeanDefinition in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      containsBeanDefinition in class org.springframework.context.support.AbstractApplicationContext
    • getBeanDefinitionCount

      public int getBeanDefinitionCount()
      Specified by:
      getBeanDefinitionCount in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeanDefinitionCount in class org.springframework.context.support.AbstractApplicationContext
    • getBeanDefinitionNames

      Specified by:
      getBeanDefinitionNames in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeanDefinitionNames in class org.springframework.context.support.AbstractApplicationContext
    • getBeanProvider

      public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(Class<T> aClass, boolean b)
      Specified by:
      getBeanProvider in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeanProvider in class org.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 interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeanProvider in class org.springframework.context.support.AbstractApplicationContext
    • getBeanNamesForType

      public String[] getBeanNamesForType(org.springframework.core.ResolvableType resolvableType)
      Specified by:
      getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeanNamesForType in class org.springframework.context.support.AbstractApplicationContext
    • getBeanNamesForType

      public String[] getBeanNamesForType(org.springframework.core.ResolvableType resolvableType, boolean includeNonSingletons, boolean allowEagerInit)
      Specified by:
      getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeanNamesForType in class org.springframework.context.support.AbstractApplicationContext
    • getBeanNamesForType

      public String[] getBeanNamesForType(Class type)
      Specified by:
      getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeanNamesForType in class org.springframework.context.support.AbstractApplicationContext
    • getBeanNamesForType

      public String[] getBeanNamesForType(Class type, boolean includeNonSingletons, boolean allowEagerInit)
      Specified by:
      getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeanNamesForType in class org.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 interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeansOfType in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      org.springframework.beans.BeansException
    • getBeanNamesForAnnotation

      public String[] getBeanNamesForAnnotation(Class<? extends Annotation> aClass)
      Specified by:
      getBeanNamesForAnnotation in interface org.springframework.beans.factory.ListableBeanFactory
      Overrides:
      getBeanNamesForAnnotation in class org.springframework.context.support.AbstractApplicationContext
    • containsBean

      public boolean containsBean(String name)
      Specified by:
      containsBean in interface org.springframework.beans.factory.BeanFactory
      Overrides:
      containsBean in class org.springframework.context.support.AbstractApplicationContext
    • isSingleton

      public boolean isSingleton(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      isSingleton in interface org.springframework.beans.factory.BeanFactory
      Overrides:
      isSingleton in class org.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 interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getType in class org.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 interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getType in class org.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 interface org.springframework.beans.factory.BeanFactory
      Overrides:
      getAliases in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • getParentBeanFactory

      public org.springframework.beans.factory.BeanFactory getParentBeanFactory()
      Specified by:
      getParentBeanFactory in interface org.springframework.beans.factory.HierarchicalBeanFactory
      Overrides:
      getParentBeanFactory in class org.springframework.context.support.AbstractApplicationContext
    • getMessage

      public String getMessage(String code, Object[] args, String defaultMessage, Locale locale)
      Specified by:
      getMessage in interface org.springframework.context.MessageSource
      Overrides:
      getMessage in class org.springframework.context.support.AbstractApplicationContext
    • getMessage

      public String getMessage(String code, Object[] args, Locale locale) throws org.springframework.context.NoSuchMessageException
      Specified by:
      getMessage in interface org.springframework.context.MessageSource
      Overrides:
      getMessage in class org.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 interface org.springframework.context.MessageSource
      Overrides:
      getMessage in class org.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 interface org.springframework.core.io.support.ResourcePatternResolver
      Overrides:
      getResources in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      IOException
    • refreshBeanFactory

      protected void refreshBeanFactory() throws org.springframework.beans.BeansException, IllegalStateException
      Specified by:
      refreshBeanFactory in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      org.springframework.beans.BeansException
      IllegalStateException
    • closeBeanFactory

      protected void closeBeanFactory()
      Specified by:
      closeBeanFactory in class org.springframework.context.support.AbstractApplicationContext
    • getBeanFactory

      public org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException
      Specified by:
      getBeanFactory in interface org.springframework.context.ConfigurableApplicationContext
      Specified by:
      getBeanFactory in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      IllegalStateException
    • getResource

      public org.springframework.core.io.Resource getResource(String location)
      Specified by:
      getResource in interface org.springframework.core.io.ResourceLoader
      Overrides:
      getResource in class org.springframework.core.io.DefaultResourceLoader
    • getAutowireCapableBeanFactory

      public org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException
      Specified by:
      getAutowireCapableBeanFactory in interface org.springframework.context.ApplicationContext
      Overrides:
      getAutowireCapableBeanFactory in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      IllegalStateException
    • containsLocalBean

      public boolean containsLocalBean(String name)
      Specified by:
      containsLocalBean in interface org.springframework.beans.factory.HierarchicalBeanFactory
      Overrides:
      containsLocalBean in class org.springframework.context.support.AbstractApplicationContext
    • isPrototype

      public boolean isPrototype(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      isPrototype in interface org.springframework.beans.factory.BeanFactory
      Overrides:
      isPrototype in class org.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 interface org.springframework.beans.factory.BeanFactory
      Overrides:
      isTypeMatch in class org.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 interface org.springframework.beans.factory.BeanFactory
      Overrides:
      isTypeMatch in class org.springframework.context.support.AbstractApplicationContext
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException