java - How Do I use a bunch of DAO's using in-memory derby database using spring autowiring.? -
i have collection of dals such transaction dao, billing dao etc. each of them have crud operations , need use methods in project using spring autowiring. in of projects have checked out, saw fetching data inmemory querying. however, have use dal's have been written , have crud operations.
for example:
@autowired transactiondao transactiondao @autowired billingdao billingdao @test public void testimplementsearchmethodfordao() throws exception{ transactionvo transactionvo = gettransvo(); billingvo billingvo = getbillingvo(); list<transactionvo> volist1 = transactiondao.searchlist(transactionvo); list<billingvo> volist2 = billingdao.searchlist(billingvo); assertthat(volist1.size()).isequalto(1)); assertthat(volist1.size()).isequalto(1)); } (assuming added 1 vo value in each table). if need more clarifications, glad provide you.
you can use setters , use @autowire annotation on setters. test code must inject daos using these setters. in tests build in mem: db instance , build connection pool or datasource or whatever need , build daos based of that.
your setup() this
bonecpconfig config = new bonecpconfig(); config.setjdbcurl("jdbc:hsqldb:mem:test_common;shutdown=false"); config.setusername("sa"); config.setpassword(""); jdbctemplate datasource = new bonecpdatasource(config); jdbctemplate = new jdbctemplate(datasource); //if using named queries namedparameterjdbctemplate namedparameterjdbctemplate = new namedparameterjdbctemplate(datasource); //create necessary tables etc here. setupdb(jdbctemplate); somebean anotherbean = new somebean(); yourdao dao = new yourdaoimpl(); dao.setnamedjdbctemplate(namedparameterjdbctemplate); dao.setsomeotherbean(anotherbean); //mimic spring container if implement initialzingbean dao.afterpropertiesset();
once dependencies injected run tests usual.
Comments
Post a Comment