forked from jfrog/ide-plugins-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
911ae50
commit 927c2b5
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
src/test/java/com/jfrog/ide/common/yarn/YarnDriverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |