I’m writing a unit test for some simple methods. The issue I am having is that ‘save’ is not working for my domain object even though the domain should be mocked. When calling validate on the domain object, it comes back as true. I’ve even surrounded the object with try/catch to make sure it wasn’t throwing any odd errors and that is not the case. Code below for call and test.
void test()
{
mockDomain(MyDomain)
Map map1= ["asdf":" "]
Map map2 = ["asdf":123]
InputObject input = new InputObject()
input.setForeignId("1") //not a constraint
input.setMap1(map1)
input.setMap2(map2 )
service.methodUnderTest(profile)
List list = MyDomain.getAll()
assertEquals 1, l.size() //FAILS
}
def persistPublishGuids(InputObject input)
{
try{
HashMap map1 = input.map1
for ( e in map1 )
{
String key= e.getKey()
String value = e.value
long size = input.map2.get(key)
MyDomain domain = new MyDomain (id:guid, field1:value, field2:input.foreignId, field3:size)
domain.save()
}
} catch(ex)
{
ex.printStackTrace()
}
}
The problem was that the grails app needed to be cleaned and the project rebuilt.