Skip to content

Commit 600d708

Browse files
committed
Added test for Action Spec Resolver
1 parent 37c55bf commit 600d708

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package springfox.documentation.grails
2+
3+
import com.fasterxml.classmate.TypeResolver
4+
import grails.core.GrailsControllerClass
5+
import grails.core.GrailsDomainClass
6+
import grails.core.GrailsDomainClassProperty
7+
import grails.web.mapping.LinkGenerator
8+
import grails.web.mapping.UrlMapping
9+
import grails.web.mapping.UrlMappings
10+
import spock.lang.Specification
11+
12+
class ActionSpecificationResolverSpec extends Specification {
13+
def resolver = new TypeResolver()
14+
def controller = Mock(GrailsControllerClass)
15+
def domain = Mock(GrailsDomainClass)
16+
def identifierProperty = Mock(GrailsDomainClassProperty)
17+
def links = Mock(LinkGenerator)
18+
def urlMappings = Mock(UrlMappings)
19+
GrailsActionAttributes actionAttributes
20+
21+
def setup() {
22+
controller.clazz >> AController
23+
controller.name >> "A"
24+
domain.clazz >> ADomain
25+
domain.identifier >> identifierProperty
26+
domain.identifier.type >> Integer
27+
actionAttributes = new GrailsActionAttributes(links, urlMappings)
28+
}
29+
30+
def "Resolves restful and method backed actions"() {
31+
given:
32+
def sut = new MethodBackedActionSpecificationFactory(resolver, actionAttributes)
33+
and:
34+
urlMappings.urlMappings >> [otherMapping(Mock(UrlMapping))]
35+
when:
36+
def spec = sut.create(new GrailsActionContext(controller, domain, action))
37+
then:
38+
spec != null
39+
spec.handlerMethod.method.name == action
40+
where:
41+
action << ["index", "save", "show", "edit", "update", "delete", "patch", "create", "other"]
42+
}
43+
44+
def otherMapping(UrlMapping urlMapping) {
45+
urlMapping.controllerName >> "A"
46+
urlMapping.actionName >> "other"
47+
urlMapping.httpMethod >> "POST"
48+
urlMapping
49+
urlMapping
50+
}
51+
}

0 commit comments

Comments
 (0)