'Munit 4: Is there a way to mock a payload from the same cache-scoped HTTP Request in different test cases for a suite?

I am trying to Mock a response payload from HTTP request like this:

        <munit-tools:mock-when doc:name="doc-name"
            doc:id="doc-id" processor="http:request">
            <munit-tools:with-attributes>
                <munit-tools:with-attribute
                    attributeName="doc:name" whereValue="#['DOCNAME']" />
            </munit-tools:with-attributes>
            <munit-tools:then-return>
                <munit-tools:payload mediaType="application/json"
                    value="#[MunitTools::getResourceAsString('testPayloadA.json')]" />
            </munit-tools:then-return>
        </munit-tools:mock-when>

Then in another test case, I mock the same HTTP request like this:

        <munit-tools:mock-when doc:name="doc-name"
            doc:id="doc-id" processor="http:request">
            <munit-tools:with-attributes>
                <munit-tools:with-attribute
                    attributeName="doc:name" whereValue="#['DOCNAME']" />
            </munit-tools:with-attributes>
            <munit-tools:then-return>
                <munit-tools:payload mediaType="application/json"
                    value="#[MunitTools::getResourceAsString('testPayloadB.json')]" />
            </munit-tools:then-return>
        </munit-tools:mock-when>

Basically the mock has the same structure for at least 4 cases where I am trying to evaluate the behavior that varies depending on the content of the payload that comes from the Http Request with name DOCNAME. The fact is that this request is enclosed in a Cache scope. This means that if I try to run the test cases individually, they will do it successfully, but when all the suite is run, the first case executes OK but the subsequent ones fail.

Does anyone have an idea about how a response payload from a cache-scoped request should be mocked in a way that does not affect all the test suite?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source