简体   繁体   English

通过JUNIT在远程Unix服务器上以编程方式运行WireMock

[英]Programmatically Run WireMock on a remote Unix Server from JUNIT

First of all would like to Thanks WireMock team for amazing mock solution which is simple to use and integrate. 首先,感谢WireMock团队提供了易于使用和集成的惊人的模拟解决方案。

http://wiremock.org/docs/ http://wiremock.org/docs/

I had a specific issue. 我有一个特定的问题。 I am running WireMock Like below in my Junit Tests on my local machine. 我在本地计算机上的Junit测试中像下面那样运行WireMock。 When WireMock starts it runs on 8089 port as below and I can browse the URL through the below link which is perfect. 当WireMock启动时,它将在如下所示的8089端口上运行,我可以通过下面的链接浏览URL,这是完美的。

http://localhost:8099/xx/xx/invoice/201628JP00006097 http:// localhost:8099 / xx / xx / invoice / 201628JP00006097

@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().httpsPort(8089));

wireMockRule.stubFor(get(urlEqualTo("/xx/larxxs/invoice/201627JP00006087"))
        .willReturn(aResponse().withHeader("Content-Type", "text/xml").withBodyFile("K000006087.xml")));

After hosting this mock on my local machine, I run some batch job on a remote UNIX Server. 在本地计算机上托管此模拟之后,我在远程UNIX服务器上运行了一些批处理作业。 The batch job then tries to fetch this data from mock via https link and it used to work fine. 然后,批处理作业尝试通过https链接从模拟中获取此数据,并且过去可以正常工作。 Now there have been some changes on Remote UNIX Server or I am not sure what has changed overnight as the remote UNIX Machine is throwing error while trying to get data from WireMock. 现在,远程UNIX服务器上进行了一些更改,或者我不确定在一夜之间发生了什么更改,因为远程UNIX计算机在尝试从WireMock获取数据时抛出错误。 Though the ping is working from my machine to remove UNIX Machine and vice versa and I am able to get data via browser on my localhost. 尽管ping是从我的机器上删除UNIX机器的过程,反之亦然,但是我可以通过本地主机上的浏览器获取数据。

2016-08-03 17:31:50.101 ERROR 19483 --- [main] .w.s.l.s.b.t.OldLarsRestInvoiceGenerator : Exception while getting invoice data from Cybill rest serviceorg.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://10.10.34.238:8089/xx/xx/invoice/201627JP00006087": Connection timed out; nested exception is java.net.ConnectException: Connection timed out

I wanted to ask, if we can run WireMock programmatically from Junit on Remote UNIX Machine and how we can do that. 我想问一下,是否可以在远程UNIX计算机上从Junit中以编程方式运行WireMock,以及如何做到这一点。 Like in @Rule I mentioned it to run on port 8089. Can I mention the host also here. 就像在@Rule中一样,我提到它可以在端口8089上运行。在这里我也可以提及主机。

I saw that we can install Jar file on remote server and then run it, but is there a way to do it programmatically and start the wireMock on remote server instead. 我看到我们可以在远程服务器上安装Jar文件,然后运行它,但是有一种方法可以通过编程方式来执行,然后在远程服务器上启动wireMock。

@Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig() .httpsPort(8089) .host(myUNIXSERVER)); @Rule public WireMockRule wireMockRule =新的WireMockRule(wireMockConfig().httpsPort(8089).host(myUNIXSERVER));

Thanks for help!! 感谢帮助!!

I think you should try below 我认为您应该尝试以下

public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8089));

just cuz now you are mocking https:// and using https:// 只是因为现在您在嘲笑https://并使用https://

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM