Incredibly Useful WireMock with IntelliJ IDEA

Look, WireMock is great! But it can be much better with the proper tooling. And wait no more, seems IntelliJ IDEA 2024.2 now have a proper plugin that finally improves a lot of things around WireMock JSON stubs!

Install WireMock Plugin

It i…


This content originally appeared on DEV Community and was authored by Impatient Insider

Look, WireMock is great! But it can be much better with the proper tooling. And wait no more, seems IntelliJ IDEA 2024.2 now have a proper plugin that finally improves a lot of things around WireMock JSON stubs!

Install WireMock Plugin

It is right here, you need IntelliJ IDEA Ultimate or any other commercial edition of JetBrains IDEs.

From Server Code to Stubs

Let's open a basic Spring PetClinic code and start by creating some stubs for our application. Go to Endpoints tool window, select desired request mappings and open the context menu.

Generating Stubs

Great! Generated stubs posted to the editor:

{
  "mappings": [
    {
      "request": {
        "url": "/owners/find",
        "method": "GET"
      },
      "response": {
        "status": 200
      }
    }
  ]
}

As far as I understand, IDE uses special scratch files for that and you can go back to generated code any time:

Scratches

Editing Experience

Once we get to the editor we see completion available and it also validates the correctness of the document.

Code Completion

Run

And what we can do right away without installing anything - start the mock server via run line marker or a floating button in the editor.

Starting Server

Runing

The server is bundled with the plugin so it starts immediately. Let's check if it responds via HTTP Client. It would be a simple request:

Getting 200

Viola! Getting 200 code in return!

Enabling Templates

There is an additional magic button in the editor you can try:

Enabling Templates

It enables Handlebars templating in your stubs files (completion, highlighting, etc). So we can write a more sophisticated stub now:

{
  "request": {
    "urlPathTemplate": "/owners/find/{name}"
  },
  "response": {
    "body": "{{request.path.name}}",
    "transformers": ["response-template"]
  }
}

And IDE helps us with all properties of a request and available functions:

Completion

Conclusion

Not that it is a big deal as AI nowadays, but WireMock plugin for IntelliJ is a huge time-saver for me. Mock everything folks, it pays of!


This content originally appeared on DEV Community and was authored by Impatient Insider


Print Share Comment Cite Upload Translate Updates
APA

Impatient Insider | Sciencx (2024-08-13T21:00:29+00:00) Incredibly Useful WireMock with IntelliJ IDEA. Retrieved from https://www.scien.cx/2024/08/13/incredibly-useful-wiremock-with-intellij-idea/

MLA
" » Incredibly Useful WireMock with IntelliJ IDEA." Impatient Insider | Sciencx - Tuesday August 13, 2024, https://www.scien.cx/2024/08/13/incredibly-useful-wiremock-with-intellij-idea/
HARVARD
Impatient Insider | Sciencx Tuesday August 13, 2024 » Incredibly Useful WireMock with IntelliJ IDEA., viewed ,<https://www.scien.cx/2024/08/13/incredibly-useful-wiremock-with-intellij-idea/>
VANCOUVER
Impatient Insider | Sciencx - » Incredibly Useful WireMock with IntelliJ IDEA. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/13/incredibly-useful-wiremock-with-intellij-idea/
CHICAGO
" » Incredibly Useful WireMock with IntelliJ IDEA." Impatient Insider | Sciencx - Accessed . https://www.scien.cx/2024/08/13/incredibly-useful-wiremock-with-intellij-idea/
IEEE
" » Incredibly Useful WireMock with IntelliJ IDEA." Impatient Insider | Sciencx [Online]. Available: https://www.scien.cx/2024/08/13/incredibly-useful-wiremock-with-intellij-idea/. [Accessed: ]
rf:citation
» Incredibly Useful WireMock with IntelliJ IDEA | Impatient Insider | Sciencx | https://www.scien.cx/2024/08/13/incredibly-useful-wiremock-with-intellij-idea/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.