From 0e9ee70b1f1521485c8309897af78ec7f61dea56 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 22 Jul 2024 19:07:42 +0200 Subject: [PATCH 1/2] Add a recipe to rewrite @QuarkusTestResource to @WithTestResource --- recipes-tests/pom.xml | 23 +++++ .../io/quarkus/updates/core/CoreTestUtil.java | 3 - .../updates/core/CoreUpdate313Test.java | 89 +++++++++++++++++++ .../quarkus-updates/core/3.13.alpha1.yaml | 30 +++++++ .../resources/quarkus-updates/core/3.13.yaml | 10 --- 5 files changed, 142 insertions(+), 13 deletions(-) create mode 100644 recipes-tests/src/test/java/io/quarkus/updates/core/CoreUpdate313Test.java create mode 100644 recipes/src/main/resources/quarkus-updates/core/3.13.alpha1.yaml delete mode 100644 recipes/src/main/resources/quarkus-updates/core/3.13.yaml diff --git a/recipes-tests/pom.xml b/recipes-tests/pom.xml index 4770709aa0..4faf8644ab 100644 --- a/recipes-tests/pom.xml +++ b/recipes-tests/pom.xml @@ -17,6 +17,8 @@ 17 17 17 + + 3.13.0.CR1 2.13.3 @@ -25,6 +27,13 @@ + + io.quarkus + quarkus-bom + ${quarkus.version} + pom + import + org.apache.camel.quarkus camel-quarkus-bom @@ -32,6 +41,12 @@ pom import + + + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.3 + @@ -132,6 +147,14 @@ test + + + + io.quarkus + quarkus-test-common + test + + org.apache.camel diff --git a/recipes-tests/src/test/java/io/quarkus/updates/core/CoreTestUtil.java b/recipes-tests/src/test/java/io/quarkus/updates/core/CoreTestUtil.java index 56941e6e86..1f1d484818 100644 --- a/recipes-tests/src/test/java/io/quarkus/updates/core/CoreTestUtil.java +++ b/recipes-tests/src/test/java/io/quarkus/updates/core/CoreTestUtil.java @@ -1,11 +1,9 @@ package io.quarkus.updates.core; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; import java.net.URI; -import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.Collection; import java.util.List; @@ -16,7 +14,6 @@ import org.openrewrite.config.Environment; import org.openrewrite.config.YamlResourceLoader; import org.openrewrite.maven.UpgradeDependencyVersion; -import org.openrewrite.maven.ChangePropertyValue; import org.openrewrite.test.RecipeSpec; public final class CoreTestUtil { diff --git a/recipes-tests/src/test/java/io/quarkus/updates/core/CoreUpdate313Test.java b/recipes-tests/src/test/java/io/quarkus/updates/core/CoreUpdate313Test.java new file mode 100644 index 0000000000..8744c27b65 --- /dev/null +++ b/recipes-tests/src/test/java/io/quarkus/updates/core/CoreUpdate313Test.java @@ -0,0 +1,89 @@ +package io.quarkus.updates.core; + +import static org.openrewrite.java.Assertions.java; + +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; +import org.openrewrite.test.TypeValidation; + +public class CoreUpdate313Test implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + CoreTestUtil.recipe(spec, Path.of("quarkus-updates", "core", "3.13.alpha1.yaml")) + .parser(JavaParser.fromJavaVersion() + .classpath("quarkus-test-common") + .logCompilationWarningsAndErrors(true)) + .typeValidationOptions(TypeValidation.all()); + } + + @Test + void testWithTestResource() { + //language=java + rewriteRun(java( + """ + package io.quarkiverse.githubapp.test; + + import io.quarkus.test.common.QuarkusTestResource; + + @QuarkusTestResource + public class GitHubAppTest { + } + """, + """ + package io.quarkiverse.githubapp.test; + + import io.quarkus.test.common.WithTestResource; + + @WithTestResource(restrictToAnnotatedClass = false) + public class GitHubAppTest { + } + """)); + + //language=java + rewriteRun(java( + """ + package io.quarkiverse.githubapp.test; + + import io.quarkus.test.common.QuarkusTestResource; + + @QuarkusTestResource(restrictToAnnotatedClass = false) + public class GitHubAppTest { + } + """, + """ + package io.quarkiverse.githubapp.test; + + import io.quarkus.test.common.WithTestResource; + + @WithTestResource(restrictToAnnotatedClass = false) + public class GitHubAppTest { + } + """)); + + //language=java + rewriteRun(java( + """ + package io.quarkiverse.githubapp.test; + + import io.quarkus.test.common.QuarkusTestResource; + + @QuarkusTestResource(restrictToAnnotatedClass = true) + class GitHubAppTest { + } + """, + """ + package io.quarkiverse.githubapp.test; + + import io.quarkus.test.common.WithTestResource; + + @WithTestResource(restrictToAnnotatedClass = true) + class GitHubAppTest { + } + """)); + } +} diff --git a/recipes/src/main/resources/quarkus-updates/core/3.13.alpha1.yaml b/recipes/src/main/resources/quarkus-updates/core/3.13.alpha1.yaml new file mode 100644 index 0000000000..7af385af84 --- /dev/null +++ b/recipes/src/main/resources/quarkus-updates/core/3.13.alpha1.yaml @@ -0,0 +1,30 @@ +##### +# Sync JPA model gen version with the one from the BOM +##### +--- +type: specs.openrewrite.org/v1beta/recipe +name: io.quarkus.updates.core.quarkus313.SyncHibernateJpaModelgenVersionWithBOM +recipeList: + - io.quarkus.updates.core.quarkus37.SyncMavenCompilerAnnotationProcessorVersion: + groupId: org.hibernate.orm + artifactId: hibernate-jpamodelgen +##### +# Replace @QuarkusTestResource with @WithTestResource while keeping the original behavior +##### +--- +type: specs.openrewrite.org/v1beta/recipe +name: io.quarkus.updates.core.quarkus313.WithTestResource +recipeList: + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: io.quarkus.test.common.QuarkusTestResource + newFullyQualifiedTypeName: io.quarkus.test.common.WithTestResource +--- +# The default for WithTestResource is different so if using the default value, let's enforce it +type: specs.openrewrite.org/v1beta/recipe +name: io.quarkus.updates.core.quarkus313.WithTestResourceRestrictToAnnotatedClassValue +recipeList: + - org.openrewrite.java.AddOrUpdateAnnotationAttribute: + annotationType: io.quarkus.test.common.WithTestResource + attributeName: restrictToAnnotatedClass + attributeValue: false + addOnly: true diff --git a/recipes/src/main/resources/quarkus-updates/core/3.13.yaml b/recipes/src/main/resources/quarkus-updates/core/3.13.yaml deleted file mode 100644 index fd02e5257b..0000000000 --- a/recipes/src/main/resources/quarkus-updates/core/3.13.yaml +++ /dev/null @@ -1,10 +0,0 @@ -##### -# Sync JPA model gen version with the one from the BOM -##### ---- -type: specs.openrewrite.org/v1beta/recipe -name: io.quarkus.updates.core.quarkus313.SyncHibernateJpaModelgenVersionWithBOM -recipeList: - - io.quarkus.updates.core.quarkus37.SyncMavenCompilerAnnotationProcessorVersion: - groupId: org.hibernate.orm - artifactId: hibernate-jpamodelgen From 7657a9b8182541c9ce313fbd244200c792463107 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 22 Jul 2024 19:51:39 +0200 Subject: [PATCH 2/2] Add a test with an existing annotation attribute --- .../updates/core/CoreUpdate313Test.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/recipes-tests/src/test/java/io/quarkus/updates/core/CoreUpdate313Test.java b/recipes-tests/src/test/java/io/quarkus/updates/core/CoreUpdate313Test.java index 8744c27b65..ee0a037a60 100644 --- a/recipes-tests/src/test/java/io/quarkus/updates/core/CoreUpdate313Test.java +++ b/recipes-tests/src/test/java/io/quarkus/updates/core/CoreUpdate313Test.java @@ -85,5 +85,26 @@ class GitHubAppTest { class GitHubAppTest { } """)); + + //language=java + rewriteRun(java( + """ + package io.quarkiverse.githubapp.test; + + import io.quarkus.test.common.QuarkusTestResource; + + @QuarkusTestResource(parallel = true) + class GitHubAppTest { + } + """, + """ + package io.quarkiverse.githubapp.test; + + import io.quarkus.test.common.WithTestResource; + + @WithTestResource(restrictToAnnotatedClass = false, parallel = true) + class GitHubAppTest { + } + """)); } }