Eolinker provides comprehensive support for mock apis. Other mock Servers that require installation and configuration are not mentioned, so why build your own mock Server?

The Api information is as follows. You can remove the root path from the URL and write the Api address directly. Configure the address prefix of the online environment and the test environment in the project. Just switch.


In the API edit page, Advanced Mock, enter the rules for the mock. Eolinker mock is based on the mockjs to change, but the same rules, rules can refer to http://mockjs.com/examples.html here




After editing, go back to the API details page and you’ll see a URL under the mock tag. Just copy it into the project. Because the address prefix is uniform, you can configure a unified test prefix in the project as just described, and change it to the production environment prefix when it goes online. Restful support is nice. Seems to be the only mock Server I’ve seen so far that supports restful?




When used in the project, it looks like this (just write a simple demo) :

[java]
view plain
copy

  1. public class MockServerTest {
  2. @Test
  3. public void testMockServer() throws IOException {
  4. mockClient.when(
  5. request()
  6. .withPath(“http://mock.eolinker.com/TPivSvI55cabdf9f2243a023dc6a76ec9514dc38084c19d?uri=/bestedu/course/primarySchool”)
  7. .withMethod(“POST”)
  8. // .withHeader(new Header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN))
  9. // .withQueryStringParameter(new Parameter(“my-token”, “12345”))
  10. ).respond(
  11. response()
  12. .withStatusCode(200)
  13. .withBody(expected)
  14. );
  15. CloseableHttpClient client = HttpClients.createDefault();
  16. HttpGet httpGet = new HttpPost(“http://mock.eolinker.com/TPivSvI55cabdf9f2243a023dc6a76ec9514dc38084c19d?uri=/bestedu/course/primarySchool”);
  17. CloseableHttpResponse response = client.execute(httpGet);
  18. // Verify that the output is correct
  19. InputStream content = response.getEntity().getContent();
  20. InputStreamReader inputStreamReader = new InputStreamReader(content);
  21. BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
  22. String responseText = bufferedReader.readLine();
  23. assertThat(responseText, equalTo(expected));
  24. }
  25. }

In addition to returning mock data, eolinker also validates the request method and parameters, and prompts if something is wrong, which is cool. But, the verification of mock is only available in the enterprise version, hoping that the technical boss can approve it by then.


Conclusion:

Do not repeat the wheel, now a lot of people advocate their own to do a set of services ah what, research is still ok, really work or simple and rough hand with the best. Besides, remote working is being promoted now, and Eolinker is doing ok in this area.