Skip to content

Commit 49388ff

Browse files
committed
Added Patch action spec tests
Also renamed test names from c&p errors
1 parent 4528c6e commit 49388ff

File tree

7 files changed

+67
-9
lines changed

7 files changed

+67
-9
lines changed

springfox-grails/src/main/java/springfox/documentation/grails/PatchActionSpecificationFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public ActionSpecification create(GrailsActionContext context) {
3131
handlerMethod,
3232
new ArrayList<>(Arrays.asList(
3333
pathParameter(1, "id", resolver.resolve(idType(context.getDomainClass()))),
34-
bodyParameter(1, resolver.resolve(domainClass(context.getDomainClass()))))),
34+
bodyParameter(2, resolver.resolve(domainClass(context.getDomainClass()))))),
3535
resolver.resolve(domainClass(context.getDomainClass())));
3636

3737
}

springfox-grails/src/test/groovy/springfox/documentation/grails/CreateActionSpecificationFactorySpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CreateActionSpecificationFactorySpec extends Specification {
3939
spec.handlerMethod.method == AController.methods.find {it.name == "create" }
4040
}
4141

42-
def "Index action throws exception when action is not found" () {
42+
def "Create action throws exception when action is not found" () {
4343
given:
4444
def resolver = new TypeResolver()
4545
def sut = new CreateActionSpecificationFactory(resolver)

springfox-grails/src/test/groovy/springfox/documentation/grails/EditActionSpecificationFactorySpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EditActionSpecificationFactorySpec extends Specification {
2020
domain.identifier.type >> Integer
2121
}
2222

23-
def "Create action produces action specification" () {
23+
def "Edit action produces action specification" () {
2424
given:
2525
def resolver = new TypeResolver()
2626
def sut = new EditActionSpecificationFactory(resolver)
@@ -45,7 +45,7 @@ class EditActionSpecificationFactorySpec extends Specification {
4545
spec.handlerMethod.method == AController.methods.find {it.name == "edit" }
4646
}
4747

48-
def "Index action throws exception when action is not found" () {
48+
def "Edit action throws exception when action is not found" () {
4949
given:
5050
def resolver = new TypeResolver()
5151
def sut = new EditActionSpecificationFactory(resolver)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 PatchActionSpecificationFactorySpec 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 "Patch action produces action specification" () {
24+
given:
25+
def resolver = new TypeResolver()
26+
def sut = new PatchActionSpecificationFactory(resolver)
27+
when:
28+
def spec = sut.create(new GrailsActionContext(controller, domain, "patch"))
29+
then:
30+
spec.consumes == [MediaType.APPLICATION_JSON] as Set
31+
spec.produces == [MediaType.APPLICATION_JSON] as Set
32+
spec.supportedMethods == [RequestMethod.PUT, RequestMethod.POST] as Set
33+
spec.parameters.size() == 2
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+
39+
spec.parameters[1].parameterType == resolver.resolve(ADomain)
40+
spec.parameters[1].parameterIndex == 2
41+
spec.parameters[1].defaultName().isPresent()
42+
spec.parameters[1].defaultName().get() == "body"
43+
44+
spec.returnType == resolver.resolve(ADomain)
45+
spec.handlerMethod.method == AController.methods.find {it.name == "patch" }
46+
}
47+
48+
def "Patch action throws exception when action is not found" () {
49+
given:
50+
def resolver = new TypeResolver()
51+
def sut = new PatchActionSpecificationFactory(resolver)
52+
when:
53+
sut.create(new GrailsActionContext(controller, domain, "unknown"))
54+
then:
55+
def exception = thrown(NullPointerException)
56+
exception.message.contains("Handler method is null")
57+
}
58+
}

springfox-grails/src/test/groovy/springfox/documentation/grails/SaveActionSpecificationFactorySpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SaveActionSpecificationFactorySpec extends Specification {
2020
domain.identifier.type >> Integer
2121
}
2222

23-
def "Create action produces action specification" () {
23+
def "Save action produces action specification" () {
2424
given:
2525
def resolver = new TypeResolver()
2626
def sut = new SaveActionSpecificationFactory(resolver)
@@ -45,7 +45,7 @@ class SaveActionSpecificationFactorySpec extends Specification {
4545
spec.handlerMethod.method == AController.methods.find {it.name == "save" }
4646
}
4747

48-
def "Index action throws exception when action is not found" () {
48+
def "Save action throws exception when action is not found" () {
4949
given:
5050
def resolver = new TypeResolver()
5151
def sut = new SaveActionSpecificationFactory(resolver)

springfox-grails/src/test/groovy/springfox/documentation/grails/ShowActionSpecificationFactorySpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ShowActionSpecificationFactorySpec extends Specification {
3939
spec.handlerMethod.method == AController.methods.find {it.name == "show" }
4040
}
4141

42-
def "Index action throws exception when action is not found" () {
42+
def "Show action throws exception when action is not found" () {
4343
given:
4444
def resolver = new TypeResolver()
4545
def sut = new ShowActionSpecificationFactory(resolver)

springfox-grails/src/test/groovy/springfox/documentation/grails/UpdateActionSpecificationFactorySpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class UpdateActionSpecificationFactorySpec extends Specification {
2020
domain.identifier.type >> Integer
2121
}
2222

23-
def "Create action produces action specification" () {
23+
def "Update action produces action specification" () {
2424
given:
2525
def resolver = new TypeResolver()
2626
def sut = new UpdateActionSpecificationFactory(resolver)
@@ -45,7 +45,7 @@ class UpdateActionSpecificationFactorySpec extends Specification {
4545
spec.handlerMethod.method == AController.methods.find {it.name == "update" }
4646
}
4747

48-
def "Index action throws exception when action is not found" () {
48+
def "Update action throws exception when action is not found" () {
4949
given:
5050
def resolver = new TypeResolver()
5151
def sut = new UpdateActionSpecificationFactory(resolver)

0 commit comments

Comments
 (0)