Skip to content

Commit

Permalink
Assert the file name instead of the abs path
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Dec 10, 2023
1 parent 93e5543 commit 3caeb53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@ 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());
// Assert only the file name since the absolute path may vary depending on the machine
String balFileName = getFileName(flow.fileName());
Assert.assertEquals(getFileName(flow.fileName()), getFileName(testConfig.getFlow().fileName()));
Flow modifiedFlow = new Flow(flow.id(), flow.name(),
Path.of("source_root").resolve(balFileName).toString(), flow.nodes());
LOG.info(modifiedFlow.fileName());

boolean result = modifiedFlow.equals(testConfig.getFlow());
if (!result) {
// updateConfig(configJsonPath, testConfig, flow);
logModelDifference(flow, testConfig.getFlow());
// updateConfig(configJsonPath, testConfig, modifiedFlow);
logModelDifference(testConfig.getFlow(), modifiedFlow);
Assert.fail(String.format("Failed test: '%s' (%s)", testConfig.getDescription(), configJsonPath));
}
}
Expand Down Expand Up @@ -127,9 +134,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<WorkerNode> missingNodes = new ArrayList<>();
List<WorkerNode> irrelevantNodes = new ArrayList<>(actualFlow.nodes());
Expand All @@ -139,16 +146,22 @@ 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));
}
}

private String getFileName(String filePath) {
return Path.of(filePath).getFileName().toString();
}

@AfterClass
public void shutDownLanguageServer() {
TestUtil.shutdownLanguageServer(this.serviceEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "source_root/simple_flow.bal",
"nodes": [
{
"name": "A",
Expand Down

0 comments on commit 3caeb53

Please sign in to comment.