Hi,
I am just having WireMock up and running. Problem is that the mocked requests seems not used in the code under test.
My setup is:
WireMockConfiguration config = wireMockConfig().port(9089).httpsPort(8443);
m_wireMockServer = new WireMockServer(config);
m_wireMockServer.start();
WireMock.configureFor("localhost", 9089);
My test code is:
String downloadUrl = "https://downloadLocation.com";
givenThat(get(urlMatching(".*"))
.willReturn(aResponse()
.withStatus(401)));
OneDriveItem item = new OneDriveItem("id");
item.setDownloadUrl(downloadUrl);
myService.getStreamForFileDownload(m_idOfTestUser, item); The code under test is ran no further than:
public InputStream getStreamForFileDownload(UUID userId, OneDriveItem file) throws NotAuthorizedException {
HttpGet httpGet = new HttpGet(file.getDownloadUrl());
httpGet.setHeader("Authorization", "Bearer " + getAccessToken(userId));
try {
HttpResponse response = HttpClients.createDefault().execute(httpGet); //this line causes exception
The last line throws an exception because downloadLocation does not exist:
java.net.UnknownHostException: downloadLocation.com: nodename nor servname provided, or not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
at java.net.InetAddress.getAllByName0(InetAddress.java:1246)
at java.net.InetAddress.getAllByName(InetAddress.java:1162)
at java.net.InetAddress.getAllByName(InetAddress.java:1098)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:111)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at getStreamForFileDownload(OneDriveServiceImpl.java:178)
If I put a breakpoint right after the last method call in the test code and look at
http://localhost:9089/__admin/ I see that the mapping is stored successfully:
{
"mappings" : [ {
"request" : {
"urlPattern" : ".*",
"method" : "GET"
},
"response" : {
"status" : 401
}
} ]
}
but looking at
http://localhost:9089/__admin/requests/find I find an empty page and it seems that no requests are handled by WireMock (and in that case the imaginary url is not found off course). Is there some configuration I missed?
Thanks in advance