Testing REST API provider response without mock - spring-boot

Currently, I am working on a project on Spring Boot where we are integrating with external REST API. As part of our integration suite test, we are doing the mock test of the actual external API which executes as part of the CI/CD.
My question is in production it calls the actual API so, how we can do that in the test environment. I don't think we need to make the actual external provider call during multiple integration test which will load the external API, also at the same time would like to test with actual REST response from the service.
Any suggestions?

If the public API has a swagger description, you could use the Atlassian Pact Swagger Validator. I describe the workflow in this talk: https://www.youtube.com/watch?v=79GKBYSqMIo#t=39m10s

Another alternative would be to create a mock API for the external service. There are some free services like https://mockfirst.com, https://www.mockable.io/, etc. where you can do that.

Related

Start an embedded gRPC server while running integration tests with Springboot

I have built a Springboot application which has a gRPC server as one of its dependencies. While running the integration test, I am able to use embedded Kafka, embedd MySQL etc using TestContainers, but how can I create an embedded gRPC server while running my integration test suite?
I have the .proto contract definition file. I would use Wiremock to mock the request and responses to the gRPC server, but I am unable to start the embedded gRPC server yet.
It will be really great if I could find some help here.
Come to think of it, my question can be generalized to starting a generic embedded HTTP server in Springboot integration test, using TestContainers or otherwise.
I had a similar problem with IT testing Java gRPC service integrations, as using InProcessServer is quite cumbersome and quite hard to use when you need to return different responses for different tests. Also when using it you cannot really test your Stub beans and their configuration, since you can't pass InProcessServer host as a variable.
For this purpose I've created a gRPC Java mocking tool gRPC Mock. It has two integration modules - one for spring-boot and one for JUnit5. It follows a similar DSL type of structure to HTTP mocking service WireMock for creating the stubs. You can visit the GitHub page for some examples.

Spring integration testing for REST call of some other Service

I've been searching it on the net , but most of the examples i found have the returning logic of rest call within the same project , but what if you want to test a rest call of some other service which you are using it in your project(calling a REST api from a REST API)
is there any way to integrate this . Integration testing for a REST call which is of some external service
can the normal Integration testing approach could work in this case.
Have you considered using Spring Cloud Contract (http://cloud.spring.io/spring-cloud-contract/) ? It's a project design specifically for that purpose.
You have the producer of the API and its consumers. The idea of Spring Cloud Contract and Consumer Driven Contract approach is such, that the consumers suggest how the API of the producer should look like. They can prototype the API without writing any production code on the producer side. The prototyping takes place in a form of a "contract". It can be a Groovy or a YAML file (you can of course extend the framework). Processing of the contract results in a creation of a WireMock stub that the consumers can leverage in their integration tests. In other words, it's as if the producers would prepare a small, fake implementation of their code for testing perspective. So the consumers can run their integration tests against a stub of the producer side. The stub was generated from the contract. Let's say that the consumer X wants to use an API in such a way that if a GET request is sent to /foo it will respond with text bar. Then a stub that responds with a bar text, when hit at the /foo endpoint will be generated.
Now, the producers reuse the same contracts to generate tests to verify if their API meets the requirement of what's there in the contract. Remember the GET # /foo will respond with bar example? If the producer tries to build its project and doesn't have such an endpoint, its build will be broken. The Spring Cloud Contract framework generates the tests that assert whether the API is working the way it should. Only after the producer fixes the missing implementation will the build pass.
This is the consumer driven contract approach. You can also do the producer driven approach where the producer of the API just defines the contracts without communicating with the consumers how exactly each of them is using the API.
Valuables links:
Spring Cloud Contract page: http://cloud.spring.io/spring-cloud-contract/
Spring Cloud Contract workshops: http://cloud-samples.spring.io/spring-cloud-contract-samples/
Contract Tests in the Enterprise presentation: https://www.youtube.com/watch?v=ZyHG-VOzPZg
Why Contract Tests matter presentation: https://www.youtube.com/watch?v=TvpkZu1e2Dc
Note: I'm the maintainer of Spring Cloud Contract.

mimic swagger api on spring boot application

I got a Spring boot REST based proxy server application with standard REST End point exposed(GET, POST,PUT and DELETE) to outside world.
Any requests coming from external world then will be routed to actual functionality internally.
Now the requirement is to expose all the API supported by my REST proxy server. As I mentioned I do not have static controller path in my code for individual APIs. So would like to get your input how to create swagger support for all the internal APIs that my proxy server support. Is there are a way I can generate swagger schema manually to mimics the controller path? Or is there any other way to solve this problem?
Thanks in advance.

how to make spring mvc functions available for rest calls

I have a spring mvc application which runs correctly,now another colleague wants to call the same functions from another application but he needs REST URL of my functions.
how is it possible to provide the same functionality through spring REST?
is it just with new annotations .please provide some resource to show me how to do it.
when server has a service, only legal clients which had any contracts with server can access it. And clients can use service by the way such as: use RestTemplate to get/post request to URL of service, and clients can get data as JSON, or XML type if you have an equivalent object as this image:
Also, a service can be support as a interface, ex: google search is a service supported by google, but it's not rest service.
If you know each other URL address you can consume each other REST API from java code by using RestTemplate object.
I would advise you to go over the Spring starter guide which deals with that issue, here is the link (Consuming a RESTful Web Service):
https://spring.io/guides/gs/consuming-rest/

load testing using multithreading for a spring rest ful webservice

I had implemented a restful service. I want to do a load testing for spring rest ful service. In this i want to check how many users can access a service. How to do that..Please provide me some information.
There are a variety of tools out there you can use for load testing. I've found JMeter to be a pretty robust open source option. Specifically for REST requests you can use the HTTP Request component.
That said, I'd be curious to hear what others are using.

Resources