Comments (4)
Sorry, I didn't understand the use case completely. If you want to assert that the call happens only once, this is exactly what restito tells: "No, it happens 2 times.". Probably I am missing some more context about "protects against duplicate invocations of the downstream HTTP server".
But in any case, it's possible to reset the state simply by calling server.getCalls().clear()
. Feel free to reopen the issue if it doesn't solve your problem.
from restito.
server.getCalls().clear()
solved my issue, so thank you very much for this.
For anybody googling this, the use case is a client calling a server which in turn calls an SMS gateway to deliver a message. If the client submits a duplicate request to the server, the server should not send a request to the SMS gateway. So there are 2 client calls, but the second is a duplicate of the first:
- Client -> Real Server -> Stubbed out SMS gateway
- Client -> Real Server -> Call to SMS gateway should not occur
In this scenario I want to verify exactly one verification that the stub was invoked after the first client call but before the second. And then after the second I want to assert that stub was not invoked.
I could just run both client calls through and then assert after them both that the stub was only invoked once in total. This has some value and is simpler. But in this particular case I need the more fine grained verification that the first client call causes the stub to get invoked and not the second, rather than just asserting the any one of the client calls cause the stub to be invoked.
from restito.
Aha, now it's clear.
Assuming that you test the Real Server
, you stubbed the SMS gateway
and you have access to the client
in the test, I'd write the test like that:
whenHttp(server).doAllResponsesSetup();
client.doCall();
verifyHttp(server).once();
client.doCall();
verifyHttp(server).once(); // Will ensure that even after the second client action, the server has been called only once.
from restito.
Many thanks for this suggestion - I've now integrated this into my test suite and it makes things a lot clearer :-)
from restito.
Related Issues (20)
- Restito Certificate has expired for SSL HOT 5
- Stub and method toString() HOT 2
- Unable to specify keystore and truststore HOT 2
- Slow server response HOT 3
- Switch to Java8
- New 0.9.0 version does not automatically identity contentType if the XML or JSON file is too big HOT 3
- connection refused error. HOT 3
- resourceContent big files handling HOT 10
- Tests fail if I have multiple requests with the same values HOT 6
- Allow @NeedsServer for types as well
- Match uris that contains regex for http methods
- Remove requirement to specify path with per-HTTP-method methods. HOT 2
- Clarify methods that accept a "URI". HOT 1
- Severe encoding bug in Action.stringContent(String content). HOT 4
- Multiply headers in request HOT 2
- proposal: more readable stack trace for big JSON payload with restito integration testing HOT 1
- Composite conditions: log failling condition HOT 8
- [Important] Critical racing condition on Stub Server while registering the calls HOT 7
- Upgrade to Gradle 7 HOT 1
- Some tests fail on my machine: M1 MBP
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restito.