Below is my action in the controller. I am to btest this action via an integration test. This would require me to mock the session objects as well. I have started with the integration test , but hve no luck with it.
def listData= {
def playerId=session["playerId”]
tuneInstanceList = tuneService.calculateId(playerId)
def listResult = [total: tuneInstanceList.size(), items: tuneInstanceList]
render listResult as JSON;
}
Below is the CalculateId method in my service class:
List calculateId(String playerId) {
try{
//read the sql file
String playerSql = grailsApplication.mainContext.getResource('classpath:' + Constants.PLAYER_FILE).inputStream.text
def sql = new groovy.sql.Sql(dataSource)
def params = [playerId:playerId]
def tuneInstanceList = new ArrayList<Tune>()
def results = sql.rows(playerSql, params)
tuneInstanceList = results.each {
def tune = new Tune()
tune.setPlayerId it.player_id
tuneInstanceList.add tune
}
return tuneInstanceList
}catch (Exception ex) {
log.error ex.message, ex
throw ex
}
//finally {
//sql.close()
//}
}
Below is the Integration Test that I wrote. This isn’t correct and I am not sure what I should be putting up here. Inputs?
public void testQuery () {
def myController = new TuneController()
myController.request.contentType = "text/json"
myController.tuneService = tuneService
myController.listData()
String actualJSON = myController.response.contentAsString
assertNotNull(actualJSON)
}
I get the belwo error when I run the test.
Cannot get property 'request' on null object
java.lang.NullPointerException: Cannot get property 'request' on null object
Thoughts??