Announcement Announcement Module
Collapse
No announcement yet.
AbstractDependencyInjectionSpringContextTests and beanRefFactory.xml - how to ...? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractDependencyInjectionSpringContextTests and beanRefFactory.xml - how to ...?

    Hi,

    I am trying to create a unit integration test by extending AbstractDependencyInjectionSpringContextTests class. The thing is I need my unit test to be initialized from the bean factory described in a separate xml file.

    For example, I have the following beanRefFactory.xml file:

    Code:
    <beans>
      <bean id="com.artilekt.modules.jetmailer" lazy-init="true"
            class="org.springframework.context.support.ClassPathXmlApplicationContext">
        <constructor-arg>
          <list>
            <value>classpath*:com/artilekt/modules/jetmailer/**/beans.xml</value>
            <value>classpath*:com/artilekt/modules/template/**/beans.xml</value>
            <value>com/artilekt/modules/configurer/beans.xml</value>
          </list>
        </constructor-arg>
      </bean>
    </beans>
    I want my unit test to be initialized from the beans loaded by the 'com.artilekt.modules.jetmailer' factory described in this xml file. How can I do that?

    Returning this xml file from 'getConfigLocations' method doesn't really work, since it only loads the factory bean itself, but the protected fields and/or setters of the unit test class are still not initialized I tried to override 'contextKey' and getContext methods, but not sure what they mean, so for now just getting a bunch of exceptions.

    My next step would be to go to the source code to figure out how this bootstrap works, but if I can avoid that, that would have been great!

    Thanks!

  • #2
    It might help you to look at the source code anyway because it's actually pretty simple. You need to override loadContext(Object) to read your factory config and return the required application context, e.g. using SingletonBeanFactoryLocator (or a factory that you write to wrap that class).

    Comment

    Working...
    X