I'm trying to write a unit test for a simple controller that takes GSON as input and writes to DB.
GSON because, the input has nested objects.
Controller implementation:
def create() {
def artist = new Artist(request.GSON)
if (!artist.save(flush: true)) {
artist.errors.each {
log.error("Error while creating Artist " + it)
}
render status: 500, layout: null
return
}
response.status = 201
render artist as GSON
}
Unit test:
@TestMixin(GsonUnitTestMixin)
@TestFor(ArtistController)
@Mock(Artist)
class ArtistControllerTests {
void testCreate() {
request.GSON = "{guid:123,"+
"name: 'Akon',"+
"albums: ["+
"{guid:1,"+
"name:'album 1'"+
"}]}"
controller.create()
assert response.status == 201
}
}
Exception:
Cannot get property 'manyToOne' on null object at
def artist = new Artist(request.GSON) in the controller
I'm trying to write a unit test for a simple controller that takes GSON as input and writes to DB.
GSON because, the input has nested objects.
Controller implementation:
Unit test:
Exception:
Cannot get property 'manyToOne' on null object at
def artist = new Artist(request.GSON) in the controller