Questions tagged [mockserver]

What is MockServer

MockServer can be used for mocking any system you integrate with via HTTP or HTTPS (i.e. services, web sites, etc).

MockServer can:

  • return a "mock" response when a request matches an expectation

  • forward a request when the request matches an expectation (i.e. a dynamic port forwarding proxy)

  • execute a callback when a request matches an expectation, allowing the response to be created dynamically

  • verify requests have been sent (i.e. as a test assertion)

What is MockServer Proxy

MockServer Proxy can be used for transparently recording all requests sent by a system (i.e. an application or set of applications).

MockServer Proxy can:

  • proxy all requests using any of the following proxying methods:

    • Port Forwarding
    • Web Proxying (i.e. HTTP proxy)
    • HTTPS Tunneling Proxying (using HTTP CONNECT)
    • SOCKS Proxying (i.e. dynamic port forwarding)
  • verify requests have been sent (i.e. in a test assertion)
  • record requests and responses to analyse how a system behaves
175 questions
17
votes
4 answers

How to test a RestClientException with MockRestServiceServer

While testing a RestClient-Implementation I want to simulate a RestClientException that may be thrown by some RestTemplate-methods in that implementation f.e. the delete-method: @Override public ResponseEntity documentDelete(String…
JMarky
  • 289
  • 2
  • 3
  • 8
14
votes
2 answers

Difference between WireMockServer vs MockServerClient

I am trying to understand what is the difference between two frameworks which are MockServerClient( or org.mockserver.integration.ClientAndServer) and WireMockServer?Can they be exchanged? I read the docs. but could not figure out what is the…
James
  • 441
  • 2
  • 6
  • 9
10
votes
1 answer

Spring MockRestServiceServer handling multiple Async requests

I have an orchestrator spring boot service that makes several async rest requests to external services and I would like to mock the responses of those services. My code is: mockServer.expect(requestTo("http://localhost/retrieveBook/book1")) …
Endika
  • 347
  • 2
  • 5
  • 20
9
votes
1 answer

How to expect requestTo by String pattern in MockRestServiceServer?

I have tests with: org.springframework.test.web.client.MockRestServiceServer mockServer When I run with any(String.class) or exact URL they work…
Justinas Jakavonis
  • 8,220
  • 10
  • 69
  • 114
6
votes
5 answers

How do I view a request coming into my Postman mock server?

My website is making post requests to Postman's mock server. I want to be able to see my request to make sure that it is coming across in the way that I expect. I have tried attaching a monitor but that doesn't show me the request anywhere that I am…
BrettARose
  • 434
  • 3
  • 12
6
votes
3 answers

How to match request parameters in wire-mock url?

I'm trying to create a mock server using wire-mock and I'm facing the following problem: I want to hit an URL like this /customers?customerId={customerId}&customerNo={customerNo}. My question is how can I match the request parameters customerId and…
Dina Bogdan
  • 4,345
  • 5
  • 27
  • 56
5
votes
3 answers

Start MockServer during spring-boot:run

We have some APIs we use in our application that are not accessible from local developer machines due to firewalls. I want to use mockServer to mock some of these API so we can develop locally. When running tests mockServer can be started and…
Chris Gunawardena
  • 6,246
  • 1
  • 29
  • 45
5
votes
1 answer

How to use WireMock.Net in a Xamarin.UITest project?

My UITest project works well with original web server, but I want to replace it with mock server using WireMock.net. I already used it in a non-UITest project successfully. Here's my code in UI Test project: [SetUp] public void…
VahidShir
  • 2,066
  • 2
  • 17
  • 27
5
votes
2 answers

Okhttp mock server is not working on API 28 and above simulator

My mock server dispatcher never reaches the override method on simulator runs API 28 and above but it works fine on the other version. Any idea how to trigger it? Or is it just the API version issue? I'm pointing to localhost:8080. And the okhttp…
Allen
  • 2,979
  • 1
  • 29
  • 34
5
votes
1 answer

How to set default response (example) in Postman

I have setup a mock server in Postman. For a request X, I have added 2 examples (responses) 200 Success Response 400 Bad request When I use x-mock-response-code I am able to get the appropriate response. But when I dont use the…
renjuwm
  • 81
  • 6
5
votes
2 answers

MockServer: IllegalArgumentException when parsing JSON

When i'm trying to mock external HTTP API with MockServer, mockserver returns java.lang.IllegalArgumentException This is the test code: new MockServerClient("localhost", 1080) .when(request("/messages") .withMethod("POST") …
Igor
  • 478
  • 9
  • 22
4
votes
2 answers

How to set up different responses for the same request to MockServer?

i'm having an issue when setting up the MockServerClient for multiple responses with the exact same request. I read that with expectations with "Times" this might be done, but i coulnd't make it work with my scenario. If you call the service with…
Gabriel Vitale
  • 163
  • 1
  • 3
  • 10
4
votes
0 answers

SocketConnectionException: Channel set as inactive before valid response has been received

I receive following exception when running a local mock server in eclipse and trying to connect with a client: org.mockserver.client.SocketConnectionException: Channel set as inactive before valid response has been received at …
AndiCover
  • 1,724
  • 3
  • 17
  • 38
4
votes
1 answer

Postman Mock server route params

there is a problem in using postman mock server. It does not respond to the requests that have route parameters. For example, My uri looks like this: PUT : {{server_url}}/order/{id} But when I call mock server in this…
Majid Akbari
  • 190
  • 2
  • 10
4
votes
1 answer

Write unit test for okhttp timeout

I have written test case for okHttp SocketTimeoutException like this: @Test public void contactDetailsTimeOut() throws Exception { server.enqueue(new MockResponse().setBody("{}").setBodyDelay(31, TimeUnit.SECONDS)); HttpUrl baseUrl…
Anand Singh
  • 5,672
  • 2
  • 23
  • 33
1
2 3
11 12