Class TestApplicationContext

java.lang.Object
org.junit.rules.ExternalResource
de.hybris.platform.dataimportcommons.TestApplicationContext
All Implemented Interfaces:
org.junit.rules.TestRule, 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 final class TestApplicationContext extends org.junit.rules.ExternalResource implements org.springframework.context.ApplicationContext
A JUnit test rule for stubbing Spring beans in the ApplicationContext. After the test(s) execution the rule automatically clears all previously stubbed beans in the application context.
  • Constructor Details

    • TestApplicationContext

      public TestApplicationContext()
  • Method Details

    • addBean

      public void addBean(String id, Object bean)
      Adds a bean definition into the application context of a test case.
      Parameters:
      id - an id the bean should have in the context
      bean - a Spring bean object
    • before

      protected void before() throws Throwable
      Overrides:
      before in class org.junit.rules.ExternalResource
      Throws:
      Throwable
    • after

      protected void after()
      Overrides:
      after in class org.junit.rules.ExternalResource
    • getId

      public String getId()
      Specified by:
      getId in interface org.springframework.context.ApplicationContext
    • getApplicationName

      @Nonnull public String getApplicationName()
      Specified by:
      getApplicationName in interface org.springframework.context.ApplicationContext
    • getDisplayName

      @Nonnull public String getDisplayName()
      Specified by:
      getDisplayName in interface org.springframework.context.ApplicationContext
    • getStartupDate

      public long getStartupDate()
      Specified by:
      getStartupDate in interface org.springframework.context.ApplicationContext
    • getParent

      public org.springframework.context.ApplicationContext getParent()
      Specified by:
      getParent in interface org.springframework.context.ApplicationContext
    • getAutowireCapableBeanFactory

      @Nonnull public org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException
      Specified by:
      getAutowireCapableBeanFactory in interface org.springframework.context.ApplicationContext
      Throws:
      IllegalStateException
    • getParentBeanFactory

      public org.springframework.beans.factory.BeanFactory getParentBeanFactory()
      Specified by:
      getParentBeanFactory in interface org.springframework.beans.factory.HierarchicalBeanFactory
    • containsLocalBean

      public boolean containsLocalBean(@Nonnull String s)
      Specified by:
      containsLocalBean in interface org.springframework.beans.factory.HierarchicalBeanFactory
    • containsBeanDefinition

      public boolean containsBeanDefinition(@Nonnull String s)
      Specified by:
      containsBeanDefinition in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanDefinitionCount

      public int getBeanDefinitionCount()
      Specified by:
      getBeanDefinitionCount in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanDefinitionNames

      @Nonnull public String[] getBeanDefinitionNames()
      Specified by:
      getBeanDefinitionNames in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanProvider

      @Nonnull public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(@Nonnull Class<T> aClass, boolean b)
      Specified by:
      getBeanProvider in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanProvider

      @Nonnull public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(@Nonnull org.springframework.core.ResolvableType resolvableType, boolean b)
      Specified by:
      getBeanProvider in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanNamesForType

      @Nonnull public String[] getBeanNamesForType(@Nonnull org.springframework.core.ResolvableType resolvableType)
      Specified by:
      getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanNamesForType

      @Nonnull public String[] getBeanNamesForType(@Nonnull org.springframework.core.ResolvableType resolvableType, boolean b, boolean b1)
      Specified by:
      getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanNamesForType

      @Nonnull public String[] getBeanNamesForType(Class<?> aClass)
      Specified by:
      getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanNamesForType

      @Nonnull public String[] getBeanNamesForType(Class<?> aClass, boolean b, boolean b1)
      Specified by:
      getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeansOfType

      @Nonnull public <T> Map<String,T> getBeansOfType(Class<T> aClass) throws org.springframework.beans.BeansException
      Specified by:
      getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactory
      Throws:
      org.springframework.beans.BeansException
    • getBeansOfType

      @Nonnull public <T> Map<String,T> getBeansOfType(Class<T> aClass, boolean b, boolean b1) throws org.springframework.beans.BeansException
      Specified by:
      getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactory
      Throws:
      org.springframework.beans.BeansException
    • getBeanNamesForAnnotation

      @Nonnull public String[] getBeanNamesForAnnotation(@Nonnull Class<? extends Annotation> aClass)
      Specified by:
      getBeanNamesForAnnotation in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeansWithAnnotation

      @Nonnull public Map<String,Object> getBeansWithAnnotation(@Nonnull Class<? extends Annotation> aClass) throws org.springframework.beans.BeansException
      Specified by:
      getBeansWithAnnotation in interface org.springframework.beans.factory.ListableBeanFactory
      Throws:
      org.springframework.beans.BeansException
    • findAnnotationOnBean

      public <A extends Annotation> A findAnnotationOnBean(@Nonnull String s, @Nonnull Class<A> aClass) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      findAnnotationOnBean in interface org.springframework.beans.factory.ListableBeanFactory
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • findAnnotationOnBean

      public <A extends Annotation> A findAnnotationOnBean(@Nonnull String s, @Nonnull Class<A> aClass, boolean b) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      findAnnotationOnBean in interface org.springframework.beans.factory.ListableBeanFactory
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • getBean

      @Nonnull public Object getBean(@Nonnull String s) throws org.springframework.beans.BeansException
      Specified by:
      getBean in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.BeansException
    • getBean

      @Nonnull public <T> T getBean(@Nonnull String s, Class<T> aClass) throws org.springframework.beans.BeansException
      Specified by:
      getBean in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.BeansException
    • getBean

      @Nonnull public Object getBean(@Nonnull String s, @Nonnull Object... objects) throws org.springframework.beans.BeansException
      Specified by:
      getBean in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.BeansException
    • getBean

      @Nonnull public <T> T getBean(Class<T> aClass) throws org.springframework.beans.BeansException
      Specified by:
      getBean in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.BeansException
    • getBean

      @Nonnull public <T> T getBean(@Nonnull Class<T> aClass, @Nonnull Object... objects) throws org.springframework.beans.BeansException
      Specified by:
      getBean in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.BeansException
    • getBeanProvider

      @Nonnull public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(@Nonnull Class<T> aClass)
      Specified by:
      getBeanProvider in interface org.springframework.beans.factory.BeanFactory
    • getBeanProvider

      @Nonnull public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(@Nonnull org.springframework.core.ResolvableType resolvableType)
      Specified by:
      getBeanProvider in interface org.springframework.beans.factory.BeanFactory
    • containsBean

      public boolean containsBean(@Nonnull String s)
      Specified by:
      containsBean in interface org.springframework.beans.factory.BeanFactory
    • isSingleton

      public boolean isSingleton(@Nonnull String s) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      isSingleton in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • isPrototype

      public boolean isPrototype(@Nonnull String s) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      isPrototype in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • isTypeMatch

      public boolean isTypeMatch(@Nonnull String s, org.springframework.core.ResolvableType resolvableType) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      isTypeMatch in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • isTypeMatch

      public boolean isTypeMatch(@Nonnull String s, Class<?> aClass) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      isTypeMatch in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • getType

      public Class<?> getType(@Nonnull String s) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      getType in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • getType

      public Class<?> getType(@Nonnull String s, boolean b) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      getType in interface org.springframework.beans.factory.BeanFactory
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • getAliases

      @Nonnull public String[] getAliases(@Nonnull String s)
      Specified by:
      getAliases in interface org.springframework.beans.factory.BeanFactory
    • publishEvent

      public void publishEvent(@Nonnull Object o)
      Specified by:
      publishEvent in interface org.springframework.context.ApplicationEventPublisher
    • getMessage

      public String getMessage(@Nonnull String s, Object[] objects, String s1, @Nonnull Locale locale)
      Specified by:
      getMessage in interface org.springframework.context.MessageSource
    • getMessage

      @Nonnull public String getMessage(@Nonnull String s, Object[] objects, @Nonnull Locale locale) throws org.springframework.context.NoSuchMessageException
      Specified by:
      getMessage in interface org.springframework.context.MessageSource
      Throws:
      org.springframework.context.NoSuchMessageException
    • getMessage

      @Nonnull public String getMessage(@Nonnull org.springframework.context.MessageSourceResolvable messageSourceResolvable, @Nonnull Locale locale) throws org.springframework.context.NoSuchMessageException
      Specified by:
      getMessage in interface org.springframework.context.MessageSource
      Throws:
      org.springframework.context.NoSuchMessageException
    • getEnvironment

      @Nonnull public org.springframework.core.env.Environment getEnvironment()
      Specified by:
      getEnvironment in interface org.springframework.core.env.EnvironmentCapable
    • getResources

      @Nonnull public org.springframework.core.io.Resource[] getResources(@Nonnull String s)
      Specified by:
      getResources in interface org.springframework.core.io.support.ResourcePatternResolver
    • getResource

      @Nonnull public org.springframework.core.io.Resource getResource(@Nonnull String s)
      Specified by:
      getResource in interface org.springframework.core.io.ResourceLoader
    • getClassLoader

      @Nonnull public ClassLoader getClassLoader()
      Specified by:
      getClassLoader in interface org.springframework.core.io.ResourceLoader