I am testing a service in Testbox and get an error to load the DAO dependency injected by wirebox in the service. Here is the test:
component extends=“coldbox.system.testing.BaseTestCase” appMapping="/" {
/*********************************** LIFE CYCLE Methods ***********************************/
function beforeAll(){
super.beforeAll();
//Create the service to test, do not remove methods, just prepare for mocking.
geozoneService = createMock(“models.crd.GeozoneSVC”);
// Mock the entity bean
mockBean = createEmptyMock(className=“models.crd.Geozone”);
// Mock the DAO object
mockDAO = createMock(className=‘models.crd.GeozoneDAO’);
// Mock the Gateway object
mockGW = createMock(className=“models.crd.GeozonesGW”);
//Init the service with mock dependencies
geozoneService.init(mockBean,mockDAO,mockGW);
}
function afterAll(){
// do your own stuff here
super.afterAll();
}
/*********************************** BDD SUITES ***********************************/
function run(){
describe( “Geozone service”, function(){
aroundEach( function( spec, suite ){
transaction action=“begin”{
try{
// execute the spec
arguments.spec.body();
} catch( Any e ){
rethrow;
} finally {
transaction action=“rollback”;
// Empty the databean target instance after each specification run
var databean = “”;
}
}
} );
beforeEach(function( currentSpec ){
// Setup as a new ColdBox request for this suite, VERY IMPORTANT. ELSE EVERYTHING LOOKS LIKE THE SAME REQUEST.
setup();
});
it(“can read a geozone record”, function(){
mockBean.setGeozoneID(18);
mockBean.setGeozoneName(“SOUTH EAST ASIA”);
mockBean.setGeozoneWestOffset(25200);
mockBean.setGeozoneEastOffset(28800);
// Create an instance of the target bean to hold the simulated data
dataBean = createObject(‘component’, ‘models.crd.Geozone’).init();
// This test must succeed.
// Populate dataBean with the data returned by the read method.
// expect mockBean to match dataBean
databean = geozoneService.read(18);
expect( databean.getGeozoneID() ).toBe( mockBean.getGeozoneID() );
expect( databean.getGeozoneName() ).toBe( mockBean.getGeozoneName() );
expect( databean.getGeozoneWestOffset() ).toBe( mockBean.getGeozoneWestOffset() );
expect( databean.getGeozoneEastOffset() ).toBe( mockBean.getGeozoneEastOffset() );
});
In the service, I have injected the DAO as follows:
component singleton accessors=“true”{
// Dependency Injection
property name=“dao” inject=“models.crd.GeozoneDAO”;
property name=“gw” inject=“models.crd.GeozonesGW”;
property name=“objGMT” inject=“models.utils.datetime.GMTconvSVC”;
property name=“log” inject=“logbox:logger:{this}”;
property name=“populator” inject=“wirebox:populator”;
property name=“wirebox” inject=“wirebox”;
function init(){
return this;
}
…
}
The test results are attached.
What am I missing?