Service Virtualization is a technique using to emulate the behaviour of dependencies of component-based applications.

Hoverfly is a service virtualisation tool written in Go which allows you to emulate HTTP(S) services. It is a proxy which responds to HTTP(S) requests with stored responses, pretending to be it’s real counterpart.

No vull veure't, vull mirar-te. No vull imaginar-te, vull sentir-te. Vull compartir tot això que sents. No vull tenir-te a tu: vull, amb tu, tenir el temps. (Una LLuna a l'Aigua - Txarango)

is a wrapper around, that let's you use it in Java world. It provides a native Java DSL to write expectations and arule to use it together withBut apart from being able to program expectations, you can also useto capture traffic between both services (in both cases are real services) and persist it.Then in next runswill use these persisted scripts to emulate traffic and not touch the remote service. In this way, instead of programming expectations, which means that you are programming how you understand the system, you are using real communication data.This can be summarised in next figures:First time the output traffic is sent thoughproxy, it is redirected to real service and it generates a response. Then when the response arrives to proxy, both request and response are stored, and the real response is sent back to caller.Then in next calls of same method:The output traffic of Service A is still sent thoughproxy, but now the response is returned from previous stored responses instead of redirecting to real service.So, how to connect from HTTP client of Service A toproxy? The quick answer is nothing.just overrides Java network system properties ( https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html ) so you don't need to do anything, all communications (independently of the host you put there) from HTTP client will go throughproxy.The problem is what's happening if the API you are using as HTTP client does not honor these system properties? Then obviously all outgoing communications will not pass thorough proxy.One example isand its HTTP client. Since WebClient does not honor these properties, you need to configure the client properly in order to useThe basic step you need to do is just configurewith proxy options that are set as system properties.Notice that the only thing that it done here is just checking if system properties regarding network proxy has been configured (byJava) and if it is the case just create aobject to configure the HTTP client.With this change, you can write tests withandwithout any problem:In previous exampleis used as in simulate mode and the request/response definitions comes in form of DSL instead of an external JSON script.Notice that in this case you are programming that when a request by current service (), is done to hostand port, usingHTTP method atthen the response is returned. For sake of simplicity of current post this method is enough.You can see source code at https://github.com/arquillian-testing-microservices/villains-service and read aboutJava at http://hoverfly-java.readthedocs.io/en/latest/ We keep learning,AlexMusic: https://www.youtube.com/watch?v=BeH2eH9iPw4