Skip to content

Commit

Permalink
👌 IMPROVE: Remove specific service messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jpontdia committed Oct 25, 2023
1 parent 87f8691 commit 11bc80c
Showing 1 changed file with 46 additions and 39 deletions.
85 changes: 46 additions & 39 deletions src/test/munit/backend-errors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd">
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/munit
http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.mulesoft.org/schema/mule/munit-tools
http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core
http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/validation
http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd">

<munit:config name="backend-errors" />

<munit:test
name="post-customer-not-created"
description="post-customer-not-created"
doc:id="c2d58ddf-f36b-40e5-87c6-cde2041683e2">
description="post-customer-not-created">

<munit:enable-flow-sources>
<munit:enable-flow-source value="api-main" />
Expand All @@ -30,7 +36,6 @@ http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mu
<munit:enable-flow-source value="delete:\customers\(customerId):api-config" />
<munit:enable-flow-source value="post:\customers:application\json:api-config" />
</munit:enable-flow-sources>


<munit:behavior>
<munit:set-event
Expand All @@ -41,9 +46,9 @@ http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mu
encoding="UTF-8" />
<munit:attributes value="#[readUrl('classpath://orderapiconsoletest/set-event_attributes.dwl')]" />
</munit:set-event>

<munit-tools:mock-when
doc:name="no Customer on Database"
doc:id="3faf0a68-495a-4736-b041-93f1e35604d7"
processor="flow-ref">
<munit-tools:with-attributes>
<munit-tools:with-attribute
Expand All @@ -54,9 +59,9 @@ http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mu
<munit-tools:payload value="#[&#10;[]&#10;]" />
</munit-tools:then-return>
</munit-tools:mock-when>

<munit-tools:mock-when
doc:name="Salesforce not success"
doc:id="73be5b07-b36a-4d07-b800-58b8cc8e5a6d"
processor="salesforce:create">
<munit-tools:with-attributes>
<munit-tools:with-attribute
Expand All @@ -70,45 +75,41 @@ http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mu
</munit-tools:then-return>
</munit-tools:mock-when>
</munit:behavior>

<munit:execution>
<flow-ref
doc:name="post"
doc:id="72262c22-5481-486c-931e-9cc17b1bb790"
name="post:\customers" />
<logger level="INFO" doc:name="Logger" doc:id="ae0362b4-2ffa-43cf-9b24-672cbb2bccfa" message='#[%dw 2.0&#10;output application/json&#10;---&#10;{&#10; message: "Result from customer creation",&#10; status: vars.httpStatus,&#10; payload: payload&#10;}]'/>
<logger
level="INFO"
doc:name="Logger"
message='#[%dw 2.0&#10;output application/json&#10;---&#10;{&#10; message: "Result from customer creation",&#10; status: vars.httpStatus,&#10; payload: payload&#10;}]'/>

</munit:execution>
<munit:validation>
<munit-tools:assert-equals
doc:name="status 500"
doc:id="5b3a56ae-45ff-41c4-a1d8-0a44c697c0a0"
actual="#[vars.httpStatus]"
expected='#["500"]'
message="The status code must be 500" />
<munit-tools:assert-that
doc:name="verify response"
doc:id="f0a119d7-96ac-4e8d-8c0b-0f12b9e685e8"
expression='#[payload.message contains "${messages.record-create-error}"]'
is="#[MunitTools::notNullValue()]" />
</munit:validation>
</munit:test>


<munit:test
name="post-customer-backend-exception"
doc:id="1e2f6512-c08d-4666-a480-61713b17accd">
<munit:test name="post-customer-backend-exception" >
<munit:behavior>
<munit:set-event
doc:name="Set Input"
doc:id="32a60db6-e1e3-4cb5-b903-cb8b26303ccc">
<munit:set-event doc:name="Set Input">
<munit:payload
value="#[readUrl('classpath://post/set-event_payload.dwl')]"
encoding="UTF-8" />
<munit:attributes value="#[readUrl('classpath://orderapiconsoletest/set-event_attributes.dwl')]" />
</munit:set-event>
<munit-tools:mock-when
doc:name="no Customer on Database"
doc:id="b5541543-3c5f-4d92-879a-e499561f537e"
processor="flow-ref">
<munit-tools:with-attributes>
<munit-tools:with-attribute
Expand All @@ -121,7 +122,6 @@ http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mu
</munit-tools:mock-when>
<munit-tools:mock-when
doc:name="Salesforce not success"
doc:id="094fb715-2617-4f95-9351-f3b87f6e24eb"
processor="salesforce:create">
<munit-tools:with-attributes>
<munit-tools:with-attribute
Expand All @@ -137,39 +137,39 @@ http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mu
</munit-tools:mock-when>
</munit:behavior>
<munit:execution>
<try
doc:name="Try"
doc:id="3c0b8cf9-a2dc-4034-b22d-50dd53cce815">
<try doc:name="Try">
<flow-ref
doc:name="post"
doc:id="dc7d6337-59aa-43ce-ad86-29d1c74d2732"
name="post:\customers" />

