Repository: micronaut-projects/micronaut-test
Pull request #931 (2024-01-23 21:21:17)

fix(deps): update dependency io.micronaut.serde:micronaut-serde-bom to v2.8.1
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [io.micronaut.serde:micronaut-serde-bom](https://micronaut.io) ([source](https://togithub.com/micronaut-projects/micronaut-serialization)) | `2.7.0` -> `2.8.1` | [![age](https://developer.mend.io/api/mc/badges/age/maven/io.micronaut.serde:micronaut-serde-bom/2.8.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/io.micronaut.serde:micronaut-serde-bom/2.8.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/io.micronaut.serde:micronaut-serde-bom/2.7.0/2.8.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/io.micronaut.serde:micronaut-serde-bom/2.7.0/2.8.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>micronaut-projects/micronaut-serialization (io.micronaut.serde:micronaut-serde-bom)</summary>

### [`v2.8.1`](https://togithub.com/micronaut-projects/micronaut-serialization/releases/tag/v2.8.1): Micronaut Serialization 2.8.1

<!-- Release notes generated using configuration in .github/release.yml at master -->

#### What's Changed

##### Other Changes 💡

-   Correct property's generic parameters by [@&#8203;dstepanov](https://togithub.com/dstepanov) in [https://github.com/micronaut-projects/micronaut-serialization/pull/743](https://togithub.com/micronaut-projects/micronaut-serialization/pull/743)

**Full Changelog**: https://github.com/micronaut-projects/micronaut-serialization/compare/v2.8.0...v2.8.1

### [`v2.8.0`](https://togithub.com/micronaut-projects/micronaut-serialization/releases/tag/v2.8.0): Micronaut Serialization 2.8.0

<!-- Release notes generated using configuration in .github/release.yml at master -->

#### What's Changed

##### Dependency updates 🚀

-   fix(deps): update dependency com.oracle.oci.sdk:oci-java-sdk-aidocument to v3.32.1 by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/726](https://togithub.com/micronaut-projects/micronaut-serialization/pull/726)
-   Update dependencies by [@&#8203;sdelamo](https://togithub.com/sdelamo) in [https://github.com/micronaut-projects/micronaut-serialization/pull/741](https://togithub.com/micronaut-projects/micronaut-serialization/pull/741)

##### Kotlin

-   fix(deps): update dependency com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin to v1.9.22-1.0.17 by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/731](https://togithub.com/micronaut-projects/micronaut-serialization/pull/731)

##### Micronaut Modules

##### Micronaut Core

-   Micronaut Core 4.3.1

##### Micronaut Validation

-   fix(deps): update dependency io.micronaut.validation:micronaut-validation-bom to v4.3.0 - autoclosed by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/735](https://togithub.com/micronaut-projects/micronaut-serialization/pull/735)

##### Micronaut Discovery Client

-   fix(deps): update dependency io.micronaut.discovery:micronaut-discovery-client to v4.2.0 by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/732](https://togithub.com/micronaut-projects/micronaut-serialization/pull/732)

##### Micronaut Test

-   Micronaut Test 4.2.0

##### CI ⚙️Build 🐘

-   chore(deps): update gradle/wrapper-validation-action action to v2 by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/740](https://togithub.com/micronaut-projects/micronaut-serialization/pull/740)
-   chore(deps): update gradle/gradle-build-action action to v2.12.0 by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/725](https://togithub.com/micronaut-projects/micronaut-serialization/pull/725)

##### SVM

-   fix(deps): update dependency org.graalvm.nativeimage:svm to v23.1.2 by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/729](https://togithub.com/micronaut-projects/micronaut-serialization/pull/729)

**Full Changelog**: https://github.com/micronaut-projects/micronaut-serialization/compare/v2.7.1...v2.8.0

### [`v2.7.1`](https://togithub.com/micronaut-projects/micronaut-serialization/releases/tag/v2.7.1): Micronaut Serialization v2.7.1

<!-- Release notes generated using configuration in .github/release.yml at master -->

##### What's Changed

##### Bug Fixes 🐞

-   Fix customized map serializer by [@&#8203;radovanradic](https://togithub.com/radovanradic) in [https://github.com/micronaut-projects/micronaut-serialization/pull/734](https://togithub.com/micronaut-projects/micronaut-serialization/pull/734)

##### Dependency updates 🚀

-   fix(deps): update dependency io.micronaut.logging:micronaut-logging-bom to v1.2.2 by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/733](https://togithub.com/micronaut-projects/micronaut-serialization/pull/733)
-   chore(deps): update plugin io.micronaut.build.shared.settings to v6.6.2 by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/728](https://togithub.com/micronaut-projects/micronaut-serialization/pull/728)
-   fix(deps): update dependency io.micronaut.reactor:micronaut-reactor-bom to v3.2.1 by [@&#8203;renovate](https://togithub.com/renovate) in [https://github.com/micronaut-projects/micronaut-serialization/pull/723](https://togithub.com/micronaut-projects/micronaut-serialization/pull/723)

##### Other Changes 💡

-   Add test for boxed/primitive deserializers by [@&#8203;dstepanov](https://togithub.com/dstepanov) in [https://github.com/micronaut-projects/micronaut-serialization/pull/730](https://togithub.com/micronaut-projects/micronaut-serialization/pull/730)

**Full Changelog**: https://github.com/micronaut-projects/micronaut-serialization/compare/v2.7.0...v2.7.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 10pm" in timezone Europe/Prague, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/micronaut-projects/micronaut-test).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMzUuMCIsInVwZGF0ZWRJblZlciI6IjM3LjE1My4yIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIn0=-->



Patch:
diff --git a/gradle.properties b/gradle.properties
index 60f7cbf5..4536bf24 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
-projectVersion=4.2.1-SNAPSHOT
+projectVersion=4.3.0-SNAPSHOT
 projectGroup=io.micronaut.test
 
 title=Micronaut Test
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index e615cdf8..fcef50f6 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -1,14 +1,14 @@
 [versions]
 micronaut = "4.3.5"
-micronaut-platform = "4.2.3"
+micronaut-platform = "4.3.2"
 micronaut-docs = "2.0.0"
 groovy = "4.0.15"
 
-managed-assertj = "3.25.1"
+managed-assertj = "3.25.3"
 managed-hamcrest = "2.2"
-managed-mockito = "5.9.0"
+managed-mockito = "5.10.0"
 managed-mockk = "1.13.9"
-managed-junit = "5.10.1"
+managed-junit = "5.10.2"
 managed-rest-assured = "5.4.0"
 managed-kotest = "5.8.0"
 managed-spock = "2.3-groovy-4.0"
@@ -16,12 +16,12 @@ managed-spock = "2.3-groovy-4.0"
 kotlin = "1.9.22"
 graal-svm = "23.1.2"
 
-micronaut-test = "4.1.1"
+micronaut-test = "4.2.0"
 micronaut-data = "4.4.1"
-micronaut-hibernate-validator = "4.1.0"
+micronaut-hibernate-validator = "4.2.0"
 micronaut-logging = "1.1.2"
 micronaut-r2dbc = "5.2.0"
-micronaut-serde = "2.7.0"
+micronaut-serde = "2.8.1"
 micronaut-spring = "5.4.1"
 micronaut-sql = "5.4.0"
 micronaut-reactor = "3.2.1"


Test patch:
diff --git a/test-core/src/main/java/io/micronaut/test/support/sql/TestSqlAnnotationHandler.java b/test-core/src/main/java/io/micronaut/test/support/sql/TestSqlAnnotationHandler.java
index eadf5c81..4417f55b 100644
--- a/test-core/src/main/java/io/micronaut/test/support/sql/TestSqlAnnotationHandler.java
+++ b/test-core/src/main/java/io/micronaut/test/support/sql/TestSqlAnnotationHandler.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017-2023 original authors
+ * Copyright 2017-2024 original authors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -63,27 +63,37 @@ public final class TestSqlAnnotationHandler {
      * @throws IOException If an error occurs reading the SQL
      */
     public static void handle(BeanDefinition<?> specDefinition, ApplicationContext applicationContext, Sql.Phase phase) throws IOException {
-        ResourceLoader resourceLoader = applicationContext.getBean(ResourceLoader.class);
         Optional<List<AnnotationValue<Sql>>> sqlAnnotations = specDefinition
             .findAnnotation(Sql.Sqls.class)
             .map(s -> s.getAnnotations("value", Sql.class));
 
         if (sqlAnnotations.isPresent()) {
-            for (var sql : sqlAnnotations.get()) {
-                if (sql.getRequiredValue("phase", Sql.Phase.class) != phase) {
-                    continue;
-                }
-                List<@NonNull String> scripts = Arrays.asList(sql.stringValues());
-                if (!scripts.isEmpty()) {
-                    Consumer<String> proc = bean(
-                        sql.getRequiredValue("resourceType", Class.class),
-                        sql.getRequiredValue("dataSourceName", String.class),
-                        applicationContext
-                    );
-                    handleScript(resourceLoader, scripts, proc, phase);
-                } else if (LOG.isTraceEnabled()) {
-                    LOG.trace("No SQL scripts found for {} phase", phase);
+            if (!applicationContext.isRunning()) {
+                if (LOG.isWarnEnabled()) {
+                    LOG.warn("Application context has been stopped, skipping SQL script annotations");
                 }
+            } else {
+                processAnnotations(applicationContext, phase, sqlAnnotations.get());
+            }
+        }
+    }
+
+    private static void processAnnotations(ApplicationContext applicationContext, Sql.Phase phase, List<AnnotationValue<Sql>> sqlAnnotations) throws IOException {
+        ResourceLoader resourceLoader = applicationContext.getBean(ResourceLoader.class);
+        for (var sql : sqlAnnotations) {
+            if (sql.getRequiredValue("phase", Sql.Phase.class) != phase) {
+                continue;
+            }
+            List<@NonNull String> scripts = Arrays.asList(sql.stringValues());
+            if (!scripts.isEmpty()) {
+                Consumer<String> proc = bean(
+                    sql.getRequiredValue("resourceType", Class.class),
+                    sql.getRequiredValue("dataSourceName", String.class),
+                    applicationContext
+                );
+                handleScript(resourceLoader, scripts, proc, phase);
+            } else if (LOG.isTraceEnabled()) {
+                LOG.trace("No SQL scripts found for {} phase", phase);
             }
         }
     }
@@ -111,5 +121,4 @@ public final class TestSqlAnnotationHandler {
             }
         }
     }
-
 }
diff --git a/test-junit5/src/test/java/io/micronaut/test/junit5/ApplicationStopTest.java b/test-junit5/src/test/java/io/micronaut/test/junit5/ApplicationStopTest.java
new file mode 100644
index 00000000..86b33586
--- /dev/null
+++ b/test-junit5/src/test/java/io/micronaut/test/junit5/ApplicationStopTest.java
@@ -0,0 +1,27 @@
+package io.micronaut.test.junit5;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.runtime.EmbeddedApplication;
+import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
+import jakarta.inject.Inject;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@MicronautTest
+class ApplicationStopTest {
+
+    @Inject
+    private ApplicationContext applicationContext;
+
+    @Test
+    void stoppingTheContextDoesntCauseFailures() {
+        applicationContext.stop();
+        assertTrue(true);
+        // should not error
+    }
+}
diff --git a/test-junit5/src/test/java/io/micronaut/test/junit5/SqlDatasourceApplicationStopTest.java b/test-junit5/src/test/java/io/micronaut/test/junit5/SqlDatasourceApplicationStopTest.java
new file mode 100644
index 00000000..8efb7669
--- /dev/null
+++ b/test-junit5/src/test/java/io/micronaut/test/junit5/SqlDatasourceApplicationStopTest.java
@@ -0,0 +1,59 @@
+package io.micronaut.test.junit5;
+
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.context.annotation.Property;
+import io.micronaut.test.annotation.Sql;
+import io.micronaut.test.annotation.TransactionMode;
+import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
+import jakarta.inject.Inject;
+import org.junit.jupiter.api.Test;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@DbProperties
+@MicronautTest(transactionMode = TransactionMode.SINGLE_TRANSACTION)
+@Property(name = "datasources.default.dialect", value = "H2")
+@Property(name = "datasources.default.driverClassName", value = "org.h2.Driver")
+@Property(name = "datasources.default.schema-generate", value = "CREATE_DROP")
+@Property(name = "datasources.default.url", value = "jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE")
+@Property(name = "datasources.default.username", value = "sa")
+@Sql({"classpath:create.sql", "classpath:datasource_1_insert.sql"}) // <1>
+class SqlDatasourceApplicationStopTest {
+
+    @Inject
+    ApplicationContext applicationContext;
+
+    @Inject
+    DataSource dataSource;
+
+    @Test
+    void stoppingTheContextDoesntCauseFailures() throws Exception {
+        assertEquals(List.of("Aardvark", "Albatross"), readAllNames(dataSource));
+        applicationContext.stop();
+        assertTrue(true);
+        // should not error
+    }
+
+    List<String> readAllNames(DataSource dataSource) throws SQLException {
+        var result = new ArrayList<String>();
+        try (
+                Connection ds = dataSource.getConnection();
+                PreparedStatement ps = ds.prepareStatement("select name from MyTable");
+                ResultSet rslt = ps.executeQuery()
+        ) {
+            while(rslt.next()) {
+                result.add(rslt.getString(1));
+            }
+        }
+        return result;
+    }
+}