0

I have a simple API from a WSO2 tutorial and am trying to run a unit test on the integration studio using the embedded micro integrator server.

The assertEquals fails with the following error. But when I use curl I get the expected response. What does the error message mean below? Seems like no response is received or there is something wrong with $body.

[INFO] Failed Assertion(s): 
[INFO] +--------------------------------------------+-------------------------------+------------------------------------------------------------------------------------------------------+
[INFO] |   TEST CASE                                |   ASSERT EXPRESSION           |       FAILURE                                                                                        |
[INFO] +============================================+===============================+======================================================================================================+
[INFO] | Test Case - querydoctorCategoryTestSuccess | assertEquals -                | Actual Response:                                                                                     |
[INFO] |                                            |                         $body | Received assert expression:                                                                          |
[INFO] |                                            |                               |                         $body                                                                        |
[INFO] |                                            |                               |                      is not a valid operation type for services                                      |
[INFO] |                                            |                               |                                                                                                      |
[INFO] |                                            |                               | Expected Response:                                                                                   |
[INFO] |                                            |                               | [{"name":"thomascollins","hospital":"grandoakcommunityhospital","category":"surgery","availability": |
[INFO] |                                            |                               | "9.00a.m-11.00a.m","fee":7000.0},{"name":"anneclement","hospital":"clemencymedicalcenter","category" |
[INFO] |                                            |                               | :"surgery","availability":"8.00a.m-10.00a.m","fee":12000.0},{"name":"sethmears","hospital":"pinevall |
[INFO] |                                            |                               | eycommunityhospital","category":"surgery","availability":"3.00p.m-5.00p.m","fee":8000.0}]            |
[INFO] +--------------------------------------------+-------------------------------+------------------------------------------------------------------------------------------------------+

The test suite xml file:

<unit-test>
    <artifacts>
        <test-artifact>
            <artifact>/SampleServicesConfigs/src/main/synapse-config/api/HealthcareAPI.xml</artifact>
        </test-artifact>
        <supportive-artifacts>
            <artifact>/SampleServices/SampleServicesConfigs/src/main/synapse-config/endpoints/QueryDoctorEP.xml</artifact>
        </supportive-artifacts>
        <registry-resources/>
        <connector-resources/>
    </artifacts>
    <test-cases>
        <test-case name="querydoctorCategoryTestSuccess">
            <input>
                <request-path>/http://localhost:9008/healthcare/querydoctor/surgery</request-path>
                <request-method>GET</request-method>
                <request-protocol>http</request-protocol>
            </input>
            <assertions>
                <assertEquals>
                    <actual>
                        $body
                    </actual>
                    <expected><![CDATA[[
    {
        "name": "thomas collins",
        "hospital": "grand oak community hospital",
        "category": "surgery",
        "availability": "9.00 a.m - 11.00 a.m",
        "fee": 7000.0
    },
    {
        "name": "anne clement",
        "hospital": "clemency medical center",
        "category": "surgery",
        "availability": "8.00 a.m - 10.00 a.m",
        "fee": 12000.0
    },
    {
        "name": "seth mears",
        "hospital": "pine valley community hospital",
        "category": "surgery",
        "availability": "3.00 p.m - 5.00 p.m",
        "fee": 8000.0
    }
]]]></expected>
                    <message>Body does not match expected value!</message>
                </assertEquals>
            </assertions>
        </test-case>
    </test-cases>
    <mock-services/>
</unit-test>
viggnah
  • 1,709
  • 1
  • 3
  • 12

2 Answers2

1

I just found a GitHub issue that mentions this problem affecting Integration studio v8.1.0 (which is the latest and the one I'm using). Looks like a fix has been merged for this on May 5, so I assume this will be fixed in the next release.

viggnah
  • 1,709
  • 1
  • 3
  • 12
0

You need to clean additional newlines in the actual and expected blocks. Please refer to the following.

<unit-test>
    <artifacts>
        <test-artifact>
            <artifact>/SampleServicesConfigs/src/main/synapse-config/api/HealthcareAPI.xml</artifact>
        </test-artifact>
        <supportive-artifacts>
            <artifact>/SampleServices/SampleServicesConfigs/src/main/synapse-config/endpoints/QueryDoctorEP.xml</artifact>
        </supportive-artifacts>
        <registry-resources/>
        <connector-resources/>
    </artifacts>
    <test-cases>
        <test-case name="querydoctorCategoryTestSuccess">
            <input>
                <request-path>/http://localhost:9008/healthcare/querydoctor/surgery</request-path>
                <request-method>GET</request-method>
                <request-protocol>http</request-protocol>
            </input>
            <assertions>
                <assertEquals>
                    <actual>$body</actual>
                    <expected><![CDATA[[{
        "name": "thomas collins",
        "hospital": "grand oak community hospital",
        "category": "surgery",
        "availability": "9.00 a.m - 11.00 a.m",
        "fee": 7000.0
    },
    {
        "name": "anne clement",
        "hospital": "clemency medical center",
        "category": "surgery",
        "availability": "8.00 a.m - 10.00 a.m",
        "fee": 12000.0
    },
    {
        "name": "seth mears",
        "hospital": "pine valley community hospital",
        "category": "surgery",
        "availability": "3.00 p.m - 5.00 p.m",
        "fee": 8000.0
    }]]]></expected>
                    <message>Body does not match expected value!</message>
                </assertEquals>
            </assertions>
        </test-case>
    </test-cases>
    <mock-services/>
</unit-test>
ycr
  • 12,828
  • 2
  • 25
  • 45
  • Still get the same error. In any case, I set up the test case using the UI and the xml was autogenerated so how could there be errors in that? At least, I wouldn't expect it, otherwise it's bug in the xml generation... – viggnah Jun 17 '22 at 04:32