Skip to content

Instantly share code, notes, and snippets.

@kimberleehowley
Last active January 22, 2020 20:21
Show Gist options
  • Save kimberleehowley/cbb1c01e3b5de51a43a3302a5eca01e4 to your computer and use it in GitHub Desktop.
Save kimberleehowley/cbb1c01e3b5de51a43a3302a5eca01e4 to your computer and use it in GitHub Desktop.
package com.testguide
import com.testguide.CampaignService
import com.testguide.User
import com.testguide.dataservice.UserDataService
import grails.testing.mixin.integration.Integration
import grails.web.servlet.mvc.GrailsParameterMap
import org.springframework.mock.web.MockHttpServletRequest
import org.springframework.test.annotation.Rollback
import org.springframework.transaction.annotation.Transactional
import spock.lang.Specification
/**
* Test class for {@link CampaignService}
*/
@Integration
@Transactional
@Rollback
class CampaignServiceSpec extends Specification {
UserDataService userDataService
//class under test
CampaignService campaignService
def setup() {//for this spec the setup does not have to do anything
}
void "list all campaigns"() {
given: "a user"
User user = userDataService.findById(1)
and: "an instance of GrailsParameterMap"
def requestParams = [startDate: '2019-03-06', endDate: '2019-03-08']
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest()
mockHttpServletRequest.parameters = requestParams
mockHttpServletRequest.getParameterMap()
def params = new GrailsParameterMap(mockHttpServletRequest)
when: "a call to list campaigns is made"
Tuple2 result = campaignService.list(user, params)
then: "result"
result
and: "it contains the campaign list"
result.first.campaignList
and: "the campaign list is 3"
result.first.campaignList.size() == 3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment