org.ops4j.pax.wicket.test.spring
Class ApplicationContextMock

java.lang.Object
  extended by org.ops4j.pax.wicket.test.spring.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.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. Only getBean(String), getBean(String, Class), and getBeansOfType(Class) are implemented so far. Any other method throws UnsupportedOperationException.

Author:
Igor Vaynberg (ivaynberg)
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
 
Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
 
Constructor Summary
ApplicationContextMock()
           
 
Method Summary
 boolean containsBean(String name)
           
 boolean containsBeanDefinition(String beanName)
           
 boolean containsLocalBean(String arg0)
           
<A extends Annotation>
A
findAnnotationOnBean(String beanName, Class<A> annotationType)
           
 String[] getAliases(String name)
           
 org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory()
           
<T> T
getBean(Class<T> requiredType)
           
 Object getBean(String name)
           
 Object getBean(String name, Class requiredType)
           
 Object getBean(String name, Object[] args)
           
 int getBeanDefinitionCount()
           
 String[] getBeanDefinitionNames()
           
 String[] getBeanNamesForType(Class type)
           
 String[] getBeanNamesForType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
           
 Map getBeansOfType(Class type)
           
 Map getBeansOfType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
           
 Map<String,Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType)
           
 ClassLoader getClassLoader()
           
 String getDisplayName()
           
 String getId()
           
 String getMessage(org.springframework.context.MessageSourceResolvable resolvable, Locale locale)
           
 String getMessage(String code, Object[] args, Locale locale)
           
 String getMessage(String code, Object[] args, String defaultMessage, 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)
           
 boolean isPrototype(String name)
           
 boolean isSingleton(String name)
           
 boolean isTypeMatch(String name, Class targetType)
           
 void publishEvent(org.springframework.context.ApplicationEvent event)
           
 void putBean(Object bean)
           
 void putBean(String name, Object bean)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApplicationContextMock

public ApplicationContextMock()
Method Detail

putBean

public void putBean(String name,
                    Object bean)

putBean

public void putBean(Object bean)

getBean

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

getBean

public Object getBean(String name,
                      Class requiredType)
               throws org.springframework.beans.BeansException
Specified by:
getBean in interface org.springframework.beans.factory.BeanFactory
Throws:
org.springframework.beans.BeansException

getBeansOfType

public Map getBeansOfType(Class type)
                   throws org.springframework.beans.BeansException
Specified by:
getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactory
Throws:
org.springframework.beans.BeansException

getParent

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

getDisplayName

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

publishEvent

public void publishEvent(org.springframework.context.ApplicationEvent event)
Specified by:
publishEvent in interface org.springframework.context.ApplicationEventPublisher

containsBeanDefinition

public boolean containsBeanDefinition(String beanName)
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

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

getBeanNamesForType

public String[] getBeanNamesForType(Class type)
Specified by:
getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory

getBeanNamesForType

public String[] getBeanNamesForType(Class type,
                                    boolean includePrototypes,
                                    boolean includeFactoryBeans)
Specified by:
getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory

getBeansOfType

public Map getBeansOfType(Class type,
                          boolean includePrototypes,
                          boolean includeFactoryBeans)
                   throws org.springframework.beans.BeansException
Specified by:
getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactory
Throws:
org.springframework.beans.BeansException

containsBean

public boolean containsBean(String name)
Specified by:
containsBean in interface org.springframework.beans.factory.BeanFactory

isSingleton

public boolean isSingleton(String name)
                    throws org.springframework.beans.factory.NoSuchBeanDefinitionException
Specified by:
isSingleton in interface org.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 interface org.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 interface org.springframework.beans.factory.BeanFactory
Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException

getParentBeanFactory

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

getMessage

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

getMessage

public String getMessage(String code,
                         Object[] args,
                         Locale locale)
                  throws org.springframework.context.NoSuchMessageException
Specified by:
getMessage in interface org.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 interface org.springframework.context.MessageSource
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
Throws:
IOException

getResource

public org.springframework.core.io.Resource getResource(String location)
Specified by:
getResource in interface org.springframework.core.io.ResourceLoader

getAutowireCapableBeanFactory

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

containsLocalBean

public boolean containsLocalBean(String arg0)
Specified by:
containsLocalBean in interface org.springframework.beans.factory.HierarchicalBeanFactory

getClassLoader

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

getId

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

getBean

public Object getBean(String name,
                      Object[] args)
               throws org.springframework.beans.BeansException
Specified by:
getBean in interface org.springframework.beans.factory.BeanFactory
Throws:
org.springframework.beans.BeansException

isPrototype

public boolean isPrototype(String name)
                    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(String name,
                           Class targetType)
                    throws org.springframework.beans.factory.NoSuchBeanDefinitionException
Specified by:
isTypeMatch in interface org.springframework.beans.factory.BeanFactory
Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException

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
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

getBean

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


Copyright © 2006-2012 OPS4J - Open Participation Software for Java. All Rights Reserved.