org.apache.wicket.spring.test
Class ApplicationContextMock

java.lang.Object
  extended by org.apache.wicket.spring.test.ApplicationContextMock
All Implemented Interfaces:
java.io.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
Direct Known Subclasses:
AnnotApplicationContextMock

public class ApplicationContextMock
extends java.lang.Object
implements org.springframework.context.ApplicationContext, java.io.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(java.lang.String name)
           
 boolean containsBeanDefinition(java.lang.String beanName)
           
 boolean containsLocalBean(java.lang.String arg0)
           
 java.lang.String[] getAliases(java.lang.String name)
           
 org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory()
           
 java.lang.Object getBean(java.lang.String name)
           
 java.lang.Object getBean(java.lang.String name, java.lang.Class requiredType)
           
 int getBeanDefinitionCount()
           
 java.lang.String[] getBeanDefinitionNames()
           
 java.lang.String[] getBeanNamesForType(java.lang.Class type)
           
 java.lang.String[] getBeanNamesForType(java.lang.Class type, boolean includePrototypes, boolean includeFactoryBeans)
           
 java.util.Map getBeansOfType(java.lang.Class type)
           
 java.util.Map getBeansOfType(java.lang.Class type, boolean includePrototypes, boolean includeFactoryBeans)
           
 java.lang.ClassLoader getClassLoader()
           
 java.lang.String getDisplayName()
           
 java.lang.String getMessage(org.springframework.context.MessageSourceResolvable resolvable, java.util.Locale locale)
           
 java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, java.util.Locale locale)
           
 java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, java.lang.String defaultMessage, java.util.Locale locale)
           
 org.springframework.context.ApplicationContext getParent()
           
 org.springframework.beans.factory.BeanFactory getParentBeanFactory()
           
 org.springframework.core.io.Resource getResource(java.lang.String location)
           
 org.springframework.core.io.Resource[] getResources(java.lang.String locationPattern)
           
 long getStartupDate()
           
 java.lang.Class getType(java.lang.String name)
           
 boolean isSingleton(java.lang.String name)
           
 void publishEvent(org.springframework.context.ApplicationEvent event)
           
 void putBean(java.lang.Object bean)
          puts bean with into the context.
 void putBean(java.lang.String name, java.lang.Object bean)
          puts bean with the given name into the context
 
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(java.lang.String name,
                    java.lang.Object bean)
puts bean with the given name into the context

Parameters:
name -
bean -

putBean

public void putBean(java.lang.Object bean)
puts bean with into the context. bean object's class name will be used as the bean name.

Parameters:
bean -

getBean

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

getBean

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

getBeansOfType

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

getParent

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

getDisplayName

public java.lang.String getDisplayName()
Specified by:
getDisplayName in interface org.springframework.context.ApplicationContext
See Also:
ApplicationContext.getDisplayName()

getStartupDate

public long getStartupDate()
Specified by:
getStartupDate in interface org.springframework.context.ApplicationContext
See Also:
ApplicationContext.getStartupDate()

publishEvent

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

containsBeanDefinition

public boolean containsBeanDefinition(java.lang.String beanName)
Specified by:
containsBeanDefinition in interface org.springframework.beans.factory.ListableBeanFactory
See Also:
ListableBeanFactory.containsBeanDefinition(java.lang.String)

getBeanDefinitionCount

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

getBeanDefinitionNames

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

getBeanNamesForType

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

getBeanNamesForType

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

getBeansOfType

public java.util.Map getBeansOfType(java.lang.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
See Also:
ListableBeanFactory.getBeansOfType(java.lang.Class, boolean, boolean)

containsBean

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

isSingleton

public boolean isSingleton(java.lang.String name)
                    throws org.springframework.beans.factory.NoSuchBeanDefinitionException
Specified by:
isSingleton in interface org.springframework.beans.factory.BeanFactory
Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
See Also:
BeanFactory.isSingleton(java.lang.String)

getType

public java.lang.Class getType(java.lang.String name)
                        throws org.springframework.beans.factory.NoSuchBeanDefinitionException
Specified by:
getType in interface org.springframework.beans.factory.BeanFactory
Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
See Also:
BeanFactory.getType(java.lang.String)

getAliases

public java.lang.String[] getAliases(java.lang.String name)
                              throws org.springframework.beans.factory.NoSuchBeanDefinitionException
Specified by:
getAliases in interface org.springframework.beans.factory.BeanFactory
Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
See Also:
BeanFactory.getAliases(java.lang.String)

getParentBeanFactory

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

getMessage

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

getMessage

public java.lang.String getMessage(java.lang.String code,
                                   java.lang.Object[] args,
                                   java.util.Locale locale)
                            throws org.springframework.context.NoSuchMessageException
Specified by:
getMessage in interface org.springframework.context.MessageSource
Throws:
org.springframework.context.NoSuchMessageException
See Also:
MessageSource.getMessage(java.lang.String, java.lang.Object[], java.util.Locale)

getMessage

public java.lang.String getMessage(org.springframework.context.MessageSourceResolvable resolvable,
                                   java.util.Locale locale)
                            throws org.springframework.context.NoSuchMessageException
Specified by:
getMessage in interface org.springframework.context.MessageSource
Throws:
org.springframework.context.NoSuchMessageException
See Also:
MessageSource.getMessage(org.springframework.context.MessageSourceResolvable, java.util.Locale)

getResources

public org.springframework.core.io.Resource[] getResources(java.lang.String locationPattern)
                                                    throws java.io.IOException
Specified by:
getResources in interface org.springframework.core.io.support.ResourcePatternResolver
Throws:
java.io.IOException
See Also:
ResourcePatternResolver.getResources(java.lang.String)

getResource

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

getAutowireCapableBeanFactory

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

containsLocalBean

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

getClassLoader

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


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.