[arquillian-issues] [JBoss JIRA] (ARQ-1303) Add Spring StaticApplicationContext

Jakub Narloch (JIRA) jira-events at lists.jboss.org
Wed Feb 20 12:38:58 EST 2013


    [ https://issues.jboss.org/browse/ARQ-1303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12755494#comment-12755494 ] 

Jakub Narloch commented on ARQ-1303:
------------------------------------

> You don't need to lookup the bean, we can provide a feature to autowire beans in a test class by using reflection. please take a look at AbstractSpringInjectionEnricher.java registerBean method

My comment was referring to this code snippet:
{code}
  public void testMethod(){
   ctx.getBeanFactory().registerSingleton(dao.getClass().getName(), dao);
  }
{code}

You won't be able to register the beans in such way and autowire it to the test, since this is done in different test phases and at the moment the Spring context is being re-created before each test. The only sollution to access such created bean would be to lookup it through the BeanFactory.

As I see it. We could introduce top level annotation, like for example @SpringStaticConfiguration (or something similar) which will allow to pass array of packages and classes that would be registered. Using this annotation will imply that the test enricher would create StaticApplicationContext and register all the classes/packages. Afterwards it would be used as any other application context. 
                
> Add Spring StaticApplicationContext
> -----------------------------------
>
>                 Key: ARQ-1303
>                 URL: https://issues.jboss.org/browse/ARQ-1303
>             Project: Arquillian
>          Issue Type: Enhancement
>      Security Level: Public(Everyone can see) 
>          Components: Extension - Spring
>            Reporter: omid pourhadi
>            Assignee: Marius Bogoevici
>            Priority: Minor
>   Original Estimate: 1 week, 1 day
>  Remaining Estimate: 1 week, 1 day
>
> It is a common way that developers programmatically register beans into context specially in testing rather than reading bean definitions from external configuration sources, in this case, you need to use StaticApplicationContext.
> As far as my experience concerned, there are some circumstances that you need to have populated context when you are testing
> 1. for registering mock objects into context 
> let's assume we inject a DAO into a service and we want to mock DAO then test our service 
> {code:title=Bar.java|borderStyle=solid}
> public class MockTest(){
>   @Mock
>   Dao dao;
>   public void testMethod(){
>    ctx.getBeanFactory().registerSingleton(dao.getClass().getName(), dao);
>   }
> }
> {code} 
> 2. for specifying classes not packages
> sometimes you need to create a spring context by only some specific classes from different packages not the whole packages.
> It might be good idea to have an annotation ClassToScan({}) to define whcih classes, you want to scan 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the arquillian-issues mailing list