-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSearchControllerSpec.groovy
95 lines (72 loc) · 3.01 KB
/
SearchControllerSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package au.org.ala.merit
import au.org.ala.merit.hub.HubSettings
import grails.testing.web.controllers.ControllerUnitTest
import org.apache.http.HttpStatus
import spock.lang.Specification
class SearchControllerSpec extends Specification implements ControllerUnitTest<SearchController> {
SearchService searchService = Mock(SearchService)
WebService webService = Mock(WebService)
CommonService commonService = Mock(CommonService)
UserService userService = Mock(UserService)
void setup() {
controller.userService = userService
controller.searchService = searchService
controller.webService = webService
controller.commonService = commonService
}
def "The search controller accepts a request to download data and delegates to the SearchService"() {
when:
controller.downloadAllData()
then:
1 * userService.userIsSiteAdmin() >> true
1 * searchService.downloadAllData(params) >> [status:HttpStatus.SC_OK]
and:
response.status == HttpStatus.SC_OK
and:
params.downloadUrl.endsWith('download/')
params.systemEmail == 'merit@ala.org.au'
params.senderEmail == 'merit@ala.org.au'
}
def "The search controller accepts a request to download a shapefile and delegates to the SearchService"() {
when:
controller.downloadShapefile()
then:
1 * userService.userIsSiteAdmin() >> true
1 * searchService.downloadShapefile(params) >> true
and:
response.status == HttpStatus.SC_OK
response.json.status == HttpStatus.SC_OK
and:
params.downloadUrl.endsWith('download/')
params.systemEmail == 'merit@ala.org.au'
params.senderEmail == 'merit@ala.org.au'
}
def "The search controller accepts a request to download a user data and delegates to ecodata"() {
when:
SettingService.setHubConfig(new HubSettings(hubId:"merit"))
controller.downloadUserData()
then:
1 * webService.doPostWithParams({ it.endsWith("search/downloadUserList") }, [:]) >> [status:HttpStatus.SC_OK]
1 * commonService.buildUrlParamsFromMap(params) >> ""
and:
response.json.status == HttpStatus.SC_OK
and:
params.downloadUrl.endsWith('download/')
params.systemEmail == 'merit@ala.org.au'
params.senderEmail == 'merit@ala.org.au'
params.hubId == "merit"
}
def "The search controller accepts a request to download organisation data and delegates to ecodata"() {
when:
controller.downloadOrganisationData()
then:
1 * webService.doPostWithParams({ it.endsWith("search/downloadOrganisationData") }, [:]) >> [status:HttpStatus.SC_OK]
1 * commonService.buildUrlParamsFromMap(params) >> ""
and:
response.json.status == HttpStatus.SC_OK
and:
params.downloadUrl.endsWith('download/')
params.systemEmail == 'merit@ala.org.au'
params.senderEmail == 'merit@ala.org.au'
}
}