DataWeave Tip #8: The write Function

Originally published February 26, 2019

Recently I have been working on a really simple case. When an HTTP server returned an error and a non-empty body, I needed to embed this body into an error structure. Although this is a simple case, I got a problem with implementing it in Mule 4. In the previous Mule edition, it was a little bit simpler. So let's see what it is all about.

Case

First, we have a look at the case that I have to implement. I have a mule application that is calling an external HTTP server via an HTTP request component. When the server responds with an error like 4xx, 5xx, and the returned body will is not empty, we would like to forward that response to the calling application.

Use Mocks in Testing? Choose the Lesser Evil!

Mocking Test Methodology 

The key idea of mocking is to replace real code (e.g. calls to a database or service) with artificial functionality that has the same return type. There are different approaches to this practice. Here, I explain best practices and why it might be better to avoid mocking to have real code quality.

User Service — Example to Be Tested With Mocks

Let's write a simple application that fetches users from HTTP service.