Uploaded image for project: 'Arquillian'
  1. Arquillian
  2. ARQ-1303

Add Spring StaticApplicationContext

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • Extension - Spring
    • None

      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

      Bar.java
      public class MockTest(){
      
        @Mock
        Dao dao;
      
        public void testMethod(){
         ctx.getBeanFactory().registerSingleton(dao.getClass().getName(), dao);
        }
      
      }
      

      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

            jmnarloch Jakub Narloch (Inactive)
            vata2999 omid pourhadi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - 1 week, 1 day
                1w 1d
                Remaining:
                Remaining Estimate - 1 week, 1 day
                1w 1d
                Logged:
                Time Spent - Not Specified
                Not Specified