[Hawkular-dev] Mocking HTTP Server

Peter Palaga ppalaga at redhat.com
Fri Jun 5 11:50:07 EDT 2015


Thanks John and others for ideas.

Indeed, doing this with Vertex seems to be very elegant.

Anyway, wiremock seems to be the winner for both its built-in and easy 
to use HTTPS support and the fact that it provides a JUnit rule that 
starts and stops the HTTP(s) service around the tests as needed.

Here is the PR: https://github.com/hawkular/hawkular/pull/193

Thanks again,

Peter

On 2015-06-05 17:03, John Sanda wrote:
>
>> On Jun 5, 2015, at 10:19 AM, John Sanda <jsanda at redhat.com> wrote:
>>
>> On Jun 5, 2015, at 10:09 AM, Peter Palaga <ppalaga at redhat.com> wrote:
>>>
>>> Hi *,
>>>
>>> it happened today: http://perfcake.org/ - one of the sites we unit-test
>>> Pinger against is down and therefore the tests are failing.
>>>
>>> Can anybody recommend a solution for mocking an HTTP Server?
>>
>> If you want more of an integration test, what about just running an HTTP server in a separate thread?
>
> Here is a simple example using Vert.x with Groovy,
>
> //----------------------------------------------------------------------------------------------------
> @Test
> void pingServer() {
>    HttpServerOptions options = new HttpServerOptions(port: 7575)
>    HttpServer server = Vertx.vertx().createHttpServer(options).requestHandler { request ->
>      request.response().putHeader('Content-Type', "text/plain").setStatusCode(200).end("test")
>    }
>    server.listen()
>
>    RESTClient client = new RESTClient("http://localhost:7575", "text/plain")
>    def response = client.get(path: "/")
>
>    assertEquals(200, response.status)
>
>    server.close()
> }
> //----------------------------------------------------------------------------------------------------
>
> IMO this is a lot easier than relying on an external server. And it is much simpler to control the server behavior.
>>
>>>
>>> http://wiremock.org/ is the first result on Google and I am going to
>>> have a look at it.
>>>
>>> Thanks,
>>>
>>> Peter
>>> _______________________________________________
>>> hawkular-dev mailing list
>>> hawkular-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/hawkular-dev
>>
>>
>> _______________________________________________
>> hawkular-dev mailing list
>> hawkular-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hawkular-dev
>
>
> _______________________________________________
> hawkular-dev mailing list
> hawkular-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hawkular-dev
>



More information about the hawkular-dev mailing list