<error-handler>
<on-error-continue
enableNotifications="true"
logException="true"
doc:name="On Error Continue"
doc:id="a0484362-987b-4d22-8e52-e4a3bd76cf2a">
doc:name="On Error Continue">

<logger
level="INFO"
doc:name="Logger"
doc:id="3d9cda2d-bd1c-4697-9972-92d3d822bc02"
message="An error was produced in the tested flow" />
</on-error-continue>
</error-handler>
</try>
<logger level="INFO" doc:name="result" doc:id="b3bb99c3-ee71-406b-b562-8e49699dc6c6" message='#[%dw 2.0&#10;output application/json&#10;---&#10;{&#10; message: "Result from customer creation",&#10; status: vars.httpStatus,&#10; payload: payload&#10;}]'/>

<logger
level="INFO"
doc:name="result"
message='#[%dw 2.0&#10;output application/json&#10;---&#10;{&#10; message: "Result from customer creation",&#10; status: vars.httpStatus,&#10; payload: payload&#10;}]'/>

</munit:execution>
<munit:validation>
<munit-tools:assert-equals
doc:name="status 500"
doc:id="96ed04c5-4013-42de-b30b-32969d05491f"
actual="#[vars.httpStatus]"
expected='#["500"]'
message="The status code must be 500" />
<munit-tools:assert-that
doc:name="verify response"
doc:id="1bff4e12-e359-4343-91f1-463e3d9d7240"
expression='#[payload.message contains "${messages.backend-error}"]'
is="#[MunitTools::notNullValue()]" />
</munit:validation>
Expand All @@ -187,11 +187,14 @@ http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mu

<munit:execution>

<logger level="INFO" doc:name="start" doc:id="b43161e2-713b-427f-8dfd-627b7f4ecf85" message="Test delete with fake id"/>
<logger
level="INFO"
doc:name="start"
message="Test delete with fake id"/>

<http:request
method="DELETE"
doc:name="Delete"
doc:id="3f820317-8219-4dbd-a7b5-5b4878d9beb5"
config-ref="http_test_local_configuration"
path="/api/customers/{customerId}">
<http:headers><![CDATA[#[output application/java
Expand All @@ -208,9 +211,14 @@ http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mu
<http:success-status-code-validator values="200,400" />
</http:response-validator>
</http:request>
<logger level="INFO" doc:name="result" doc:id="db5e815b-7923-4a2f-9f38-9a7a5a562107" message='#[%dw 2.0&#10;output application/json&#10;---&#10;{&#10; message: "Result",&#10; payload: payload&#10;}]' />

<logger
level="INFO"
doc:name="result"
message='#[%dw 2.0&#10;output application/json&#10;---&#10;{&#10; message: "Result",&#10; payload: payload&#10;}]' />

</munit:execution>

<munit:validation>
<munit-tools:assert-equals
actual="#[attributes.statusCode]"
Expand All @@ -219,10 +227,9 @@ http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mu
doc:name="status 400" />
<munit-tools:assert-that
doc:name="verify message"
doc:id="58e2a1fb-98b2-49c4-900e-190c679a5bfa"
expression='#[payload.message contains "${messages.customer-doesnt-exist-relations}"]'
expression='#[payload.message contains "${messages.record-delete-error}"]'
is="#[MunitTools::notNullValue()]" />
</munit:validation>
</munit:test>

</mule>
</mule>

0 comments on commit 11bc80c

Please sign in to comment.