Wiremock Bookmarks

Published: 2020-09-02, Updated: 2020-09-02

Mocando servidores HTTP com Wiremock

POST /__admin/mappings/reset

Criando mock programaticamente

mockServer
.stubFor(
    get(urlPathEqualTo("/nextBusinessDay"))
        .willReturn(
            aResponse()
                .withHeaders(new HttpHeaders(
                    HttpHeader.httpHeader("content-type", "application/json")
                ))
                .withJsonBody(
                    JsonNodeFactory
                        .instance
                        .objectNode()
                        .put("nextBusinessDay",
                            LocalDateTime
                                .now()
                                .plusDays(1)
                                .format(API_DATE_FORMATTER)
                        )
                )
        )
);

Mocando servidores HTTP com Wiremock no Modo Standalone

Subindo o server

java -jar wiremock-standalone-2.10.1.jar

Criando mock via API

$ curl -X POST \
--data '{ "request": { "url": "/get/this", "method": "GET" }, "response": { "status": 200, "body": "Here it is!\n" }}' \
http://localhost:8080/__admin/mappings/new

Testando

$ curl http://localhost:8080/get/this
Here it is!

Criando mock via arquivo (tem que derrubar e subir o server depois de criar/deletar o arquivo)

{
	"request": {
		"method": "GET",
		"url": "/api/mytest"
	},
	"response": {
		"status": 200,
		"body": "More content\n"
	}
}

Testando

$ curl -XGET localhost:8080/api/mytest

wiremock commands


Configurar Mouse e Teclado Como fazer baliza com facilidade

Comments