From 64852e7769b820ed9f879ff8ac7bcb737102047b Mon Sep 17 00:00:00 2001 From: svacas Date: Fri, 27 May 2022 18:13:33 -0300 Subject: [PATCH] Support mocks with no "with-attributes" or "then-return" children --- .../input/src/test/munit/munit-test.xml | 16 ++++++++++ .../munitMockMvn/output/report/report.json | 12 +++---- .../output/src/test/munit/munit-test.xml | 32 +++++++++++++++++++ .../migration/library/munit/steps/Mock.java | 14 +++++--- 4 files changed, 63 insertions(+), 11 deletions(-) diff --git a/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/input/src/test/munit/munit-test.xml b/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/input/src/test/munit/munit-test.xml index ebef6209f..405755f4a 100644 --- a/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/input/src/test/munit/munit-test.xml +++ b/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/input/src/test/munit/munit-test.xml @@ -25,4 +25,20 @@ http://www.mulesoft.org/schema/mule/mock http://www.mulesoft.org/schema/mule/moc + + + + + + + + + + + + + + + + diff --git a/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/output/report/report.json b/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/output/report/report.json index a171e0776..6c76a1e76 100644 --- a/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/output/report/report.json +++ b/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/output/report/report.json @@ -2,8 +2,8 @@ "projectType": "MULE_THREE_MAVEN_APPLICATION", "projectName": "input", "connectorsMigrated": [], - "numberOfMuleComponents": 11, - "numberOfMuleComponentsMigrated": 11, + "numberOfMuleComponents": 19, + "numberOfMuleComponentsMigrated": 19, "componentDetails": { "mule": { "success": 2, @@ -14,7 +14,7 @@ "failure": 0 }, "flow-ref": { - "success": 1, + "success": 3, "failure": 0 }, "set-payload": { @@ -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": { diff --git a/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/output/src/test/munit/munit-test.xml b/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/output/src/test/munit/munit-test.xml index 1c227c4d2..6862c2f55 100644 --- a/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/output/src/test/munit/munit-test.xml +++ b/mule-migration-tool-e2e-tests/src/test/resources/e2e/munit/munitMockMvn/output/src/test/munit/munit-test.xml @@ -22,4 +22,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mule-migration-tool-library/src/main/java/com/mulesoft/tools/migration/library/munit/steps/Mock.java b/mule-migration-tool-library/src/main/java/com/mulesoft/tools/migration/library/munit/steps/Mock.java index 78c68da09..bbfe3703e 100644 --- a/mule-migration-tool-library/src/main/java/com/mulesoft/tools/migration/library/munit/steps/Mock.java +++ b/mule-migration-tool-library/src/main/java/com/mulesoft/tools/migration/library/munit/steps/Mock.java @@ -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());