Skip to content

Commit

Permalink
Support mocks with no "with-attributes" or "then-return" children (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
svacas authored May 31, 2022
1 parent 110aec3 commit 42746b4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,20 @@ http://www.mulesoft.org/schema/mule/mock http://www.mulesoft.org/schema/mule/moc
<flow-ref name="simplemunitFlow" doc:name="Flow-ref to simplemunitFlow"/>
<munit:assert-payload-equals message="#['Not the same']" expectedValue="#['mock']" doc:name="Assert Payload"/>
</munit:test>
<munit:test name="munit-test-mock-no-attributes" description="Test">
<mock:when messageProcessor=".*:.*" doc:name="Mock">
<mock:then-return payload="#['mock']" encoding="UTF-8"/>
</mock:when>
<flow-ref name="simplemunitFlow" doc:name="Flow-ref to simplemunitFlow"/>
<munit:assert-payload-equals message="#['Not the same']" expectedValue="#['mock']" doc:name="Assert Payload"/>
</munit:test>
<munit:test name="munit-test-mock-no-then-return" description="Test">
<mock:when messageProcessor=".*:.*" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['Set Payload']"/>
</mock:with-attributes>
</mock:when>
<flow-ref name="simplemunitFlow" doc:name="Flow-ref to simplemunitFlow"/>
<munit:assert-payload-equals message="#['Not the same']" expectedValue="#['']" doc:name="Assert Payload"/>
</munit:test>
</mule>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"projectType": "MULE_THREE_MAVEN_APPLICATION",
"projectName": "input",
"connectorsMigrated": [],
"numberOfMuleComponents": 11,
"numberOfMuleComponentsMigrated": 11,
"numberOfMuleComponents": 19,
"numberOfMuleComponentsMigrated": 19,
"componentDetails": {
"mule": {
"success": 2,
Expand All @@ -14,7 +14,7 @@
"failure": 0
},
"flow-ref": {
"success": 1,
"success": 3,
"failure": 0
},
"set-payload": {
Expand All @@ -26,15 +26,15 @@
"failure": 0
},
"munit-tools:assert-that": {
"success": 1,
"success": 3,
"failure": 0
},
"munit-tools:mock-when": {
"success": 1,
"success": 3,
"failure": 0
},
"munit:test": {
"success": 1,
"success": 3,
"failure": 0
},
"munit:config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,36 @@
</munit:validation>
</munit:test>

<munit:test name="munit-test-mock-no-attributes" description="Test">
<munit:behavior>
<munit-tools:mock-when processor=".*:.*" doc:name="Mock">
<munit-tools:then-return>
<munit-tools:payload value="#['mock']" encoding="UTF-8" />
</munit-tools:then-return>
</munit-tools:mock-when>
</munit:behavior>
<munit:execution>
<flow-ref name="simplemunitFlow" doc:name="Flow-ref to simplemunitFlow" />
</munit:execution>
<munit:validation>
<munit-tools:assert-that message="#['Not the same']" is="#[MunitTools::equalTo('mock')]" doc:name="Assert Payload" expression="#[payload]" />
</munit:validation>
</munit:test>

<munit:test name="munit-test-mock-no-then-return" description="Test">
<munit:behavior>
<munit-tools:mock-when processor=".*:.*" doc:name="Mock">
<munit-tools:with-attributes>
<munit-tools:with-attribute attributeName="doc:name" whereValue="#['Set Payload']" />
</munit-tools:with-attributes>
</munit-tools:mock-when>
</munit:behavior>
<munit:execution>
<flow-ref name="simplemunitFlow" doc:name="Flow-ref to simplemunitFlow" />
</munit:execution>
<munit:validation>
<munit-tools:assert-that message="#['Not the same']" is="#[MunitTools::equalTo('')]" doc:name="Assert Payload" expression="#[payload]" />
</munit:validation>
</munit:test>

</mule>
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ public void execute(Element element, MigrationReport report) throws RuntimeExcep
updateChildElementsNamespace(element.getChildren());

Element attributesNode = element.getChild("with-attributes", element.getNamespace());

attributesNode.getChildren().forEach(n -> changeAttribute("name", of("attributeName"), empty())
.apply(n));

movePayloadToChildNode(element.getChild("then-return", element.getNamespace()));
if (attributesNode != null) {
attributesNode.getChildren().forEach(n -> changeAttribute("name", of("attributeName"), empty())
.apply(n));
}

Element thenReturnNode = element.getChild("then-return", element.getNamespace());
if (thenReturnNode != null) {
movePayloadToChildNode(thenReturnNode);
}

} catch (Exception e) {
throw new MigrationStepException("Fail to apply step. " + e.getMessage());
Expand Down

0 comments on commit 42746b4

Please sign in to comment.