Mock external http requests in grails - unit-testing

I am using RestBuilder (LINK) for making REST calls to outer services.
Now I want to mock that http requests for unit testing (or integration testing, whatever) service that handles all logic about communication with that outer services.
Does anyone know how to mock http requests or this RestBuilder maybe?
Thanks for any help!
Ivan

This kind of test is called «functional test». There are many plugins that can help you with this task:
http://www.grails.org/plugin/functional-test
http://www.grails.org/plugins/tag/functional

Related

How to mock client inside paymentintent for Stripe?

Currently we are using paymentintent.New() method to create a payment intent for stripe but the issue we are facing is in writing unit tests (for integration test, we are already aware of stripe-mock)
Inside this method, a http client is created internally. Not sure how can we mock it.
https://github.com/stripe/stripe-go/blob/master/paymentintent/client.go#L24
We have tried generating the mock of stripe http client by ourselves but that won't help much since paymentintent internally creates a HTTP client and we don't see a way to pass our own http client inside the paymentintent method
stripe-go is using stripe-mock internally for unit testing. You can see this piece of code to learn how to set a mock server for you unit tests.

SoapUI: Create mock service with pass-through behavior for selected methods

While developing a web application I have the following use case:
a 3rd party Web Service with quite a lot of methods is deployed on a test server A (with a single endpoint, e.g. http://3rdPartyServer/3rdPartySvc?WSDL)
a new method is about to be implemented in the near future, but I need to use it now
the rest of the methods are used throughout my code extensively
So I would like to do the following:
Create a mock service in SoapUI locally, based on the new WSDL which includes the new WS method (i.e. a superset of the WS methods currently on server A)
point my local application server to use the SoapUI mock service endpoint
mock only the response of the new WS method (create a dummy response for it in SoapUI)
let the other WS method calls to reach server A and return whatever it returns normally (i.e. use SoapUI as a proxy for these calls)
I've gone through the SoapUI documentation regarding service mocking and have used it numerous times, but could not find an option for such "pass-through" behavior.
When you read in your WSDL, the endpoint will point to your server.
Open your service, and select the service endpoint.
Add a second endpoint, to point to your mock. SoapUI has little bit of documentation showing this here. Only step "2. Getting Started" applies, not step 3!
In each of your tests, where you are using the mocked method, you will need to select the mock endpoint. Further discussion is here.

JUnit: Mocking a http server

I have a service that has a method that makes a rest call using apache httpclient. I want to test the call using junit but i do not want to mock out the call but mock out the server that it is making the call to
My question is, is it possible to mock out a server using something like mockwebserver so that if you make a request to a specific url that this will be picked up from the service (without mocking the service) rather then going off to the real server?
HttpClient is an interface so you can return a mock in your tests.
Try Jadler (http://jadler.net), an open source library for creating stub/mock http servers. It should provide you everything you need (I'm one of its developers).

Automated testing of a SOAP Service

Before just answering: Use SoapUI. Please read the Question, because I tried SoapUI.
I have a lot big wsdl Files. Every Method works like this:
First do a synchronous Call:
Request: Please do foo and send Request to URI: XY
Response: Ok, your Job has UUID: abc
After the Job is done, my Sevice will respond to URI: XY, by sending only a request Message synchronously:
Request: Ok I finished your Job with the UUID: abc and the result is bar
We needed to use this behavior, because we have a pool where all answers will be stored and are identified by UUID.
Do you know a possibility to test such a SOAP Service?
I tried:
SOAP UI
BPEL Unit (I think it should be possible with BPEL Unit but I can't make it work properly)
Please don't recommend writing my own JAVA tests, because I have more than 100 methods to test.
Also the Tests need to be run and the results need to be analyzed automatically in a Test-suite, I can't do this for 100 Methods by hand everytime I change the code of the Web Service.
I'm one of the SoapUI Guys, so you'll probably HATE my answer...
But the solution is using SoapUI; more specifically using MockResponse TestSteps. SoapUI is NOT very strong when it comes to BPEL testing, but using MockResponse Steps you can fix it.
Look here: http://www.soapui.org/SOAP-and-WSDL/testing-asynchronous-services.html. Even though all calls are done synchronously, this can still be considered asynch testing since we have more than plain request/response.
I also know that Oracle has got a great write up on this.
What you need to do is to create a mock service that will receive the second call which signals that the job processing is done. This is can be done in SOAP UI, you can read about how to create a mock web-service here.
You can test Web Services by using Eclipse.
Just put the WSDL file on your project -> right click on the file -> web services -> test using web service explorer.
You will have an interface showing all your WSDL operations and fields which are needed.

Asynchronous Webservice

I wanted to clear something about Asynchronous Webservices.
I read that weblogic give you the ability to create Asynchronous Webservices.
but I also read that it's only supported as log as the client and the server of the webservice both working under Weblogic container.
Is that true?
is it possible to create Asynchronous Webservices without having the need to have the same system(weblogic, jboss) both at client adn server side?
In case it's possible I would like to get details how is it working..
thanks,
ray.
Neither WS-Addressing nor Weblogic have anything to do with enabling async services. See the Asynchronous Client documentation for JAX-WS. There are two basic approaches supported: Static stubs and the Dispatch API. Static stubs require the use of customizations and will result in additional methods being added to the service endpoint interface. These methods expose both polling and callback functionality for async invocation.
I understood that I can invoke async webservice as long as both the server and the client supports: WS-Addressing specification.
ray.