I just wanted to know can we run wiremock on local...
# wiremock-java
m
I just wanted to know can we run wiremock on local machine instead of running it on a server. currently we are running wiremocks to automate different security tools on jenkins server. but we are not able to run the same setup on our local machine.
r
You'll need a JRE installed, but then you should just be able to follow this: https://wiremock.org/docs/running-standalone/
m
can the same code work on both jenkins as well as local?
r
I don't really understand the question - in principal yes? But it depends what code you mean.
m
I mean the code I used for running it on jenkins can the same code be used to run it on local?? or do I need some changes
Copy code
org.eclipse.jetty.util.log.StdErrLog logger = new org.eclipse.jetty.util.log.StdErrLog();
        logger.setLevel(org.eclipse.jetty.util.log.StdErrLog.LEVEL_OFF);
        org.eclipse.jetty.util.log.Log.setLog(logger);

        wireMockServer = new WireMockServer(options().usingFilesUnderDirectory(getDirectoryLocation(toolName)).port(randomWiremockPort())); //No-args constructor will start on port 8080, no HTTPS 
       wireMockServer.start();
r
Yes, you can run that code locally. I think most people run tests that start and stop WireMock locally.
m
ok thanks
and what will be the api endpoint when running locally. we also run that using ssh where the endpoint is the server IP and when we run on jenkins the endpoint is the jenkins endpoint, but what will be the endpoint when we run on local?
r
It will be
<http://localhost>:<random_port>
because you are using
.port(randomWiremockPort())
- I think
randomWiremockPort()
must be your own logic, it's not a WireMock function.
The WireMock equivalent is
options().dynamicPort()
. You can get the port from WireMock -
wireMockServer.port()
will return it so you can print it.
Are you able to share more details about the use case? We'd love to go on a short call to understand what you are doing.
m
we use it to test the security tools that are integrated into our platform, our test cases run fine on Jenkins but somehow not able to run on http://localhost:<random_port>.