zoukankan      html  css  js  c++  java
  • MockServer调试通过,本地通过浏览器可以打开对应web网页


    import
    static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import java.util.HashMap; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; import com.zte.aip.dfs.HttpClient; import net.sf.json.JSONObject; public class MockTest{ public static void main(String[] args) { System.out.println("This is println message."); String str = "tac"; int i = 1; logger.debug("This is debug message."); logger.info("This is info message."); logger.warn("warn message {} int: {}", str, i); logger.error("This is error message."); WireMockServer wireMockServer = null; wireMockServer = new WireMockServer(wireMockConfig().port(8888)); WireMock.configureFor("localhost", 8888); wireMockServer.start(); stubFor(get(urlEqualTo("/cars/Chevy")) // .withHeader("Accept", equalTo("application/json")) // .withHeader("User-Agent", equalTo("Jakarta Commons-HttpClient/3.1")) .willReturn(aResponse() .withHeader("content-type", "application/json") .withStatus(200) .withBody("{"message":"Chevy car response body"}") ) ); String url = "http://localhost:8888/cars/Chevy";try { JSONObject response = HttpClient.httpGet(url, true); System.out.println("Response:" + response); } catch (Exception e) { logger.debug("Problem using HTTPRequestor to generate response: " + e.getMessage()); e.printStackTrace(); } // wireMockServer.stop(); // wireMockServer.shutdown(); } }

    相关Jar包:

  • 相关阅读:
    为什么 PCB 生产时推荐出 Gerber 给工厂?
    Fedora Redhat Centos 有什么区别和关系?
    【KiCad】 如何给元件给元件的管脚加上划线?
    MCU ADC 进入 PD 模式后出现错误的值?
    FastAdmin 生产环境升级注意
    EMC EMI 自行评估记录
    如何让你的 KiCad 在缩放时不眩晕?
    KiCad 5.1.0 正式版终于发布
    一次单片机 SFR 页引发的“事故”
    java基础之集合
  • 原文地址:https://www.cnblogs.com/mmzhang/p/8065638.html
Copyright © 2011-2022 走看看