Using WireMock with Spring Boot 3 and JUnit 5

To use WireMock with JUnit 4.x you use a @Rule statement to configure the WireMock server:

@Rule
public WireMockRule wireMockRule = new WireMockRule();

With JUnit 5, @Rule was replaced with extensions, so the equivalent setup looks like this:

@RegisterExtension
static WireMockExtension wm1 = WireMockExtension.newInstance()
.options(options().port(8089))
.build();

Testing Spring Boot 3 apps with JUnit 5 however gives the following error as Spring Boot 3 does not have Jetty 11 dependencies, so WireMock’s use of Jetty 11 fails to start:

com.github.tomakehurst.wiremock.common.FatalStartupException: Jetty 11 is not present and no suitable HttpServerFactory extension was found. Please ensure that the classpath includes a WireMock extension that provides an HttpServerFactory implementation. See http://wiremock.org/docs/extending-wiremock/ for more information.
at com.github.tomakehurst.wiremock.WireMockServer.lambda$getHttpServerFactory$2(WireMockServer.java:95)

Per the WireMock docs here, wiremock-spring-boot provides support using another approach. To use, add this dependency:

<dependency>
<groupId>com.maciejwalkowiak.spring</groupId>
<artifactId>wiremock-spring-boot</artifactId>
<version>2.1.2</version>
<scope>test</scope>
</dependency>

Enable for your test by adding @EnableWireMock:

@SpringBootTest
@EnableWireMock({
@ConfigureWireMock(name = "your-mock-service", property = "your-url-to-mock.url")
})
class YourTest {
...
}

Inject the WireMock server into your test with:

@InjectWireMock("your-mock-service")
private WireMockServer wiremock;

@Value("${your-url-to-mock.url}")
private String wiremockUrl;

While this is a neat option to use with SpringBootTests, unfortunately it still doesn’t work with Spring Boot 3.3.x because of WireMock’s dependency on Jetty 11.

Tickets posted on the wiremock-spring-boot project suggest to avoid this in the meantime by using a dependency for wiremock-standalone instead:

        <dependency>
<groupId>com.maciejwalkowiak.spring</groupId>
<artifactId>wiremock-spring-boot</artifactId>
<version>2.0.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>

This works as expected.

Changing MacOS keybindings for Home/End keys to behave the same as Windows

Sometimes muscle memory is hard to unlearn. I can’t get used to the Home and End keys on a Mac jumping to the top and end of a file instead of start and end of a line. Yes, I know Cmd-left and Cmd-right do the same thing on a Mac, but pressing Home and having it jump to the top of a file is too much for me to handle when in the middle of editing something in an IDE like Eclipse.

To remap the Home and End keys to behave the same as on Windows, make a dir here:

mkdir ~/Library/KeyBindings

and create a file called DefaultKeyBinding.dict (NOTE: this file must be named exactly as shown to work) containing this content:

{
"\UF729" = "moveToBeginningOfLine:";
"\UF72B" = "moveToEndOfLine:";
"$\UF729" = "moveToBeginningOfLineAndModifySelection:";
"$\UF72B" = "moveToEndOfLineAndModifySelection:";
}

Logoff and log back on again, and the Home and End keys should now work the same as on Windows. (source here)

If this still doesn’t work in Eclipse, it maybe because Line Start and Line End and explicitly mapped to Cmd-left and Cmd-right – these can be changed in Preferences under Keys:

Delete the existing mappings for Home and End and change to the Home and End keys:

Updating local versions of Docker images if using the latest tag

I have an ubuntu:latest image pulled locally from a couple of years ago, and it’s obviously not the latest since it’s over 2 years old. ‘docker images’ shows:

ubuntu                                                                           latest                     d5ca7a445605   2 years ago     65.6MB

If I run the image with -it and cat the /etc/lsb-release file, it shows it’s 20.04. Docker Hub is currently showing latest as 22.04.

To update it, if I ‘docker pull ubuntu:latest’ then it shows:

> docker pull ubuntu:latest
latest: Pulling from library/ubuntu
70104cd59e2a: Pull complete
Digest: sha256:1b8d8ff4777f36f19bfe73ee4df61e3a0b789caeff29caa019539ec7c9a57f95
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

If I now start it and cat /etc/lsb-release, it shows 22.04. Done!

Moving from msql client to mysqlsh

I posted a while back about running mysql in a Docker container on an Apple Silicon MacBook. It’s been a while since I’ve run mysql locally, and it seems the mysqlsh client is now preferred over the previous mysql client.

With mysqlsh, after connecting, to issue a ‘use’ command to select a db, use ‘\use dbname’

Once a db is selected, to issue other mysql commands enter the sql mode with ‘\sql’ command.