From a3eb32d31790ac7ee2a7e8cd13aa1cfa7dec0f43 Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Sun, 10 Dec 2023 19:58:44 +0530 Subject: [PATCH] Assert the file name instead of the abs path --- .../extension/ModelGeneratorTest.java | 29 ++++++++++++------- .../test/resources/config/simple_flow.json | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/worker-model-generator/modules/model-generator-ls-extension/src/test/java/io/ballerina/workermodelgenerator/extension/ModelGeneratorTest.java b/worker-model-generator/modules/model-generator-ls-extension/src/test/java/io/ballerina/workermodelgenerator/extension/ModelGeneratorTest.java index 98aa07bda..781b118b6 100644 --- a/worker-model-generator/modules/model-generator-ls-extension/src/test/java/io/ballerina/workermodelgenerator/extension/ModelGeneratorTest.java +++ b/worker-model-generator/modules/model-generator-ls-extension/src/test/java/io/ballerina/workermodelgenerator/extension/ModelGeneratorTest.java @@ -77,10 +77,15 @@ public void testGeneratedModel(Path config) throws IOException { JsonObject jsonModel = json.getAsJsonObject("result").getAsJsonObject("workerDesignModel"); Flow flow = gson.fromJson(jsonModel, Flow.class); - boolean result = flow.equals(testConfig.getFlow()); - if (!result) { -// updateConfig(configJsonPath, testConfig, flow); - logModelDifference(flow, testConfig.getFlow()); + // Assert only the file name since the absolute path may vary depending on the machine + String balFileName = Path.of(flow.fileName()).getFileName().toString(); + boolean fileNameEquality = balFileName.equals(testConfig.getFlow().fileName()); + Flow modifiedFlow = new Flow(flow.id(), flow.name(), balFileName, flow.nodes()); + + boolean flowEquality = modifiedFlow.equals(testConfig.getFlow()); + if (!fileNameEquality || !flowEquality) { +// updateConfig(configJsonPath, testConfig, modifiedFlow); + logModelDifference(testConfig.getFlow(), modifiedFlow); Assert.fail(String.format("Failed test: '%s' (%s)", testConfig.getDescription(), configJsonPath)); } } @@ -127,9 +132,9 @@ private void updateConfig(Path configJsonPath, TestConfig testConfig, Flow respo } private void logModelDifference(Flow expectedFlow, Flow actualFlow) { - logPropertyDifference(expectedFlow.id(), actualFlow.id()); - logPropertyDifference(expectedFlow.name(), actualFlow.name()); - logPropertyDifference(expectedFlow.fileName(), actualFlow.fileName()); + logPropertyDifference("id", expectedFlow.id(), actualFlow.id()); + logPropertyDifference("name", expectedFlow.name(), actualFlow.name()); + logPropertyDifference("fileName", expectedFlow.fileName(), actualFlow.fileName()); List missingNodes = new ArrayList<>(); List irrelevantNodes = new ArrayList<>(actualFlow.nodes()); @@ -139,13 +144,15 @@ private void logModelDifference(Flow expectedFlow, Flow actualFlow) { missingNodes.add(expectedNode); } } - LOG.info("Completion items which are in response but not in test config : " + irrelevantNodes); - LOG.info("Completion items which are in test config but not in response : " + missingNodes); + if (!missingNodes.isEmpty() || !irrelevantNodes.isEmpty()) { + LOG.info("Completion items which are in response but not in test config : " + irrelevantNodes); + LOG.info("Completion items which are in test config but not in response : " + missingNodes); + } } - private void logPropertyDifference(String expected, String actual) { + private void logPropertyDifference(String name, String expected, String actual) { if (!expected.equals(actual)) { - LOG.info(String.format("Expected name=(%s), but found name=(%s)", expected, actual)); + LOG.info(String.format("Expected %s=(%s), but found %s=(%s)", name, expected, name, actual)); } } diff --git a/worker-model-generator/modules/model-generator-ls-extension/src/test/resources/config/simple_flow.json b/worker-model-generator/modules/model-generator-ls-extension/src/test/resources/config/simple_flow.json index c97e13fcd..846550d63 100644 --- a/worker-model-generator/modules/model-generator-ls-extension/src/test/resources/config/simple_flow.json +++ b/worker-model-generator/modules/model-generator-ls-extension/src/test/resources/config/simple_flow.json @@ -12,7 +12,7 @@ "flow": { "id": "1", "name": "main/function", - "fileName": "/Users/nipunaf/projects/ballerina/ballerina-dev-tools/worker-model-generator/modules/model-generator-ls-extension/src/test/resources/source/simple_flow.bal", + "fileName": "simple_flow.bal", "nodes": [ { "name": "A",