Closed rahulkanchi closed 7 years ago
That feature already exists if you use the initializationClass
property of the Maven plugin. This is also described at http://www.mock-server.com/mock_server/running_mock_server.html#maven_plugin. Even if you don't have a maven build it is possible to run the plugin standalone as follows:
mvn -Dmockserver.serverPort=1080 -Dmockserver.proxyPort=1090 -Dmockserver.logLevel=INFO -Dmockserver.initializationClass="org.mockserver.maven.ExampleInitializationClass" org.mock-server:mockserver-maven-plugin:3.10.4:runForked
In the example above I have assumed you have an initialisation class called org.mockserver.maven.ExampleInitializationClass.
Please consider the following scenario: Before my integration test starts, a docker-compose with the entire test environment is being started. It essentially contains all required services for the test. I want to use mock-server for mocking some services that I don't need during my test. The problem is that some of the services make a call to the "mocked" service during the startup, so it will fail since the mock-server still doesn't have expectations. It will be very convenient to have an ability to run mock-server in docker with predefined expectations from the file system, environment, etc.
Is there any workaround for the scenario described by @dimarassin ? I am running into the same situation.
This is already possible, see: http://mock-server.com/mock_server/initializing_expectations.html
If your using Kubernetes the documentation describes how to inject the expectation initialiser JSON file (or any other configuration) http://mock-server.com/where/kubernetes.html
Hi James, I tried your suggestion to run MockServer standalone to replace an API that is not up and running yet. I created a class in my Springboot project accroding to : https://mock-server.com/mock_server/initializing_expectations.html where I declare my pre-defined expecations.
Then I added a application-local.properties file mockserver.initializationClass=my.class.path.ExampleInitializationClass
Then I run below command like you suggested. mvn -Dmockserver.serverPort=1080 -Dmockserver.proxyPort=1090 -Dmockserver.logLevel=INFO -Dmockserver.initializationClass="my.class.path.ExampleInitializationClass" org.mock-server:mockserver-maven-plugin:3.10.4:runForked
But it complains it cannot find the ExpectationsInitializer, no matter what I try. I mockserver not meant to run as standalone to replace an API, and only for testing purposes?
Atm, standalone mockserver always starts up with empty expectations and we will have to setup expectations via java/Ruby/Javascript clients or via direct curl calls. This issue is raised to add a feature in standalone mockserver, that enables it to load a pre-defined set of expectations located in a configured folder. These expectations will be in json format and each file will have one expectation.