Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mocks with no "with-attributes" or "then-return" children #652

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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