matrei commented on code in PR #15478:
URL: https://github.com/apache/grails-core/pull/15478#discussion_r2890730113


##########
grails-test-examples/views-functional-tests/src/integration-test/groovy/functional/tests/api/NamespacedBookSpec.groovy:
##########
@@ -16,142 +16,103 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-
 package functional.tests.api
 
-import com.fasterxml.jackson.databind.ObjectMapper
-import functional.tests.Application
-import functional.tests.HttpClientSpec
-import grails.testing.mixin.integration.Integration
-import grails.testing.spock.RunOnce
-import grails.web.http.HttpHeaders
-import io.micronaut.http.HttpRequest
-import io.micronaut.http.HttpResponse
-import io.micronaut.http.HttpStatus
-import io.micronaut.http.MediaType
-import org.junit.jupiter.api.BeforeEach
 import spock.lang.Issue
-import spock.lang.Shared
-
-@Integration(applicationClass = Application)
-class NamespacedBookSpec extends HttpClientSpec {
-
-    @Shared
-    ObjectMapper objectMapper
+import spock.lang.Specification
 
-    def setup() {
-        objectMapper = new ObjectMapper()
-    }
+import grails.testing.mixin.integration.Integration
+import org.apache.grails.testing.httpclient.HttpClientSupport
 
-    @RunOnce
-    @BeforeEach
-    void init() {
-        super.init()
-    }
+@Integration
+class NamespacedBookSpec extends Specification implements HttpClientSupport {
 
     void 'test view rendering with a namespace'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = HttpRequest.GET('/api/book')
-        HttpResponse<Map> rsp = client.toBlocking().exchange(request, Map)
-
-        then: 'The rsponse is correct'
-            rsp.status() == HttpStatus.OK
-            rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-            rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/json;charset=UTF-8'
-            rsp.body().api == 'version 1.0 (Namespaced)'
-            rsp.body().title == 'API - The Shining'
+        def response = http('/api/book')
+
+        then: 'The response is correct'
+        response.expectJson(200, 'Content-Type': 
'application/json;charset=UTF-8', [
+                api: 'version 1.0 (Namespaced)',
+                title: 'API - The Shining'
+        ])
     }
 
     void 'test nested template rendering with a namespace'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = HttpRequest.GET('/api/book/nested')
-        HttpResponse<Map> rsp = client.toBlocking().exchange(request, Map)
-
-        then: 'The rsponse contains the child template'
-        rsp.status() == HttpStatus.OK
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/json;charset=UTF-8'
-        rsp.body().foo == 'bar'
+        def response = http('/api/book/nested')
+
+        then: 'The response contains the child template'
+        response.expectJson(200, 'Content-Type': 
'application/json;charset=UTF-8', [
+                foo: 'bar'
+        ])
     }
 
     void 'test the correct content type is chosen (json)'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = HttpRequest.GET('/api/book')
-        HttpResponse<Map> rsp = client.toBlocking().exchange(request, Map)
+        def response = http('/api/book')
 
         then: 'The response contains the child template'
-        rsp.status() == HttpStatus.OK
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/json;charset=UTF-8'
-        !rsp.body()['_links']
-        rsp.body().api == 'version 1.0 (Namespaced)'
-        rsp.body().title == 'API - The Shining'
+        response.expectJson(200, 'Content-Type': 
'application/json;charset=UTF-8', [
+                api: 'version 1.0 (Namespaced)',
+                title: 'API - The Shining'
+        ])
     }
 
     void 'test the correct content type is chosen (hal)'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = 
HttpRequest.GET('/api/book').accept(MediaType.APPLICATION_HAL_JSON_TYPE)
-        HttpResponse<String> rsp = client.toBlocking().exchange(request, 
String)
-        Map body = objectMapper.readValue(rsp.body(), Map)
+        def response = http('/api/book', 'Accept': 'application/hal+json')
 
         then: 'The response contains the child template'
-        rsp.status() == HttpStatus.OK
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/hal+json;charset=UTF-8'
-        body['_links']
-        body.api == 'version 1.0 (Namespaced HAL)'
-        body.title == 'API - The Shining'
+        response.expectJsonContains(200, 'Content-Type': 
'application/hal+json;charset=UTF-8', [
+                api: 'version 1.0 (Namespaced HAL)',
+                title: 'API - The Shining',
+        ])
+        response.json()._links
     }
 
     void 'test render(view: "..", model: ..) in controllers with namespaces 
