Pregunta

I am trying to write an integration test using AbstractTransactionalJUnit4SpringContextTests. I want to use executeSQLScript method of this class.

However, when executeSQLScript method is called, it throws NullPointerException because simpleJdbcTemplate parameter of class AbstractTransactionalJUnit4SpringContextTests is not getting initialized.

My code looks as given below:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:test-services-spring-context.xml"})
@TransactionConfiguration(transactionManager = "promoTransactionManager")
public class PromoBrickDAOIT extends AbstractTransactionalJUnit4SpringContextTests {

    @Autowired
    private PromoBricksDAO promoBricksDAO;

    @Before
    public void setUp(){
        executeSqlScript("classpath:testdata/sql/PromoBrick_Create.sql",     false);
    }

    @After
    public void tearDown(){
    }

    @Test  
    public void testPromoBrickGivenBrowseTaxonomyNodeId(){
        String btxNodeId = "v1_12";
        List<PromoBrick> promoBricks =     promoBricksDAO.findByBtxNodeId(btxNodeId);
        assertNotNull(promoBricks);
        assertEquals(promoBricks.size(), 1);
        PromoBrick promoBrick = promoBricks.get(0);
        assertNotNull(promoBrick);
    }


    public void setDataSource (@Qualifier("promoDataSource") DataSource     dataSource)    {
            super.setDataSource(dataSource);
    }
}

Thanks in advance for the help!

¿Fue útil?

Solución

You're missing @Autowired on your setDataSource() method.

See the last NOTE in the Dependency injection of test fixtures section of the Spring Reference Manual.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top