Skip to content

Commit d650cdb

Browse files
authored
Add MigrateToOracleFree recipe for Testcontainers (#964)
* Add MigrateToOracleFree recipe for Testcontainers (#435) Migrate from `org.testcontainers:oracle-xe` to `org.testcontainers:oracle-free`, changing the type from `org.testcontainers.containers.OracleContainer` to `org.testcontainers.oracle.OracleContainer`. * Use dependsOn stubs instead of classpath.tsv.gz entries
1 parent d08715b commit d650cdb

3 files changed

Lines changed: 131 additions & 0 deletions

File tree

src/main/resources/META-INF/rewrite/recipes.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ maven,org.openrewrite.recipe:rewrite-testing-frameworks,org.openrewrite.java.tes
224224
maven,org.openrewrite.recipe:rewrite-testing-frameworks,org.openrewrite.java.testing.testcontainers.AddTestcontainersAnnotations,Adopt `@Container` and add `@Testcontainers`,Convert Testcontainers `@Rule`/`@ClassRule` to JUnit 5 `@Container` and add `@Testcontainers`.,1,Testcontainers,Testing,Java,Recipes for [Testcontainers](https://testcontainers.com/) integration testing with Docker.,,Basic building blocks for transforming Java code.,,
225225
maven,org.openrewrite.recipe:rewrite-testing-frameworks,org.openrewrite.java.testing.testcontainers.ConvertToRawType,Remove parameterized type arguments from a Java class,Convert parameterized types of a specified Java class to their raw types.,1,Testcontainers,Testing,Java,Recipes for [Testcontainers](https://testcontainers.com/) integration testing with Docker.,,Basic building blocks for transforming Java code.,"[{""name"":""fullyQualifiedTypeName"",""type"":""String"",""displayName"":""Fully qualified type name"",""description"":""The fully qualified name of the Java class to convert to its raw type."",""example"":""org.testcontainers.containers.PostgreSQLContainer"",""required"":true}]",
226226
maven,org.openrewrite.recipe:rewrite-testing-frameworks,org.openrewrite.java.testing.testcontainers.ExplicitContainerImage,Add image argument to container constructor,"Set the image to use for a container explicitly if unset, rather than relying on the default image for the container class.",1,Testcontainers,Testing,Java,Recipes for [Testcontainers](https://testcontainers.com/) integration testing with Docker.,,Basic building blocks for transforming Java code.,"[{""name"":""containerClass"",""type"":""String"",""displayName"":""Container class"",""description"":""The fully qualified name of the container class to use."",""example"":""org.testcontainers.containers.NginxContainer"",""required"":true},{""name"":""image"",""type"":""String"",""displayName"":""Image to use"",""description"":""The image to use for the container."",""example"":""nginx:1.9.4"",""required"":true},{""name"":""parseImage"",""type"":""Boolean"",""displayName"":""Parse image"",""description"":""Whether to call `DockerImageName.parse(image)`.""}]",
227+
maven,org.openrewrite.recipe:rewrite-testing-frameworks,org.openrewrite.java.testing.testcontainers.MigrateToOracleFree,Migrate from `oracle-xe` to `oracle-free`,Oracle Database Free is the successor of Oracle XE. Migrate from `org.testcontainers:oracle-xe` to `org.testcontainers:oracle-free`.,3,Testcontainers,Testing,Java,Recipes for [Testcontainers](https://testcontainers.com/) integration testing with Docker.,,Basic building blocks for transforming Java code.,,
227228
maven,org.openrewrite.recipe:rewrite-testing-frameworks,org.openrewrite.java.testing.testcontainers.TestContainersBestPractices,Testcontainers best practices,Apply best practices to Testcontainers usage.,149,Testcontainers,Testing,Java,Recipes for [Testcontainers](https://testcontainers.com/) integration testing with Docker.,,Basic building blocks for transforming Java code.,,
228229
maven,org.openrewrite.recipe:rewrite-testing-frameworks,org.openrewrite.java.testing.testcontainers.Testcontainers2Migration,Migrate to testcontainers-java 2.x,Change dependencies and types to migrate to testcontainers-java 2.x.,148,Testcontainers,Testing,Java,Recipes for [Testcontainers](https://testcontainers.com/) integration testing with Docker.,,Basic building blocks for transforming Java code.,,
229230
maven,org.openrewrite.recipe:rewrite-testing-frameworks,org.openrewrite.java.testing.testcontainers.GetHostMigration,Replace `ContainerState.getContainerIpAddress()` with `getHost()`,Replace `org.testcontainers.containers.ContainerState.getContainerIpAddress()` with `getHost()`.,2,Testcontainers,Testing,Java,Recipes for [Testcontainers](https://testcontainers.com/) integration testing with Docker.,,Basic building blocks for transforming Java code.,,

src/main/resources/META-INF/rewrite/testcontainers.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
# limitations under the License.
1515
#
1616

17+
---
18+
type: specs.openrewrite.org/v1beta/recipe
19+
name: org.openrewrite.java.testing.testcontainers.MigrateToOracleFree
20+
displayName: Migrate from `oracle-xe` to `oracle-free`
21+
description: >-
22+
Oracle Database Free is the successor of Oracle XE.
23+
Migrate from `org.testcontainers:oracle-xe` to `org.testcontainers:oracle-free`.
24+
recipeList:
25+
- org.openrewrite.java.ChangeType:
26+
oldFullyQualifiedTypeName: org.testcontainers.containers.OracleContainer
27+
newFullyQualifiedTypeName: org.testcontainers.oracle.OracleContainer
28+
- org.openrewrite.java.dependencies.ChangeDependency:
29+
oldGroupId: org.testcontainers
30+
oldArtifactId: oracle-xe
31+
newArtifactId: oracle-free
1732
---
1833
type: specs.openrewrite.org/v1beta/recipe
1934
name: org.openrewrite.java.testing.testcontainers.TestContainersBestPractices
@@ -22,6 +37,7 @@ description: Apply best practices to Testcontainers usage.
2237
preconditions:
2338
- org.openrewrite.Singleton
2439
recipeList:
40+
- org.openrewrite.java.testing.testcontainers.MigrateToOracleFree
2541
- org.openrewrite.java.testing.testcontainers.Testcontainers2Migration
2642
---
2743
type: specs.openrewrite.org/v1beta/recipe
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://docs.moderne.io/licensing/moderne-source-available-license
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.testing.testcontainers;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.InMemoryExecutionContext;
21+
import org.openrewrite.java.JavaParser;
22+
import org.openrewrite.test.RecipeSpec;
23+
import org.openrewrite.test.RewriteTest;
24+
25+
import static org.openrewrite.java.Assertions.java;
26+
import static org.openrewrite.maven.Assertions.pomXml;
27+
28+
class MigrateToOracleFreeTest implements RewriteTest {
29+
@Override
30+
public void defaults(RecipeSpec spec) {
31+
spec
32+
.recipeFromResource("/META-INF/rewrite/testcontainers.yml",
33+
"org.openrewrite.java.testing.testcontainers.MigrateToOracleFree")
34+
.parser(JavaParser.fromJavaVersion()
35+
//language=java
36+
.dependsOn(
37+
"""
38+
package org.testcontainers.containers;
39+
public class OracleContainer {
40+
public OracleContainer(String image) {}
41+
}
42+
""",
43+
"""
44+
package org.testcontainers.oracle;
45+
public class OracleContainer {
46+
public OracleContainer(String image) {}
47+
}
48+
"""));
49+
}
50+
51+
@DocumentExample
52+
@Test
53+
void changeTypeAndImport() {
54+
rewriteRun(
55+
//language=java
56+
java(
57+
"""
58+
import org.testcontainers.containers.OracleContainer;
59+
60+
class A {
61+
private OracleContainer oracle = null;
62+
}
63+
""",
64+
"""
65+
import org.testcontainers.oracle.OracleContainer;
66+
67+
class A {
68+
private OracleContainer oracle = null;
69+
}
70+
"""
71+
)
72+
);
73+
}
74+
75+
@Test
76+
void changeDependency() {
77+
rewriteRun(
78+
pomXml(
79+
//language=xml
80+
"""
81+
<project>
82+
<modelVersion>4.0.0</modelVersion>
83+
<groupId>org.openrewrite.example</groupId>
84+
<artifactId>testcontainers</artifactId>
85+
<version>1.0-SNAPSHOT</version>
86+
<dependencies>
87+
<dependency>
88+
<groupId>org.testcontainers</groupId>
89+
<artifactId>oracle-xe</artifactId>
90+
<version>1.20.6</version>
91+
</dependency>
92+
</dependencies>
93+
</project>
94+
""",
95+
//language=xml
96+
"""
97+
<project>
98+
<modelVersion>4.0.0</modelVersion>
99+
<groupId>org.openrewrite.example</groupId>
100+
<artifactId>testcontainers</artifactId>
101+
<version>1.0-SNAPSHOT</version>
102+
<dependencies>
103+
<dependency>
104+
<groupId>org.testcontainers</groupId>
105+
<artifactId>oracle-free</artifactId>
106+
<version>1.20.6</version>
107+
</dependency>
108+
</dependencies>
109+
</project>
110+
"""
111+
)
112+
);
113+
}
114+
}

0 commit comments

Comments
 (0)