works'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = HttpRequest.GET('/api/book/testRender')
-        HttpResponse<Map> rsp = client.toBlocking().exchange(request, Map)
-
-        then: 'The rsponse is correct'
-        rsp.status() == HttpStatus.OK
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/json;charset=UTF-8'
-        rsp.body().api == 'version 1.0 (Namespaced)'
-        rsp.body().title == 'API - The Shining'
+        def response = http('/api/book/testRender')
+
+        then: 'The responseonse is correct'
+        response.expectJson(200, 'Content-Type': 
'application/json;charset=UTF-8', [

Review Comment:
   Good catch!



##########
grails-test-examples/views-functional-tests/src/integration-test/groovy/functional/tests/api/NamespacedBookSpec.groovy:
##########
@@ -16,142 +16,103 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-
 package functional.tests.api
 
-import com.fasterxml.jackson.databind.ObjectMapper
-import functional.tests.Application
-import functional.tests.HttpClientSpec
-import grails.testing.mixin.integration.Integration
-import grails.testing.spock.RunOnce
-import grails.web.http.HttpHeaders
-import io.micronaut.http.HttpRequest
-import io.micronaut.http.HttpResponse
-import io.micronaut.http.HttpStatus
-import io.micronaut.http.MediaType
-import org.junit.jupiter.api.BeforeEach
 import spock.lang.Issue
-import spock.lang.Shared
-
-@Integration(applicationClass = Application)
-class NamespacedBookSpec extends HttpClientSpec {
-
-    @Shared
-    ObjectMapper objectMapper
+import spock.lang.Specification
 
-    def setup() {
-        objectMapper = new ObjectMapper()
-    }
+import grails.testing.mixin.integration.Integration
+import org.apache.grails.testing.httpclient.HttpClientSupport
 
-    @RunOnce
-    @BeforeEach
-    void init() {
-        super.init()
-    }
+@Integration
+class NamespacedBookSpec extends Specification implements HttpClientSupport {
 
     void 'test view rendering with a namespace'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = HttpRequest.GET('/api/book')
-        HttpResponse<Map> rsp = client.toBlocking().exchange(request, Map)
-
-        then: 'The rsponse is correct'
-            rsp.status() == HttpStatus.OK
-            rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-            rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/json;charset=UTF-8'
-            rsp.body().api == 'version 1.0 (Namespaced)'
-            rsp.body().title == 'API - The Shining'
+        def response = http('/api/book')
+
+        then: 'The response is correct'
+        response.expectJson(200, 'Content-Type': 
'application/json;charset=UTF-8', [
+                api: 'version 1.0 (Namespaced)',
+                title: 'API - The Shining'
+        ])
     }
 
     void 'test nested template rendering with a namespace'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = HttpRequest.GET('/api/book/nested')
-        HttpResponse<Map> rsp = client.toBlocking().exchange(request, Map)
-
-        then: 'The rsponse contains the child template'
-        rsp.status() == HttpStatus.OK
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/json;charset=UTF-8'
-        rsp.body().foo == 'bar'
+        def response = http('/api/book/nested')
+
+        then: 'The response contains the child template'
+        response.expectJson(200, 'Content-Type': 
'application/json;charset=UTF-8', [
+                foo: 'bar'
+        ])
     }
 
     void 'test the correct content type is chosen (json)'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = HttpRequest.GET('/api/book')
-        HttpResponse<Map> rsp = client.toBlocking().exchange(request, Map)
+        def response = http('/api/book')
 
         then: 'The response contains the child template'
-        rsp.status() == HttpStatus.OK
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/json;charset=UTF-8'
-        !rsp.body()['_links']
-        rsp.body().api == 'version 1.0 (Namespaced)'
-        rsp.body().title == 'API - The Shining'
+        response.expectJson(200, 'Content-Type': 
'application/json;charset=UTF-8', [
+                api: 'version 1.0 (Namespaced)',
+                title: 'API - The Shining'
+        ])
     }
 
     void 'test the correct content type is chosen (hal)'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = 
HttpRequest.GET('/api/book').accept(MediaType.APPLICATION_HAL_JSON_TYPE)
-        HttpResponse<String> rsp = client.toBlocking().exchange(request, 
String)
-        Map body = objectMapper.readValue(rsp.body(), Map)
+        def response = http('/api/book', 'Accept': 'application/hal+json')
 
         then: 'The response contains the child template'
-        rsp.status() == HttpStatus.OK
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/hal+json;charset=UTF-8'
-        body['_links']
-        body.api == 'version 1.0 (Namespaced HAL)'
-        body.title == 'API - The Shining'
+        response.expectJsonContains(200, 'Content-Type': 
'application/hal+json;charset=UTF-8', [
+                api: 'version 1.0 (Namespaced HAL)',
+                title: 'API - The Shining',
+        ])
+        response.json()._links
     }
 
     void 'test render(view: "..", model: ..) in controllers with namespaces 
works'() {
         when: 'A request is sent to a controller with a namespace'
-        HttpRequest request = HttpRequest.GET('/api/book/testRender')
-        HttpResponse<Map> rsp = client.toBlocking().exchange(request, Map)
-
-        then: 'The rsponse is correct'
-        rsp.status() == HttpStatus.OK
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).isPresent()
-        rsp.headers.getFirst(HttpHeaders.CONTENT_TYPE).get() == 
'application/json;charset=UTF-8'
-        rsp.body().api == 'version 1.0 (Namespaced)'
-        rsp.body().title == 'API - The Shining'
+        def response = http('/api/book/testRender')
+
+        then: 'The responseonse is correct'
+        response.expectJson(200, 'Content-Type': 
'application/json;charset=UTF-8', [
+                api: 'version 1.0 (Namespaced)',
+                title: 'API - The Shining'
+        ])
     }
 
-    void 'test rspond(foo, view: ..) in controllers with namespaces works'() {
+    void 'test responseond(foo, view: ..) in controllers with namespaces 
works'() {
         when: 'A request is sent to a controller with a namespace'

Review Comment:
   Good catch!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to