Skip to main content

Upgrade WireMock to 4.x

org.openrewrite.java.testing.wiremock.Wiremock3to4Migration

Upgrade WireMock to 4.x, which requires Java 17, ships Jetty 12.1 by default, splits JUnit support out into separate modules and makes the primary domain classes immutable. Note that RequestMethod.GET_OR_HEAD is a multi method matcher in 4.x rather than a method named GET_OR_HEAD, so code reading a name off that particular constant needs a look.

Tags​

Recipe source​

GitHub: wiremock4.yml, Issue Tracker, Code Genome Project

Info

This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.

This recipe is available under the Moderne Source Available License. Moderne customers can download precompiled artifacts from The Code Genome Project. For non-commercial use you can build the artifact from source locally.

Definition​

Preconditions

Recipes

  • Keep a single Content-Type response header while still on WireMock 3
  • Upgrade WireMock to 3.x
  • Change Gradle or Maven dependency
    • oldGroupId: org.wiremock
    • oldArtifactId: wiremock-jetty12
    • newGroupId: org.wiremock
    • newArtifactId: wiremock
    • newVersion: 4.0.0-beta.38
  • Upgrade Gradle or Maven dependency versions
    • groupId: org.wiremock
    • artifactId: wiremock
    • newVersion: 4.0.0-beta.38
  • Upgrade Gradle or Maven dependency versions
    • groupId: org.wiremock
    • artifactId: wiremock-standalone
    • newVersion: 4.0.0-beta.38
  • Add Gradle or Maven dependency
    • groupId: org.wiremock
    • artifactId: wiremock-junit5
    • version: 4.0.0-beta.38
    • onlyIfUsing: com.github.tomakehurst.wiremock.junit5.*
    • scope: test
  • Add Gradle or Maven dependency
    • groupId: org.wiremock
    • artifactId: wiremock-junit4
    • version: 4.0.0-beta.38
    • onlyIfUsing: com.github.tomakehurst.wiremock.junit.WireMock*Rule
    • scope: test
  • Add Gradle or Maven dependency
    • groupId: org.eclipse.jetty
    • artifactId: jetty-client
    • version: 12.1.x
    • onlyIfUsing: org.eclipse.jetty.client.*
  • Add Gradle or Maven dependency
    • groupId: org.eclipse.jetty
    • artifactId: jetty-proxy
    • version: 12.1.x
    • onlyIfUsing: org.eclipse.jetty.proxy.*
  • Add Gradle or Maven dependency
    • groupId: org.eclipse.jetty
    • artifactId: jetty-xml
    • version: 12.1.x
    • onlyIfUsing: org.eclipse.jetty.xml.*
  • Add Gradle or Maven dependency
    • groupId: org.eclipse.jetty.ee10
    • artifactId: jetty-ee10-webapp
    • version: 12.1.x
    • onlyIfUsing: org.eclipse.jetty.ee10.webapp.*
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty11.CertificateGeneratingSslContextFactory
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.ssl.CertificateGeneratingSslContextFactory
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty11.HttpsProxyDetectingHandler
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.proxy.HttpsProxyDetectingHandler
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty11.ManInTheMiddleSslConnectHandler
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.proxy.ManInTheMiddleSslConnectHandler
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty11.NotFoundHandler
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.NotFoundHandler
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty11.SslContexts
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.ssl.SslContexts
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty11.WritableFileOrClasspathKeyStoreSource
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.common.ssl.WritableFileOrClasspathKeyStoreSource
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty12.HttpProxyDetectingHandler
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.proxy.HttpProxyDetectingHandler
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty12.HttpsProxyDetectingHandler
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.proxy.HttpsProxyDetectingHandler
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty12.Jetty12HttpServer
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.Jetty12HttpServer
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty12.Jetty12HttpServerFactory
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.JettyHttpServerFactory
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty12.Jetty12HttpUtils
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.Jetty12HttpUtils
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty12.ManInTheMiddleSslConnectHandler
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.proxy.ManInTheMiddleSslConnectHandler
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty12.NotFoundHandler
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.NotFoundHandler
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.JettyFaultInjector
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.faults.JettyFaultInjector
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.JettyFaultInjectorFactory
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.faults.JettyFaultInjectorFactory
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.JettyHttpsFaultInjector
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.faults.JettyHttpsFaultInjector
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.ContentTypeSettingFilter
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.ContentTypeSettingFilter
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.FaultInjectorFactory
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.FaultInjectorFactory
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.NoFaultInjector
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.NoFaultInjector
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.NoFaultInjectorFactory
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.NoFaultInjectorFactory
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.NotMatchedServlet
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.NotMatchedServlet
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.TrailingSlashFilter
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.TrailingSlashFilter
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.WarConfiguration
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.WarConfiguration
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.WireMockHandlerDispatchingServlet
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.WireMockHttpServletMultipartAdapter
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.WireMockHttpServletMultipartAdapter
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.WireMockHttpServletRequestAdapter
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.WireMockHttpServletRequestAdapter
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.servlet.WireMockWebContextListener
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.WireMockWebContextListener
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.common.ServletContextFileSource
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.servlet.ServletContextFileSource
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.common.JettySettings
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.JettySettings
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.client.ApacheBackedHttpClient
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.client.apache5.ApacheBackedHttpClient
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.client.ApacheHttpClientFactory
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.client.apache5.ApacheHttpClientFactory
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.NetworkAddressRulesAdheringDnsResolver
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.client.apache5.NetworkAddressRulesAdheringDnsResolver
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.ssl.TrustSelfSignedStrategy
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.client.apache5.TrustSelfSignedStrategy
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.HttpClientFactory
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.client.HttpClientFactory
    • ignoreDefinition: true
  • Change type
    • oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.MimeType
    • newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.common.entity.MimeType
    • ignoreDefinition: true
  • Replace WireMock constructors removed in 4.x
  • Replace WireMock setter calls with transform()
  • Migrate the uuid field in WireMock stub mapping files to id
  • Preserve the UTF-8 default of ContentTypeHeader.charset()
  • Migrate RequestMethod.isOneOf to the matcher it became
  • Change method name
    • methodPattern: com.github.tomakehurst.wiremock.stubbing.StubMapping getUuid()
    • newMethodName: getId
  • Change method name
    • methodPattern: com.github.tomakehurst.wiremock.http.RequestMethod value()
    • newMethodName: getName

