Announcement Announcement Module
Collapse
No announcement yet.
JUnit tests - Support multiple databases Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JUnit tests - Support multiple databases

    Hello spring forum,

    I read that AbstractTransactionalSpringContextTests is designed to support a single database. Does anybody have an idea how to make AbstractTransactionalSpringContextTests to support multiple databases?

    One idea could be to extend AbstractTransactionalSpringContextTests and add several transaction managers, would this be a good idea or what do you think about it? Any suggestions or ideas are welcome.


    Thanks,

  • #2
    I guess you could use something like JOTM(http://jotm.objectweb.org/).

    Comment


    • #3
      when you use AbstractTransactionalDataSourceSpringContextTests, Spring autowire the bean by type. So you cannot specify multiple bean say for e.g datasource of the same type. I have the same requirement to go to different oracle database schemas for fetching data and do the assertions. This is how I used multiple datasources along with AbstractTransactionalDataSourceSpringContextTests.

      I have used seperate spring context for different datasources and then I used the following line of code to load a seperate datasource in appripriate junit tests.

      ApplicationContext context = new ClasspathXmlApplicationContext(new String[] {"context_file.xml"})

      Write an API say getAbcDataSource()

      private DataSource abcDataSource;
      public Datasource getAbdDataSource(){
      abcDataSource = (DataSource)context.getBean("abcDataSource");
      }

      Comment


      • #4
        Same need here

        Hi,

        did someone solve this one? Is there any way to turn autowiring off?

        I would prefer not to have autowire and therefore have the rollback feature.

        I badly need to be able to run tests over configs with *multiple* datasources configured. There is no way to split them as it would wrap my assembly inside out.

        brgds,

        Papick G. Taboada

        Comment


        • #5
          You can turn autowire off: see setAutowire method from AbstractTransactionalSpringContextTests.

          Comment


          • #6
            I have multiple datasources / transaction managers in my app.
            Here is what I did to get around the org.springframework.beans.factory.UnsatisfiedDepen dencyException:

            public class AbcTest extends AbstractTransactionalSpringContextTests{
            public AbcTest(){
            super();
            setAutowireMode(this.AUTOWIRE_BY_NAME);
            }
            ...
            }

            By using the AUTOWIRE_BY_NAME mode, AbstractTransactionalSpringContextTests is looking to inject the bean with the name "transactionManager", instead of looking for a bean of type PlatformTransactionManager. It will find multiple beans by type, but only one bean by name, thus the exception is prevented.

            Hope this helps someone.

            Comment

            Working...
            X