I have microservice based app, and I need to mock one of the service.
So when Im requesting one microservice http://service1/src it triggers another one by link lets say
http://service2/src
I cannot change this link to the mocked one but I want to start wiremock somehow and fake this link, so when I will send request to http://service1/src it will trigger http://service2/src but mocked one
Im able to setup wiremock but I cannot get it directly by link http://service2/src I need to add http://localhost:8080/http://service2/src
Or maybe you can advice some another framework for such purpose
thanks for helping in advance
Related
I am writing Spring Boot Integration test. For this, we boot up the empty application (context) and call multiple services as part of test.
One of the requirements is to call the external REST endpoint with payload that contains an URL to notify (call back) and that service, after some business logic, calls the URL received in the payload.
From the test, I can call the REST endpoint, which is external service. But I want to be able to test the call back from that service for the given URL. URL can be random.
Can I do with MockClientServer? OR MockRestServiceServer Or some other day to test this?
Essentially, I want the test to be able to get an external call and verify it.
After trying out a couple things, WireMock actually does what I wanted. It takes the rest call from outside application(s). Very useful for testing.
This question already has an answer here:
In Karate API mocking not working as expected for me
(1 answer)
Closed 1 year ago.
I have a question about external mocking server. My set up is:
I have an API which I want to test
The service internally calls Database , Gateways , payment aggregators whichs have their own URLS
I control the Mock URLS which I can call. But if it is internally initiated how can i mock it without changing my code?
For example I call service
I call Controller of paymentservice which I can mock
What about my controller call java module which makes a call to gateway
I want to mock that gateway not controller. I see all the examples of karate-netty and Proxy . Proxy tracks all the request after host:port but in my case the host will be real host and how proxy will track it ?
Looks like I tried so much but did not get any perfect solution
This is not a question regarding karate, because you want to make your code more testable.
Your controller that call other services have to know how to request service. I would expect that you have at leas some sort of configuration file where all the urls and other application properties are specified.
In more complex environment, I would expect some sort of service discovery with consul for instance.
The simplest thing you can do is to read a system or environment property in your controller to make the service url configurable.
Background
I'm writing a web service that makes calls to an external api. This api has not yet been put into production. As such, when I make a call to my web service in my dev environment, I want to stub out the responses that it returns. Note: this is not a unit testing question.
My Solution So Far
The api calls are made using RestTemplate from the lovely Spring people, the url of which is held in application.properties. This has allowed me to set different urls for different environments using Active Profiles. So, for example, application-dev.properties holds a different url.
The dev url is ideally a pointer to a json file under resources/.
My Issue
I can't seem to get RestTemplate to pick up the local json file. The url I'm using is:
url = "file://staticJson.json"
However that comes up with a
Object of class [sun.net.www.protocol.ftp.FtpURLConnection] must be an instance of class java.net.HttpURLConnection
And now I'm unsure of how to proceed, or if this is even possible without extending RestTemplate.
Any directions to try or solutions would be fantastic.
If any more information is required I'll do my best to provide it asap.
When mocking REST with Restito, is it possible to get some feedback when you mocked something incorrectly? I mean, if the request has already been sent to the stubserver from the implementation, couldn't it just record that request and present it for me?
Because sometimes it requires a lot of struggling to get the exact match of everything and it would be helpful to get some feedback when working with it.
You could set logging level to DEBUG and then you see all the requests to thestub server.
yesterday i started brainstorm for a project of mine and I'm not sure if its the correct approach.
On my website I'm having an (kind of an order form) which sends a post to a target URL, which works with a simple curl php script. The target is an external service (where I have no access no rights, nothing). I only know that I will get a POST with further processed data back from the service, which I have to save into my DB.
in steps:
Users fills out the (order) form and posts data to an external url on my website.
data gets externally handled and after finishing that resents a post.
read incoming post data.
save data into DB.
Success page on my website.
My thoughts were to handle the incoming data with a servlet (spring maven project) but I'm not sure if this is a correct approach. Is there a better why to do this. Or is the first step with the php scripts wrong. thx for any help.
A simplest workflow could be
1. Forward the initial (Order form with values) request to a servlet
2. Invoke a post request using java to an external url inside this servlet (Using Apache http client, or libraries such as HTMLUnit)
3. Once you get the incoming response in your servlet, you can update your database.
If you are using spring, the controller could forward initial request to a business class which will handle this post processing and delegate the database update to respective DAO.
There are a number of suitable ways to handle this, and the decision is largely a matter of preference and what you're familiar with. Spring can handle this sort of job quite well.
Note: Maven is a build system for Java and some other JVM languages. I recommend using it, but it's not part of Spring; what you're probably looking for is Spring MVC.