Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a recipe to rewrite @QuarkusTestResource to @WithTestResource #187

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions recipes-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<!-- Quarkus version used by the tests -->
<quarkus.version>3.13.0.CR1</quarkus.version>
<!-- Camel quarkus version used by the tests -->
<camel-quarkus.version>2.13.3</camel-quarkus.version>
<!-- Http version used by the tests -->
Expand All @@ -25,13 +27,26 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom</artifactId>
<version>${camel-quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- OpenRewrite depends on a Jackson version that still uses the old JAXB API -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -132,6 +147,14 @@
<scope>test</scope>
</dependency>

<!-- Quarkus test dependencies -->

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-common</artifactId>
<scope>test</scope>
</dependency>

<!-- Camel quarkus testing -->
<dependency>
<groupId>org.apache.camel</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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)
Copy link

@edeandrea edeandrea Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case where @QuarkusTestResource(restrictToAnnotatedClass = true), it would be nicer I think if we just eliminated the attribute, since the default in @WithTestResource is true.

I'm not sure if thats possible though. I don't know much about Open Rewrite.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably could but I thought about it when doing it and I decided it was not worth the hassle, given the size of my TODO list :).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it was one of those "this would be nice if it was easy to do" things.

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 {
}
"""));
}
}
30 changes: 30 additions & 0 deletions recipes/src/main/resources/quarkus-updates/core/3.13.alpha1.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions recipes/src/main/resources/quarkus-updates/core/3.13.yaml

This file was deleted.

Loading