Skip to content

Commit a165c80

Browse files
authored
Replicate ClassCastException in EnableVirtualThreads (#460)
* Replicate ClassCastException in EnableVirtualThreads * Expand tests
1 parent 39fe593 commit a165c80

File tree

3 files changed

+94
-4
lines changed

3 files changed

+94
-4
lines changed

build.gradle.kts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
group = "org.openrewrite.recipe"
66
description = "Eliminate legacy Spring patterns and migrate between major Spring Boot versions. Automatically."
77

8-
val springBootVersions: List<String> = listOf("1_5", "2_1", "2_2", "2_3", "2_4", "2_5", "2_6", "2_7", "3_0")
8+
val springBootVersions: List<String> = listOf("1_5", "2_1", "2_2", "2_3", "2_4", "2_5", "2_6", "2_7", "3_0", "3_2")
99
val springSecurityVersions: List<String> = listOf("5_7", "5_8", "6_2")
1010

1111
val sourceSetNames: Map<String, List<String>> = mapOf(
@@ -109,7 +109,6 @@ recipeDependencies {
109109

110110
val rewriteVersion = rewriteRecipe.rewriteVersion.get()
111111

112-
var springBoot3Version = "3.0.0-RC1"
113112
dependencies {
114113
implementation("org.openrewrite:rewrite-java:${rewriteVersion}")
115114
implementation("org.openrewrite:rewrite-xml:${rewriteVersion}")
@@ -205,8 +204,8 @@ dependencies {
205204
"testWithSpringBoot_2_7RuntimeOnly"("org.springframework.security:spring-security-ldap:5.7.+")
206205
"testWithSpringBoot_2_7RuntimeOnly"("org.apache.tomcat.embed:tomcat-embed-core:9.0.+")
207206

208-
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.boot:spring-boot-starter:${springBoot3Version}")
209-
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.boot:spring-boot-starter-test:${springBoot3Version}")
207+
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.boot:spring-boot-starter:3.0+")
208+
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.boot:spring-boot-starter-test:3.0+")
210209
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework:spring-context:6.0.+")
211210
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework:spring-web:6.0.+")
212211
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.batch:spring-batch-core:5.+")
@@ -216,6 +215,9 @@ dependencies {
216215
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.security:spring-security-web:6.0.+")
217216
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.security:spring-security-ldap:6.0.+")
218217

218+
"testWithSpringBoot_3_2RuntimeOnly"("org.springframework.boot:spring-boot-starter:3.2+")
219+
"testWithSpringBoot_3_2RuntimeOnly"("org.springframework.boot:spring-boot-starter-test:3.2+")
220+
219221
"testWithSpringSecurity_5_7RuntimeOnly"("org.springframework:spring-context:5.3.+")
220222
"testWithSpringSecurity_5_7RuntimeOnly"("org.springframework.boot:spring-boot-starter:2.7.+")
221223
"testWithSpringSecurity_5_7RuntimeOnly"("org.springframework.boot:spring-boot:2.7.+")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*.java]
4+
indent_size = 4
5+
ij_continuation_indent_size = 2
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.spring.boot3;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.test.RecipeSpec;
21+
import org.openrewrite.test.RewriteTest;
22+
23+
import static org.openrewrite.properties.Assertions.properties;
24+
import static org.openrewrite.yaml.Assertions.yaml;
25+
26+
class EnableVirtualThreadsTest implements RewriteTest {
27+
@Override
28+
public void defaults(RecipeSpec spec) {
29+
spec.recipeFromResources("org.openrewrite.java.spring.boot3.EnableVirtualThreads");
30+
}
31+
32+
@Test
33+
@DocumentExample
34+
void enableVirtualThreadsProperties() {
35+
rewriteRun(
36+
//language=properties
37+
properties(
38+
"",
39+
"""
40+
spring.threads.virtual.enabled=true
41+
""",
42+
s -> s.path("src/main/resources/application.properties")
43+
)
44+
);
45+
}
46+
47+
@Test
48+
@DocumentExample
49+
void enableVirtualThreadsYaml() {
50+
rewriteRun(
51+
//language=yaml
52+
yaml(
53+
"",
54+
"""
55+
spring:
56+
threads.virtual.enabled: true
57+
""",
58+
s -> s.path("src/main/resources/application.yml")
59+
)
60+
);
61+
}
62+
63+
@Test
64+
void dontEnableVirtualThreadsIfDisabled() {
65+
rewriteRun(
66+
//language=properties
67+
properties(
68+
"""
69+
spring.threads.virtual.enabled=false
70+
""",
71+
s -> s.path("src/main/resources/application.properties")
72+
),
73+
//language=yaml
74+
yaml(
75+
"""
76+
spring:
77+
threads.virtual.enabled: false
78+
""",
79+
s -> s.path("src/main/resources/application.yml")
80+
)
81+
);
82+
}
83+
}

0 commit comments

Comments
 (0)