|
| 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 org.springframework.http.MediaType |
| 8 | +import org.springframework.web.bind.annotation.RequestMethod |
| 9 | +import spock.lang.Specification |
| 10 | + |
| 11 | +class DeleteActionSpecificationFactorySpec extends Specification { |
| 12 | + def controller = Mock(GrailsControllerClass) |
| 13 | + def domain = Mock(GrailsDomainClass) |
| 14 | + def identifierProperty = Mock(GrailsDomainClassProperty) |
| 15 | + |
| 16 | + def setup() { |
| 17 | + controller.clazz >> AController |
| 18 | + domain.clazz >> ADomain |
| 19 | + domain.identifier >> identifierProperty |
| 20 | + domain.identifier.type >> Integer |
| 21 | + } |
| 22 | + |
| 23 | + def "Delete action produces action specification" () { |
| 24 | + given: |
| 25 | + def resolver = new TypeResolver() |
| 26 | + def sut = new DeleteActionSpecificationFactory(resolver) |
| 27 | + when: |
| 28 | + def spec = sut.create(new GrailsActionContext(controller, domain, "delete")) |
| 29 | + then: |
| 30 | + spec.consumes == [MediaType.APPLICATION_JSON] as Set |
| 31 | + spec.produces == [MediaType.APPLICATION_JSON] as Set |
| 32 | + spec.supportedMethods == [RequestMethod.GET] as Set |
| 33 | + spec.parameters.size() == 1 |
| 34 | + spec.parameters[0].parameterType == resolver.resolve(Integer) |
| 35 | + spec.parameters[0].parameterIndex == 1 |
| 36 | + spec.parameters[0].defaultName().isPresent() |
| 37 | + spec.parameters[0].defaultName().get() == "id" |
| 38 | + spec.returnType == resolver.resolve(ADomain) |
| 39 | + spec.handlerMethod.method == AController.methods.find {it.name == "delete" } |
| 40 | + } |
| 41 | + |
| 42 | + def "Delete action throws exception when action is not found" () { |
| 43 | + given: |
| 44 | + def resolver = new TypeResolver() |
| 45 | + def sut = new DeleteActionSpecificationFactory(resolver) |
| 46 | + when: |
| 47 | + sut.create(new GrailsActionContext(controller, domain, "unknown")) |
| 48 | + then: |
| 49 | + def exception = thrown(NullPointerException) |
| 50 | + exception.message.contains("Handler method is null") |
| 51 | + } |
| 52 | +} |
0 commit comments