-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move HtmlUnit migrations to rewrite-testing-frameworks (#643)
* Move HtmlUnit migrations to rewrite-testing-frameworks Coming from rewrite-jenkins * Add explicit new 3.x versions
- Loading branch information
Showing
3 changed files
with
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# | ||
# 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. | ||
# | ||
--- | ||
type: specs.openrewrite.org/v1beta/recipe | ||
name: org.openrewrite.java.testing.htmlunit.UpgradeHtmlUnit_3 | ||
displayName: Migrate to HtmlUnit 3.x | ||
description: >- | ||
Automates the HtmlUnit [migration guide](https://htmlunit.sourceforge.io/migration.html) from 2.x to 3.x. | ||
recipeList: | ||
- org.openrewrite.java.dependencies.ChangeDependency: | ||
oldGroupId: net.sourceforge.htmlunit | ||
oldArtifactId: '*' | ||
newGroupId: org.htmlunit | ||
newVersion: 3.x | ||
- org.openrewrite.java.dependencies.ChangeDependency: | ||
oldGroupId: com.gargoylesoftware | ||
oldArtifactId: HTMLUnit | ||
newGroupId: org.htmlunit | ||
newArtifactId: htmlunit | ||
newVersion: 3.x | ||
- org.openrewrite.java.ChangePackage: | ||
oldPackageName: com.gargoylesoftware.htmlunit | ||
newPackageName: org.htmlunit | ||
recursive: true | ||
- org.openrewrite.java.ChangeMethodName: | ||
methodPattern: org.htmlunit.html.HtmlInput getValueAttribute() | ||
newMethodName: getValue | ||
matchOverrides: true | ||
- org.openrewrite.java.ChangeMethodName: | ||
methodPattern: org.htmlunit.html.HtmlInput setValueAttribute(String) | ||
newMethodName: setValue | ||
matchOverrides: true |
90 changes: 90 additions & 0 deletions
90
src/test/java/org/openrewrite/java/testing/htmlunit/UpgradeHtmlUnit3Test.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,90 @@ | ||
/* | ||
* Copyright 2023 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.testing.htmlunit; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.DocumentExample; | ||
import org.openrewrite.java.JavaParser; | ||
import org.openrewrite.test.RecipeSpec; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
import static org.openrewrite.java.Assertions.java; | ||
|
||
class UpgradeHtmlUnit3Test implements RewriteTest { | ||
|
||
@Override | ||
public void defaults(RecipeSpec spec) { | ||
spec | ||
.parser(JavaParser.fromJavaVersion().classpath("htmlunit")) | ||
.recipeFromResource("/META-INF/rewrite/htmlunit.yml", "org.openrewrite.java.testing.htmlunit.UpgradeHtmlUnit_3"); | ||
} | ||
|
||
@Test | ||
@DocumentExample | ||
void shouldUpdateHtmlUnit() { | ||
rewriteRun( | ||
//language=java | ||
java( | ||
""" | ||
import com.gargoylesoftware.htmlunit.WebClient; | ||
import com.gargoylesoftware.htmlunit.html.HtmlForm; | ||
import com.gargoylesoftware.htmlunit.html.HtmlInput; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
import java.io.IOException; | ||
public class HtmlUnitUse { | ||
void run() throws IOException { | ||
try (WebClient webClient = new WebClient()) { | ||
HtmlPage page = webClient.getPage("https://htmlunit.sourceforge.io/"); | ||
HtmlForm form = page.getFormByName("config"); | ||
HtmlInput a = form.getInputByName("a"); | ||
String value = a.getValueAttribute(); | ||
assert "".equals(value); | ||
a.setAttribute("value", "up2"); | ||
a.setAttribute("value2", "leave"); | ||
a.setValueAttribute("updated"); | ||
} | ||
} | ||
} | ||
""", | ||
""" | ||
import org.htmlunit.WebClient; | ||
import org.htmlunit.html.HtmlForm; | ||
import org.htmlunit.html.HtmlInput; | ||
import org.htmlunit.html.HtmlPage; | ||
import java.io.IOException; | ||
public class HtmlUnitUse { | ||
void run() throws IOException { | ||
try (WebClient webClient = new WebClient()) { | ||
HtmlPage page = webClient.getPage("https://htmlunit.sourceforge.io/"); | ||
HtmlForm form = page.getFormByName("config"); | ||
HtmlInput a = form.getInputByName("a"); | ||
String value = a.getValue(); | ||
assert "".equals(value); | ||
a.setAttribute("value", "up2"); | ||
a.setAttribute("value2", "leave"); | ||
a.setValue("updated"); | ||
} | ||
} | ||
} | ||
""" | ||
) | ||
); | ||
} | ||
} |