From dcfd63b57fe1666c6ed3b232bbce367ce1d0b856 Mon Sep 17 00:00:00 2001 From: Suganya Date: Mon, 8 Feb 2021 10:35:19 +0530 Subject: [PATCH] Test dist update --- .../distribution/test/BallerinaCommandTest.java | 13 +++++++++++++ .../ballerinalang/distribution/utils/TestUtils.java | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ballerina-test/src/test/java/org/ballerinalang/distribution/test/BallerinaCommandTest.java b/ballerina-test/src/test/java/org/ballerinalang/distribution/test/BallerinaCommandTest.java index 714a6b31a2..bdbc0c8c91 100644 --- a/ballerina-test/src/test/java/org/ballerinalang/distribution/test/BallerinaCommandTest.java +++ b/ballerina-test/src/test/java/org/ballerinalang/distribution/test/BallerinaCommandTest.java @@ -25,6 +25,8 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; /** * Test ballerina commands. @@ -71,9 +73,13 @@ public void testDistCommands() throws IOException { Assert.assertTrue(actualOutput.contains("'1.2.3' successfully set as the active distribution")); TestUtils.testInstallation(path, "1.2.3", "2020R1", TOOL_VERSION, "1.2.3"); // test bal dist update + Path ballerinaHome = Paths.get(TestUtils.getUserHome()).resolve(".ballerina").resolve("ballerina-version"); actualOutput = TestUtils.executeCommand(path + " dist update"); + String latestPatchVersion = actualOutput.split("Downloading ")[1].split(" ")[0]; + String version = TestUtils.getContent(ballerinaHome).split("-")[1].trim(); Assert.assertTrue(actualOutput.contains("Fetching the latest patch distribution for 'jballerina-1.2.3' from the remote server...")); Assert.assertTrue(actualOutput.contains("Successfully set the latest patch distribution")); + Assert.assertEquals(version, latestPatchVersion); actualOutput = TestUtils.executeCommand(path + " dist update"); Assert.assertTrue(actualOutput.contains("is already the active distribution")); // test bal dist use @@ -93,6 +99,13 @@ public void testDistCommands() throws IOException { Assert.assertTrue(actualOutput.contains("Distribution '" + SHORT_VERSION + "' successfully removed")); actualOutput = TestUtils.executeCommand(path + " dist use " + SHORT_VERSION); Assert.assertTrue(actualOutput.contains("Distribution '" + SHORT_VERSION + "' not found")); + actualOutput = TestUtils.executeCommand(path + " dist update"); + latestPatchVersion = actualOutput.split("Downloading ")[1].split(" ")[0]; + version = TestUtils.getContent(ballerinaHome).split("-")[1].trim(); + Assert.assertTrue(actualOutput.contains("Fetching the latest patch distribution for 'ballerina-slp7' from the remote server...")); + Assert.assertTrue(actualOutput.contains("Successfully set the latest patch distribution")); + Assert.assertEquals(version, latestPatchVersion); + // test bal dist remove -a actualOutput = TestUtils.executeCommand(path + " dist remove -a"); Assert.assertTrue(actualOutput.contains("All non-active distributions are successfully removed")); diff --git a/ballerina-test/src/test/java/org/ballerinalang/distribution/utils/TestUtils.java b/ballerina-test/src/test/java/org/ballerinalang/distribution/utils/TestUtils.java index 648236d882..bc82b742c9 100644 --- a/ballerina-test/src/test/java/org/ballerinalang/distribution/utils/TestUtils.java +++ b/ballerina-test/src/test/java/org/ballerinalang/distribution/utils/TestUtils.java @@ -280,7 +280,7 @@ public static void testInstallation(String path, String jBallerinaVersion, Strin /** * Get version output for version command. - * @param jBallerinaVersion Installed jBallerina version + * @param jBallerinaVersion Installed jBallerina version * @param specVersion Installed language specification * @param toolVersion Installed tool version * @param versionDisplayText display text for installed jBallerina version @@ -323,4 +323,14 @@ public static boolean isSupportedRelease(String version) { String[] versions = version.split("\\."); return !(versions[0].equals("1") && versions[1].equals("0")); } + + /** + * Get the content of the file. + * @param filePath Path to the file + * @return content of the file + * @throws IOException + */ + public static String getContent(Path filePath) throws IOException { + return Files.readString(filePath); + } }