When trying to create integration test for existing legacy database schema I cannot instantiate the domain class inside the integration test or with the controller class itself.
ex:
I have a County Domain Class with a corresponding hbm file located in the hiberate directory.
I also have the crud created with generate-all CountyController plus views.
I also have an Integration Test CountyTest that call a method on the CountyController .countyCombo.
The problem is that I cannot create/instantiate the County Object from within the CountyTest integration test and also the countyCombo will not let me create
a County object either. Files are attached but here is the example code from the Integration test CountyTest and the CountyController countyCombo method
I think this must have to do something with the hibernate hbm and how spring is loading it in the context. If I create just a plain domain object using grails it allows me to instantiate it both in the Integration test and the Controller.
class CountyTests extends GroovyTestCase {
void testSomething() {
def cc = new CountyController()
def cty = new County() // this is not working. Always is null
println(cc)
def aList = cc.countyCombo()
assert(aList.size() == 100)
}
}
//CountyController class
def countyCombo = {
def countyList = new ArrayList()
def county = new County() // This does not create a County either
println(county)
countyList = County.findAll() // Here is where I am getting the NullPointerException
LabelValueBean lvb = new LabelValueBean("*Select*", null);
List aList = new ArrayList();
for(County in countyList){
aList.add(new LabelValueBean(County.getName(), County.getId()));
}
return aList
}