1

I´m developing a munit test but It is failing, because when it makes a call to another api, it is expecting a new Id, but for the test I cannot make several new Ids, as I understand this is a simulation, that´s why we use mock responses. But is weird, It is not returning the mock responses, instead, it returns the real responses, so it is always gonna fail.

        <munit:parameterizations file="postEndPoint/tests.yaml" />
    </munit:config>
    <munit:test name="post-test-suite" doc:id="deab786d-ee5b-4ba8-96d3-613d4e8de55e" description="Test" expectedErrorType="${errorType}">
        <munit:behavior >
            <munit-tools:mock-when doc:name="Mock when APIKIT" doc:id="5aa0b2d4-8552-493f-a03f-6b548f45562c" processor="apikit:router">
                <munit-tools:with-attributes >
                    <munit-tools:with-attribute whereValue="${routerConfig}" attributeName="config-ref" />
                </munit-tools:with-attributes>
                <munit-tools:then-call flow="${callFlow}" />
            </munit-tools:mock-when>
            <munit-tools:mock-when doc:name="Call Product Sys API" doc:id="e89e50c0-2a20-4ca3-a32b-c715b1f2adcc" processor="${processorOne}">
                <munit-tools:with-attributes >
                    <munit-tools:with-attribute whereValue="${valueName1}" attributeName="doc:name" />
                    <munit-tools:with-attribute whereValue="${valueId1}" attributeName="doc:id" />
                </munit-tools:with-attributes>
                <munit-tools:then-return >
                    <munit-tools:variables >
                        <munit-tools:variable key="productResponse" value="#[output application/json --- readUrl(p('mockResponse1'),&quot;application/json&quot;)]" mediaType="application/json" />
                    </munit-tools:variables>
                </munit-tools:then-return>
            </munit-tools:mock-when>
            <munit-tools:mock-when doc:name="Call Entitlement sys API" doc:id="6e6964c3-72c4-4d3f-86e9-d0734fb706cf" processor="${processorOne}">
                <munit-tools:with-attributes >
                    <munit-tools:with-attribute whereValue="${valueName2}" attributeName="doc:name" />
                    <munit-tools:with-attribute whereValue="${valueId2}" attributeName="doc:id" />
                </munit-tools:with-attributes>
                <munit-tools:then-return >
                    <munit-tools:payload value="#[output application/json --- readUrl(p('mockResponse2'),&quot;application/json&quot;)]" />
                    <munit-tools:error typeId="${errorType}" />
                    <munit-tools:variables >
                        <munit-tools:variable key="updateEntitlementResponse" value="#[output application/json --- readUrl(p('mockResponse2'),&quot;application/json&quot;)]" />
            
Itzel Moo
  • 11
  • 2
  • 1
    Which of these MUnits are failing? Can you remove the other MUnit and only share the failing one? Also share the xml of the processor that is not getting mocked – Harshank Bansal Jul 13 '23 at 02:40
  • 1
    Also what are the values of the property placeholders? Please provide a minimal reproducible example https://stackoverflow.com/help/minimal-reproducible-example – aled Jul 13 '23 at 03:21
  • The code is a test suite, so all single munits are failing... – Itzel Moo Jul 13 '23 at 04:05
  • the processor is an apikit:router – Itzel Moo Jul 13 '23 at 04:06
  • Also it would be super helpful if you tell me how to call external apis without actually call them, I mean just make the simulation – Itzel Moo Jul 13 '23 at 04:25
  • As I said before, create a minimum reproducible example of the issue, focusing in one mock, one test and the minimum flow to reproduce. Then share the details here. Saying something like 'all test fail using APIKit' doesn't provide any details to look at, so no one can help you. Read [How to Ask page](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) in the Help Center of Stack Overflow to understand how to help others to help you. – aled Jul 13 '23 at 17:29

1 Answers1

1

I don't usually see property placeholders used for processor attribute of a mock. I also avoid using doc:id or doc:name for the attributeName property of with-attribute.

You will have better luck matching a mock to a processor by using the static value of the element you want to match for processor and a static value for the attribute you want to match on in the with-attribute element. Also, try to use a fundamental quality of the processor you want to match like config-ref and something like path if you're mocking an HTTP request.

Ryan Hoegg
  • 2,415
  • 2
  • 14
  • 15