Skip to content

Commit

Permalink
added a basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
joanvr committed Jul 28, 2023
1 parent 0156149 commit 9b22f47
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 27 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ dependencies {

testRuntimeOnly("ch.qos.logback:logback-classic:1.+")
testRuntimeOnly(gradleApi())
testRuntimeOnly("org.apache.httpcomponents:httpclient:4.5.14")
testRuntimeOnly("org.apache.httpcomponents.client5:httpclient5:5.1.+")

testImplementation("com.github.marschall:memoryfilesystem:latest.release")

Expand Down
54 changes: 27 additions & 27 deletions src/main/resources/META-INF/rewrite/apache-httpclient-5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,33 +275,6 @@ recipeList:
oldFullyQualifiedTypeName: org.apache.hc.core5.http.impl.io.DefaultHttpResponseFactory
newFullyQualifiedTypeName: org.apache.hc.core5.http.impl.nio.DefaultHttpResponseFactory

- org.openrewrite.java.ChangePackage:
oldPackageName: org.apache.http.conn
newPackageName: org.apache.hc.client5.http
# Fixing specific mappings
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.ManagedHttpClientConnection
newFullyQualifiedTypeName: org.apache.hc.client5.http.io.ManagedHttpClientConnection
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.HttpClientConnectionManager
newFullyQualifiedTypeName: org.apache.hc.client5.http.io.HttpClientConnectionManager
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.HttpClientConnectionOperator
newFullyQualifiedTypeName: org.apache.hc.client5.http.io.HttpClientConnectionOperator
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.EofSensorWatcher
newFullyQualifiedTypeName: org.apache.hc.core5.http.io.EofSensorWatcher
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.EofSensorInputStream
newFullyQualifiedTypeName: org.apache.hc.core5.http.io.EofSensorInputStream
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.HttpConnectionFactory
newFullyQualifiedTypeName: org.apache.hc.core5.http.io.HttpConnectionFactory
# Fixing Deprecated
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.ClientConnectionManager
newFullyQualifiedTypeName: org.apache.hc.client5.http.io.HttpClientConnectionManager

- org.openrewrite.java.ChangePackage:
oldPackageName: org.apache.http.conn.util
newPackageName: org.apache.hc.client5.http.psl
Expand Down Expand Up @@ -382,6 +355,33 @@ recipeList:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.impl.io.DefaultHttpResponseParser
newFullyQualifiedTypeName: org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser

- org.openrewrite.java.ChangePackage:
oldPackageName: org.apache.http.conn
newPackageName: org.apache.hc.client5.http
# Fixing specific mappings
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.ManagedHttpClientConnection
newFullyQualifiedTypeName: org.apache.hc.client5.http.io.ManagedHttpClientConnection
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.HttpClientConnectionManager
newFullyQualifiedTypeName: org.apache.hc.client5.http.io.HttpClientConnectionManager
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.HttpClientConnectionOperator
newFullyQualifiedTypeName: org.apache.hc.client5.http.io.HttpClientConnectionOperator
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.EofSensorWatcher
newFullyQualifiedTypeName: org.apache.hc.core5.http.io.EofSensorWatcher
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.EofSensorInputStream
newFullyQualifiedTypeName: org.apache.hc.core5.http.io.EofSensorInputStream
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.HttpConnectionFactory
newFullyQualifiedTypeName: org.apache.hc.core5.http.io.HttpConnectionFactory
# Fixing Deprecated
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.ClientConnectionManager
newFullyQualifiedTypeName: org.apache.hc.client5.http.io.HttpClientConnectionManager

- org.openrewrite.java.ChangePackage:
oldPackageName: org.apache.http
newPackageName: org.apache.hc.core5.http
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.apache.httpclient5;

import org.junit.jupiter.api.Test;
import org.openrewrite.config.Environment;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.java;

public class NamespaceChangesTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec
.parser(JavaParser.fromJavaVersion()
.classpath("httpclient", "httpcore", "httpclient5", "httpcore5")
)
.recipe(Environment.builder()
.scanRuntimeClasspath("org.openrewrite", "org.openrewrite.java", "org.openrewrite.java.dependencies")
.build()
.activateRecipes("org.openrewrite.java.apache.httpclient5.UpgradeApacheHttpClient_5_ClassMapping")
);
}

@Test
void testSomeImports() {
rewriteRun(
//language=java
java("""
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.util.EntityUtils;
class A {
void method(HttpEntity entity, String urlStr) {
HttpUriRequest getRequest = new HttpGet(urlStr);
EntityUtils.consume(entity);
}
}
""","""
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
class A {
void method(HttpEntity entity, String urlStr) {
HttpUriRequest getRequest = new HttpGet(urlStr);
EntityUtils.consume(entity);
}
}
""")
);
}
}

0 comments on commit 9b22f47

Please sign in to comment.