You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@aries.apache.org by "Setya (JIRA)" <ji...@apache.org> on 2016/05/25 09:12:12 UTC

[jira] [Commented] (ARIES-1471) BeanPostProcessor in Blueprint

    [ https://issues.apache.org/jira/browse/ARIES-1471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15299716#comment-15299716 ] 

Setya commented on ARIES-1471:
------------------------------

Hi Guillaume,

Sorry for not being clear enough. Currently below is my simplified code:

//Spring context file
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="mybean" class="com.mycompany.MyBean"/>
</beans>

//Application context 
AbstractApplicationContext context = new ClassPathXmlApplicationContext(getContextFile())
{
	@Override
	protected void registerBeanPostProcessors(ConfigurableListableBeanFactory factory)
	{
		BeanPostProcessor beanPostProcessor = new BeanPostProcessor()
		{
			@Override
			public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException 
			{
				return name.equals("mybean") ? Mockito.mock(com.mycompany.MyBean.class) : bean;
			}
			
			@Override
			public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {return bean;}
		};
		
		factory.addBeanPostProcessor(beanPostProcessor);
		
		super.registerBeanPostProcessors(factory);
	}
};

//Getting mocked bean instead of the real one
MyBean mockedBean = context.getBean(com.mycompany.MyBean.class);

As you can see I can override postProcessBeforeInitialization method as needed to return mocked bean instance instead of the real one. This gives me high flexibility in unit test.

I'm asking if there's similliar way in Aries Blueprint.

Thanks & Regards,
Setya


> BeanPostProcessor in Blueprint
> ------------------------------
>
>                 Key: ARIES-1471
>                 URL: https://issues.apache.org/jira/browse/ARIES-1471
>             Project: Aries
>          Issue Type: Question
>          Components: Blueprint
>            Reporter: Setya
>            Priority: Minor
>
> Hi all,
> I test my Spring based app by registering custom BeanPostProcessor, this way I can mock any Spring beans component as needed without having to create multiple Spring context files for every test case. 
> I'm considering using Blueprint for my OSGI based application but I was wondering if it is possible to test the same way on Blueprint.
> Any insight would be greatly appreciated.
> Regards,
> Setya



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)