From 927c2b54ba61fbb1c08bf7c7191943d044f172ba Mon Sep 17 00:00:00 2001 From: noys Date: Wed, 15 Nov 2023 14:05:59 +0200 Subject: [PATCH] :white_check_mark: YarnDriver tests were added --- .../jfrog/ide/common/yarn/YarnDriverTest.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/test/java/com/jfrog/ide/common/yarn/YarnDriverTest.java diff --git a/src/test/java/com/jfrog/ide/common/yarn/YarnDriverTest.java b/src/test/java/com/jfrog/ide/common/yarn/YarnDriverTest.java new file mode 100644 index 0000000..c0086a4 --- /dev/null +++ b/src/test/java/com/jfrog/ide/common/yarn/YarnDriverTest.java @@ -0,0 +1,84 @@ +package com.jfrog.ide.common.yarn; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.commons.io.FileUtils; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.testng.Assert.*; + +/** + * Test the 'why' functionality in YarnDriver. + */ +public class YarnDriverTest { + private static final Path YARN_ROOT = Paths.get(".").toAbsolutePath().normalize().resolve(Paths.get("src", "test", "resources", "yarn")); + + enum Project { + + EMPTY("empty"), + DEPENDENCY("dependency"); + + private final Path path; + + Project(String path) { + this.path = YARN_ROOT.resolve(path); + } + } + + private final YarnDriver yarnDriver = new YarnDriver(null); + private File tempProject; + + @BeforeMethod + public void setUp(Object[] testArgs) { + try { + tempProject = Files.createTempDirectory("ide-plugins-common-yarn").toFile(); + tempProject.deleteOnExit(); + FileUtils.copyDirectory(((Project) testArgs[0]).path.toFile(), tempProject); + } catch (IOException e) { + fail(e.getMessage(), e); + } + } + + @AfterMethod + public void tearDown() { + FileUtils.deleteQuietly(tempProject); + } + + @DataProvider + private Object[][] yarnWhyProvider() { + return new Object[][]{ + {Project.DEPENDENCY, "progress"}, + {Project.DEPENDENCY, "has-flag"}, + {Project.EMPTY, "component-name"} // Should return an error + }; + } + + @Test(dataProvider = "yarnWhyProvider") + public void yarnWhyTest(Project project, String componentName) { + try { + JsonNode[] whyResults = yarnDriver.why(tempProject, componentName); + assertNotNull(whyResults); + assertTrue(whyResults.length > 0); + + if (project == Project.EMPTY) { + assertTrue(whyResults[0].has("problems"), "Yarn why command result should contain problems:\n" + whyResults[0].toString()); + return; + } + + for (JsonNode result : whyResults) { + assertNotNull(result); + assertFalse(result.has("problems"), "Unexpected problems in yarn why command result:\n" + result.get("problems")); + } + } catch (IOException e) { + fail("Exception during yarn why command: " + e.getMessage(), e); + } + } +}