This Spring based project contains code to demonstrate the use of Embedded Wiremock with configuration for recording mapping files from both HTTP and HTTPS target URLs and setting up appropriate keystores and truststores to establish what SSL certificate is seen when accessing the URL through wiremock and also what SSL certificates can be trusted by the wiremock server.
This code in this project provides a WAR file that can be deployed into a Apache Tomcat Server. The WAR file when deployed, programmatically starts wiremock server, and starts recording mode targeting a HTTP URL first, and calls this HTTP endpoint through Wiremock server, using RestAssured framework, in order to automatically generate the mapping files for the HTTP endpoint. The code then stops recording mode for the HTTP endpoint and resets the wiremock cache in order to move on to recording mapping files for a HTTPS URL. This HTTPS URL will be called through Wiremock server, using RestAssured framework configured with truststores and also Oauth 2 authentication.
- Microsoft Windows
- Oracle Java JDK 8 - https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- Apache Tomcat 9 - http://tomcat.apache.org/
- Microsoft Windows
- Git - https://git-scm.com/
- Eclipse IDE - https://www.eclipse.org/ide/
- Apache Maven 3 - https://maven.apache.org/
- Oracle Java JDK 8 - https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- RestAssured - http://rest-assured.io/
- Apache HTTP client - https://hc.apache.org/httpcomponents-client-ga/
- Apache Commons IO - https://commons.apache.org/proper/commons-io/
- JSON in Java - https://github.com/stleary/JSON-java
- Wiremock - https://github.com/tomakehurst/wiremock
- Spring Boot - https://github.com/spring-projects/spring-boot
- Go to the Oracle website to download the JDK. At time of writing instructions were available here on the Oracle website: https://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_jdk_install.html#CHDEBCCJ
- Set the
JAVA_HOME
environment variable to point to the folder the JDK was installed at. For example in Windows running the commandecho %JAVAHOME%
may returnC:\Program Files\Java\jdk1.8.0_191
- Steps to download Apache Maven may be found here: https://maven.apache.org/download.cgi
- Steps to install Apache Maven may be found here: https://maven.apache.org/install.html
- Latest version of Eclipse may be downloaded here: http://www.eclipse.org/downloads/packages/
- Steps to install Eclipse may be followed here: https://wiki.eclipse.org/Eclipse/Installation
- Configure Eclipse to use JDK 8 as an Installed JRE - https://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-add_new_jre.htm
- Configure Eclipse to use above external Maven installation - in Eclipse go to Window > Preferences > Maven > Installations to see this
- Ensure Git bash is installed - https://gitforwindows.org/
- Download the source code of this repository using Git bash - https://help.github.com/articles/cloning-a-repository/#platform-windows
- Run the following command to build maven project. The –U option update the local maven repository with newest versions from remote maven repositories.
mvn clean install -U
- A target folder will be created if not already existing and a WAR file named WireMockSprintBootDemo.war will be generated.