-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create spring 2.7 data YML file with getReferenceById changes (#518)
* Create spring 2.7 data YML file with getReferenceById changes * Include Spring Data migration with Spring Boot 2.7 migration * Add a quick unit test, that fails for now * Add DocumentExample * ChangeMethodName for Spring Data 2.5 should match overrides * Add missing spring-data-commons reference to test * Drop unused test dependency --------- Co-authored-by: Lucas Han <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
- Loading branch information
1 parent
e9e3340
commit 4ecc3f2
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# Copyright 2024 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. | ||
# | ||
|
||
######################################################################################################################## | ||
# Spring Data 2.7 | ||
--- | ||
type: specs.openrewrite.org/v1beta/recipe | ||
name: org.openrewrite.java.spring.data.UpgradeSpringData_2_7 | ||
displayName: Migrate to Spring Data 2.7 | ||
description: Migrate applications to the latest Spring Data 2.7 release. | ||
recipeList: | ||
- org.openrewrite.java.spring.data.UpgradeSpringData_2_5 | ||
- org.openrewrite.java.spring.data.UseJpaRepositoryGetReferenceById | ||
--- | ||
type: specs.openrewrite.org/v1beta/recipe | ||
name: org.openrewrite.java.spring.data.UseJpaRepositoryGetReferenceById | ||
displayName: Use `JpaRepository#getReferenceById(ID id)` | ||
description: '`JpaRepository#getOne(ID)` was deprecated in 2.5 and `JpaRepository#getById(ID)` was deprecated in 2.7.' | ||
recipeList: | ||
- org.openrewrite.java.ChangeMethodName: | ||
methodPattern: org.springframework.data.jpa.repository.JpaRepository getById(..) | ||
newMethodName: getReferenceById | ||
matchOverrides: true | ||
- org.openrewrite.java.ChangeMethodName: | ||
methodPattern: org.springframework.data.jpa.repository.JpaRepository getOne(..) | ||
newMethodName: getReferenceById | ||
matchOverrides: true |
79 changes: 79 additions & 0 deletions
79
...gBoot_2_7/java/org/openrewrite/java/spring/data/UseJpaRepositoryGetReferenceByIdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2024 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.data; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.DocumentExample; | ||
import org.openrewrite.InMemoryExecutionContext; | ||
import org.openrewrite.java.JavaParser; | ||
import org.openrewrite.test.RecipeSpec; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
import static org.openrewrite.java.Assertions.java; | ||
|
||
class UseJpaRepositoryGetReferenceByIdTest implements RewriteTest { | ||
|
||
@Override | ||
public void defaults(RecipeSpec spec) { | ||
spec | ||
.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "spring-data-commons-2.7", "spring-data-jpa-2.7")) | ||
.recipeFromResource("/META-INF/rewrite/spring-data-27.yml", "org.openrewrite.java.spring.data.UseJpaRepositoryGetReferenceById"); | ||
} | ||
|
||
@Test | ||
@DocumentExample | ||
void matchAndUpdateReferences() { | ||
//language=java | ||
rewriteRun( | ||
java( | ||
""" | ||
package foo; | ||
public class Book {} | ||
""" | ||
), | ||
java( | ||
""" | ||
package foo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
public interface BookRepository extends JpaRepository<Book, Long> { | ||
} | ||
""" | ||
), | ||
java( | ||
""" | ||
import foo.*; | ||
class A { | ||
BookRepository repo; | ||
void method(Long id) { | ||
repo.getById(id); | ||
repo.getOne(id); | ||
} | ||
} | ||
""", | ||
""" | ||
import foo.*; | ||
class A { | ||
BookRepository repo; | ||
void method(Long id) { | ||
repo.getReferenceById(id); | ||
repo.getReferenceById(id); | ||
} | ||
} | ||
""" | ||
) | ||
); | ||
} | ||
} |