Questions tagged [mockrestserviceserver]

22 questions
11
votes
4 answers

How can I unit-test javanica @HystrixCommand annotated methods?

I am using javanica and annotating my hystrix command methods like this: @HystrixCommand(groupKey="MY_GROUP", commandKey="MY_COMMAND" fallbackMethod="fallbackMethod") public Object getSomething(Object request) { .... And I am trying to unit tests…
Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
9
votes
1 answer

Spring boot testing of a rest client using @RestClientTest

I am using spring boot 1.5.8 and want to test my client: @Component public class RestClientBean implements RestClient { private Map restTemplates = new HashMap<>(); @Autowired public RestClientBean(RestTemplateBuilder…
radio
  • 897
  • 2
  • 10
  • 25
8
votes
2 answers

How to mock multiple responses for same request using spring's MockRestServiceServer?

Im using MockRestServiceServer for mocking http responses. In a specific scenario i call an endpoint two times and want a different response the second time. But when i write a second expectation it's like it overwrites my first expectation. How…
5
votes
2 answers

MockRestServiceServer how to verify only request path exlcuding query string

I have a @Component DataClientImpl that calls a REST API using RestTemplate. The API endpoint has query params, which are passed when calling RestTemplate. There is a @RestClientTest Test class DataApiClientImplTest testing the DataClientImpl,…
5
votes
1 answer

Parsing an exception instead of List of entities is not working, when using TestRestTemplate and MockRestServiceServer

I have a simple controller (CODE) @RestController @RequestMapping("/profiles" , produces = [MediaType.APPLICATION_JSON_VALUE]) class Controller(@Autowired val restClient: RestClient) { @GetMapping("/simple-get") fun simpleGetCall():…
Joergi
  • 1,527
  • 3
  • 39
  • 82
2
votes
1 answer

mockServer andExpect(content().XML with current date concatenated

I am getting an Assertion error " Body Content Expected child but was null when asserting the andExpect XML. If I input as as a String "2020-10-01-5:00" it works fine but if I concatenate the date into a string like: LocalDate startDate =…
2
votes
1 answer

Is there a ready-made class to capture request body in MockRestServiceServer for logging etc.?

I will answer my question myself, but I am not happy with my solution, so if there is a ready-made convenience class/method doing the same, let me know. Problem statement I am using Spring MockRestServiceServer in unit tests to mock a REST service…
Honza Zidek
  • 9,204
  • 4
  • 72
  • 118
2
votes
2 answers

How to Mock StreamingResponseBody in Testing?

In my production code I need to execute POST command to a controller which response StreamingResponseBody. A short example of such code is : @RestController @RequestMapping("/api") public class DalaLakeRealController { @PostMapping(value =…
Ida Amit
  • 1,411
  • 2
  • 13
  • 27
2
votes
1 answer

Mock Rest Server Response for Unit Testing

In integration testing, I use a real remote server to consume REST APIs. What's the simplest way to provide those responses within a unit test w/o depending on external entity. One possible approach is to build public class TestHttpResponse…
Rockoder
  • 746
  • 2
  • 11
  • 22
2
votes
3 answers

How to mock RestTemplate with MockRestServiceServer?

@RunWith(MockitoJUnitRunner.class) public class FeatureFlipperManagerTest { @Autowired RestTemplate restTemplate = new RestTemplate(); @Autowired Service service = new Service(); MockRestServiceServer mockServer =…
c2340878
  • 389
  • 1
  • 4
  • 12
1
vote
0 answers

How can I mock rest client from external library in spring boot tests?

I tried to use MockRestServiceServer to mock rest client from external library but it doesn't work because tested code instantiate its own RestTemplate internally and I don't have access to it. It seems like MockRestServiceServer only work if the…
1
vote
0 answers

MockRestServiceServer.verify() is failed when the test did not mock all of API in the project

My project have 2 APIs and I want to separate test for each API. So I am trying to use MockRestServiceServer to mock my API but MockRestServiceServer requires all of API that I have in my project have to mock even it does not need. My spring boot…
1
vote
1 answer

MockRestServiceServer seeing request from previous test

I am running JUnit5 with MockRestServiceServer and seeing that when I run multiple tests with async requests, the MockRestServiceServer in test A will see a request from test B and flag as unexpected. @SpringBootTest(webEnvironment =…
C Taylor
  • 117
  • 1
  • 9
1
vote
1 answer

Is there a way to specify only one MockResponse be returned in a SoapUI Mock REST Server?

Newbie to SoapUI. I am trying to set up a mock REST server to do some testing. I can see that you can dispatch MockResponses either in a "SEQUENCE" or using a "SCRIPT". I may have many different responses set up depending on my test cases, but I…
GregH
  • 12,278
  • 23
  • 73
  • 109
0
votes
0 answers

Mock Servers which can support both GraphQL and REST endpoints?

I'm trying to find some mock servers which can support both graphQL and REST endpoints . so that when I query, it returns back mock data instead of going to the Graphql / Http server. At the moment I found some ways to mock queries ,…
1
2