[Hawkular-dev] Mocking HTTP Server

John Sanda jsanda at redhat.com
Fri Jun 5 11:03:33 EDT 2015


> 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




More information about the hawkular-dev mailing list