I am using wiremock for mocking the services. With WireMock Standlone jar i am able to run my mock api's by placing the .json files in __files folder.
But i would like to create a Java project for WireMock. WireMock Website provides snippets to get started. But i some how face challenges in basic project setup.
Here are the steps i followed
- Created a gradle project in intellij
Added gradle dependency for WireMock. Here is my build.gradle
dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' testCompile "com.github.tomakehurst:wiremock:2.17.0" }
3.Created a sample class with following code , taken this code from WireMock website
import com.github.tomakehurst.wiremock.WireMockServer;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static
com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
public class samplemock {
public static void main(String args[]){
WireMockServer wireMockServer = new WireMockServer(options().port(9999));
wireMockServer.start();
stubFor(get(urlEqualTo("/test"))
.willReturn(aResponse()
.withBody("Hello")));
}
}
But , on executing this code i am getting errors in my ide console
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/Resources
at com.github.tomakehurst.wiremock.core.WireMockConfiguration.<init>(WireMockConfiguration.java:58)
at com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig(WireMockConfiguration.java:104)
at com.github.tomakehurst.wiremock.core.WireMockConfiguration.options(WireMockConfiguration.java:108)
at com.tech.samplemock.main(samplemock.java:11)
Caused by: java.lang.ClassNotFoundException: com.google.common.io.Resources
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
Not sure why this error occured. And there is no any sample project available in java except some code snippets in WireMock. There is a sample web app provided here which is not much helpful in building plain old java wiremock framework.
Appreciate your support.
Thank you.