Copilot commented on code in PR #15411:
URL: https://github.com/apache/grails-core/pull/15411#discussion_r2827712804


##########
grails-test-examples/micronaut/src/integration-test/groovy/micronaut/MicronautBeanTypesSpec.groovy:
##########
@@ -0,0 +1,84 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package micronaut
+
+import bean.injection.AppConfig
+import bean.injection.FactoryCreatedService
+import bean.injection.JavaSingletonService
+
+import grails.testing.mixin.integration.Integration
+import org.springframework.beans.factory.annotation.Autowired
+import spock.lang.Specification
+
+/**
+ * Integration tests for various Micronaut bean registration mechanisms in 
Grails context.
+ *
+ * Tests that:
+ * 1. Java @Singleton beans (processed via annotation processor) are available 
in Spring context
+ * 2. Groovy @Factory/@Bean beans (processed via AST transform) are available 
in Spring context
+ * 3. @ConfigurationProperties beans reflect Grails application.yml config 
into Micronaut
+ */
+@Integration
+class MicronautBeanTypesSpec extends Specification {
+
+    @Autowired
+    JavaSingletonService javaSingletonService
+
+    @Autowired
+    FactoryCreatedService factoryCreatedService
+
+    @Autowired
+    AppConfig appConfig
+
+    void "Java @Singleton bean is available via Spring autowiring"() {
+        expect: "bean is injected and functional"
+        javaSingletonService != null
+        javaSingletonService.message == 'from-java-singleton'
+    }
+
+    void "Groovy @Factory/@Bean created bean is available via Spring 
autowiring"() {
+        expect: "bean is injected with factory-configured values"
+        factoryCreatedService != null
+        factoryCreatedService.name == 'factory-created'
+    }
+
+    void "@ConfigurationProperties bean reflects application.yml config"() {
+        expect: "config properties are bound from application.yml"
+        appConfig != null
+        appConfig.name == 'test-micronaut-app'
+    }
+
+    void "Java @Singleton bean is a singleton instance"() {
+        when:
+        def first = javaSingletonService
+        def second = javaSingletonService
+
+        then: "same instance is returned"
+        first.is(second)
+    }
+
+    void "Factory-created bean is a singleton instance"() {
+        when:
+        def first = factoryCreatedService
+        def second = factoryCreatedService
+
+        then: "same instance is returned (factory method annotated with 
@Singleton)"
+        first.is(second)
+    }

Review Comment:
   These “singleton” assertions are ineffective because both `first` and 
`second` reference the same injected field, so the test will always pass even 
if the bean is not singleton-scoped. To actually verify singleton scope, 
retrieve the bean twice from the Spring and/or Micronaut context (e.g., 
`applicationContext.getBean(...)` twice) or inject two separate lookups and 
compare them.



##########
grails-test-examples/micronaut/src/main/java/bean/injection/JavaSingletonService.java:
##########
@@ -0,0 +1,34 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package bean.injection;
+
+import jakarta.inject.Singleton;
+
+interface JavaMessageProvider {
+
+    String getMessage();
+
+}
+
+@Singleton
+public class JavaSingletonService implements JavaMessageProvider {
+
+    @Override

Review Comment:
   `JavaMessageProvider` is declared but not referenced anywhere in the module, 
which adds dead code to the example. Consider removing the interface (or adding 
a test/assertion that exercises injection by the interface type) to keep the 
example focused.
   ```suggestion
   @Singleton
   public class JavaSingletonService {
   ```



##########
grails-test-examples/micronaut/grails-app/controllers/micronaut/MicronautTestController.groovy:
##########
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package micronaut
+
+import bean.injection.AppConfig
+import bean.injection.FactoryCreatedService
+import bean.injection.JavaSingletonService
+import bean.injection.NamedService
+import groovy.transform.CompileStatic
+
+import org.springframework.beans.factory.annotation.Autowired
+
+@CompileStatic
+class MicronautTestController {
+
+    @Autowired
+    JavaSingletonService javaSingletonService
+
+    @Autowired
+    FactoryCreatedService factoryCreatedService
+
+    @Autowired
+    AppConfig appConfig
+
+    @Autowired
+    NamedService namedService
+
+    def index() {
+        render(contentType: 'application/json', text: [
+            javaMessage: javaSingletonService.message,
+            factoryName: factoryCreatedService.name,
+            appName: appConfig.name,
+            namedService: namedService.name
+        ])

Review Comment:
   `render(contentType: 'application/json', text: [...])` will send the Groovy 
`Map#toString()` representation (e.g. `[a:1]`), which is not valid JSON despite 
the JSON content type. Use a JSON renderer/converter (e.g. `render([:] as 
JSON)`, `respond`, or serialize via `JsonBuilder`) so the response body matches 
the declared content type.



##########
grails-doc/src/en/guide/upgrading/upgrading60x.adoc:
##########
@@ -371,6 +371,12 @@ Here's an example `gradle.properties` file:
 micronautPlatformVersion=4.9.2
 ----
 
+Please note that due to 
https://github.com/micronaut-projects/micronaut-spring/issues/769[this issue], 
Spring Boot Dev tools does not work with the micronaut integration.

Review Comment:
   The upgrade note uses inconsistent product naming/capitalization: “Spring 
Boot Dev tools” and “micronaut integration”. For clarity and consistency, use 
“Spring Boot DevTools” and “Micronaut integration” (and consider tightening the 
sentence grammar).
   ```suggestion
   Please note that, due to 
https://github.com/micronaut-projects/micronaut-spring/issues/769[this issue], 
Spring Boot DevTools does not work with the Micronaut integration.
   ```



-- 
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