Giter VIP home page Giter VIP logo

Comments (4)

mkotsur avatar mkotsur commented on May 18, 2024

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.

0x6e6562 avatar 0x6e6562 commented on May 18, 2024
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:

  1. Client -> Real Server -> Stubbed out SMS gateway
  2. 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.

mkotsur avatar mkotsur commented on May 18, 2024

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.

0x6e6562 avatar 0x6e6562 commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.