Skip to content

Commit

Permalink
Replicate ClassCastException in EnableVirtualThreads (#460)
Browse files Browse the repository at this point in the history
* Replicate ClassCastException in EnableVirtualThreads

* Expand tests
  • Loading branch information
timtebeek authored Dec 8, 2023
1 parent 39fe593 commit a165c80
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
group = "org.openrewrite.recipe"
description = "Eliminate legacy Spring patterns and migrate between major Spring Boot versions. Automatically."

val springBootVersions: List<String> = listOf("1_5", "2_1", "2_2", "2_3", "2_4", "2_5", "2_6", "2_7", "3_0")
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")
val springSecurityVersions: List<String> = listOf("5_7", "5_8", "6_2")

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

val rewriteVersion = rewriteRecipe.rewriteVersion.get()

var springBoot3Version = "3.0.0-RC1"
dependencies {
implementation("org.openrewrite:rewrite-java:${rewriteVersion}")
implementation("org.openrewrite:rewrite-xml:${rewriteVersion}")
Expand Down Expand Up @@ -205,8 +204,8 @@ dependencies {
"testWithSpringBoot_2_7RuntimeOnly"("org.springframework.security:spring-security-ldap:5.7.+")
"testWithSpringBoot_2_7RuntimeOnly"("org.apache.tomcat.embed:tomcat-embed-core:9.0.+")

"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.boot:spring-boot-starter:${springBoot3Version}")
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.boot:spring-boot-starter-test:${springBoot3Version}")
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.boot:spring-boot-starter:3.0+")
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.boot:spring-boot-starter-test:3.0+")
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework:spring-context:6.0.+")
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework:spring-web:6.0.+")
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.batch:spring-batch-core:5.+")
Expand All @@ -216,6 +215,9 @@ dependencies {
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.security:spring-security-web:6.0.+")
"testWithSpringBoot_3_0RuntimeOnly"("org.springframework.security:spring-security-ldap:6.0.+")

"testWithSpringBoot_3_2RuntimeOnly"("org.springframework.boot:spring-boot-starter:3.2+")
"testWithSpringBoot_3_2RuntimeOnly"("org.springframework.boot:spring-boot-starter-test:3.2+")

"testWithSpringSecurity_5_7RuntimeOnly"("org.springframework:spring-context:5.3.+")
"testWithSpringSecurity_5_7RuntimeOnly"("org.springframework.boot:spring-boot-starter:2.7.+")
"testWithSpringSecurity_5_7RuntimeOnly"("org.springframework.boot:spring-boot:2.7.+")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[*.java]
indent_size = 4
ij_continuation_indent_size = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2021 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java.spring.boot3;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.properties.Assertions.properties;
import static org.openrewrite.yaml.Assertions.yaml;

class EnableVirtualThreadsTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec.recipeFromResources("org.openrewrite.java.spring.boot3.EnableVirtualThreads");
}

@Test
@DocumentExample
void enableVirtualThreadsProperties() {
rewriteRun(
//language=properties
properties(
"",
"""
spring.threads.virtual.enabled=true
""",
s -> s.path("src/main/resources/application.properties")
)
);
}

@Test
@DocumentExample
void enableVirtualThreadsYaml() {
rewriteRun(
//language=yaml
yaml(
"",
"""
spring:
threads.virtual.enabled: true
""",
s -> s.path("src/main/resources/application.yml")
)
);
}

@Test
void dontEnableVirtualThreadsIfDisabled() {
rewriteRun(
//language=properties
properties(
"""
spring.threads.virtual.enabled=false
""",
s -> s.path("src/main/resources/application.properties")
),
//language=yaml
yaml(
"""
spring:
threads.virtual.enabled: false
""",
s -> s.path("src/main/resources/application.yml")
)
);
}
}

0 comments on commit a165c80

Please sign in to comment.