WireMock not used by requests under test

1,729 views
Skip to first unread message

Jos Roseboom

unread,
May 8, 2015, 8:58:53 AM5/8/15
to wiremo...@googlegroups.com
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




Tom Akehurst

unread,
May 15, 2015, 12:30:11 PM5/15/15
to wiremo...@googlegroups.com, josro...@gmail.com
Given that you seem to be accessing a domain that isn't localhost, how were you expecting your code to be able to route a request to WireMock? Do you have some DNS or hostfile config for this?

Jos Roseboom

unread,
May 18, 2015, 10:43:01 AM5/18/15
to wiremo...@googlegroups.com, josro...@gmail.com
Thanks for your response, it points to my misunderstanding, as I was expecting WireMock to do such a routing.

Op vrijdag 15 mei 2015 18:30:11 UTC+2 schreef Tom Akehurst:
Reply all
Reply to author
Forward
0 new messages