Wild guess here, but m_dao is never initialized so I assume a NullPointerException when you try to set the m_dao-Datasource.
Cheers Marc Heimann Software Engineer Prolifics Deutschland GmbH Notkestr. 3, D-22607 Hamburg phone +49 (0)40 890 667-70 fax +49 (0)40 890 667-99 [EMAIL PROTECTED] SOA... Building the Future into Your Business Handelsregister: Hamburg, HRB 89903 Geschäftsführer: Ulrich Frotscher francesco77 <[EMAIL PROTECTED]> wrote on 20.04.2007 13:30:22: > > Hi to All, > > I'd like to write a TestCase using JUnit to test my DAO. > This DAO works correctly using the WEB Application, but I'd like write a > "standalone" test case for the DAO. > > So I write this java class : > > ***************************************************************** > > package com.fiat.mida.controller.dashboard; > > import java.io.IOException; > import java.io.Reader; > import java.util.Map; > > import org.springframework.jdbc.CannotGetJdbcConnectionException; > import org.springframework.jdbc.datasource.DriverManagerDataSource; > import org.springframework.jdbc.datasource.SingleConnectionDataSource; > > import com.fiat.mida.model.dashboard.SearchBean; > > import junit.framework.TestCase; > > import com.fiat.mida.model.dashboard.dao.SearchRefuseDao; > import com.fiat.mida.model.dashboard.logic.*; > import com.ibatis.common.resources.Resources; > import com.ibatis.sqlmap.client.SqlMapClient; > import com.ibatis.sqlmap.client.SqlMapClientBuilder; > > public class AbstractTest extends TestCase{ > > private SearchRefuseService service; > private SearchBean bean; > private String resource = > "com/fiat/mida/controller/dashboard/test-sql-map-config.xml"; > > private Reader reader ; > > protected DriverManagerDataSource m_dataSource; > protected SqlMapClient m_sqlMapClient; > private SearchRefuseDao m_dao; > > protected void setUp() { > > try { > reader = Resources.getResourceAsReader(resource); > m_dataSource = new SingleConnectionDataSource(); > m_dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); > System.out.println("driver OK!! "); > m_dataSource.setUrl("jdbc:hsqldb:svuni000.replynet.prv: > 1522:AHZ7O01S"); > m_dataSource.setUsername("AHZ7OP1000"); > m_dataSource.setPassword("AHZ7OP1000"); > System.out.println("data source created"); > m_sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader); > System.out.println("sql map created"); > m_dao.setDataSource(m_dataSource); > System.out.println("Setted data source on DAO"); > m_dao.setSqlMapClient(m_sqlMapClient); > System.out.println("Setted sql map on DAO"); > } catch (CannotGetJdbcConnectionException e) { > System.out.println("no jdbc connection"); > e.printStackTrace(); > } catch (IOException e) { > System.out.println("IO Exception"); > e.printStackTrace(); > } > } > > > public void tearDown() { > > } > > public void testProva(){ > > bean = new SearchBean(); > bean.setFonte("ACDEK100"); > Integer dimStat = service.findCountStatisticGroup(bean); > assertEquals(584, dimStat.intValue()); > } > > } > > *********************************************************************** > > The test-sql-map-config.xml file is: > > ************************************************************************ > > <?xml version="1.0" encoding="UTF-8" ?> > > <!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config > 2.0//EN" > "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> > > <!-- List of all iBatis SQL maps grouped by package name. --> > <sqlMapConfig> > > <settings useStatementNamespaces="true" /> > > <sqlMap resource="com/fiat/mida/model/dashboard/dao/SearchRefuse.xml" /> > > </sqlMapConfig> > > ************************************************************************ > > And the SearchRefuseDao class is: > > ************************************************************************** > > package com.fiat.mida.model.dashboard.dao; > > import java.util.HashMap; > import java.util.List; > import java.util.Map; > > import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; > > import com.fiat.mida.model.dashboard.SearchBean; > > public class SearchRefuseDao extends SqlMapClientDaoSupport { > > /** Map for a single thread to hold query parameters. */ > private static ThreadLocal messageKeyOfThread = new ThreadLocal() { > protected Object initialValue() { > return new HashMap(3); > } > }; > > /** > * conta il numero di statistiche degli scarti che soddisfano i criteri di > * ricerca. Serve per la paginazione > * > * @param bean: > * parametri di ricerca > * @return: il numero di record di statistiche > */ > public Integer getCountStatistics(SearchBean bean) { > Map messageKey = (Map) messageKeyOfThread.get(); > messageKey.put("sourceCode", bean.getFonte()); > messageKey.put("dataAcq", bean.getDati()); > return (Integer) getSqlMapClientTemplate().queryForObject( > "SearchRefuse.getCountStatisticGroup", messageKey); > > } > > } > > ************************************************************ > > When I run this TestCase I have this output: > > Apr 20, 2007 1:27:41 PM > org.springframework.jdbc.datasource.DriverManagerDataSource > setDriverClassName > INFO: Loaded JDBC driver: org.hsqldb.jdbcDriver > driver OK!! > data source created > sql map created > > And I don't know why my test stop at that point. > > Someone could help me ? > > Thanks a lot for any suggestion, > > Have a good day, > Francesco > > > -- > View this message in context: http://www.nabble.com/JUnit-Test-with- > IBatis-tf3615809.html#a10098759 > Sent from the iBATIS - User - Java mailing list archive at Nabble.com. >
gifpOjLP7OuoE.gif
Description: GIF image