Usage​

This recipe has no required configuration options. It can be activated by adding a dependency on `org.openrewrite.recipe:rewrite-testing-frameworks` in your build file or by running a shell command (in which case no build changes are needed):

OpenRewrite artifacts, including the Maven and Gradle plugins themselves, are distributed through the Code Genome Project repository (https://artifacts.codegenomeproject.org/maven), which requires authentication. Sign in to the Code Genome Project to create a download token; your build authenticates with the email or username you signed in with, plus that token as the password. See the quickstart guide for details.

  1. Put your Code Genome Project credentials in ~/.gradle/gradle.properties, so that they are not committed alongside your build:
    ~/.gradle/gradle.properties
    codeGenomeUsername=you@example.com
    codeGenomeToken=your-download-token
  2. Add the Code Genome Project repository to your settings.gradle file, so that the plugin itself can be resolved:
    settings.gradle
    pluginManagement {
    repositories {
    maven {
    url = "https://artifacts.codegenomeproject.org/maven"
    credentials {
    username = providers.gradleProperty("codeGenomeUsername").get()
    password = providers.gradleProperty("codeGenomeToken").get()
    }
    }
    // Keep the portal for any other plugins your build applies
    gradlePluginPortal()
    }
    }
  3. Add the following to your build.gradle file:
    build.gradle
    plugins {
    id("org.openrewrite.rewrite") version("latest.release")
    }

    rewrite {
    activeRecipe("org.openrewrite.java.testing.wiremock.Wiremock3to4Migration")
    setExportDatatables(true)
    }

    repositories {
    mavenCentral()
    maven {
    url = "https://artifacts.codegenomeproject.org/maven"
    credentials {
    username = providers.gradleProperty("codeGenomeUsername").get()
    password = providers.gradleProperty("codeGenomeToken").get()
    }
    }
    }

    dependencies {
    rewrite("org.openrewrite.recipe:rewrite-testing-frameworks:3.48.0")
    }
  4. Run gradle rewriteRun to run the recipe.

See how this recipe works across multiple open-source repositories​

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables​

Source files that had results​

org.openrewrite.table.SourcesFileResults

Source files that were modified by the recipe run.

Column NameDescription
Source path before the runThe source path of the file before the run. null when a source file was created during the run.
Source path after the runA recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run.
Parent of the recipe that made changesIn a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all.
Recipe that made changesThe specific recipe that made a change.
Estimated time savingAn estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds.
CycleThe recipe cycle in which the change was made.