-
Notifications
You must be signed in to change notification settings - Fork 18
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
Showing
6 changed files
with
151 additions
and
63 deletions.
There are no files selected for viewing
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
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
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
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
74 changes: 74 additions & 0 deletions
74
src/test/java/com/jfrog/ide/common/utils/ConsolidatePathsTest.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,74 @@ | ||
package com.jfrog.ide.common.utils; | ||
|
||
import com.google.common.collect.Sets; | ||
import org.testng.annotations.BeforeTest; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Set; | ||
|
||
import static org.testng.AssertJUnit.assertEquals; | ||
import static org.testng.AssertJUnit.assertTrue; | ||
|
||
/** | ||
* @author yahavi | ||
*/ | ||
public class ConsolidatePathsTest { | ||
|
||
private static String rootFolderA, rootFolderB, rootFolderC; | ||
|
||
@BeforeTest | ||
public void setUp() { | ||
if (isWindows()) { | ||
rootFolderA = "C:\\"; | ||
rootFolderB = "D:\\"; | ||
rootFolderC = "E:\\"; | ||
} else { | ||
rootFolderA = "/a"; | ||
rootFolderB = "/b"; | ||
rootFolderC = "/c"; | ||
} | ||
} | ||
|
||
@Test(dataProvider = "pathsDataProvider") | ||
public void testConsolidatePaths(Set<Path> given, Set<Path> expected) { | ||
Set<Path> results = Utils.consolidatePaths(given); | ||
assertEquals(expected.size(), results.size()); | ||
expected.forEach(path -> assertTrue(results.contains(path))); | ||
} | ||
|
||
@DataProvider | ||
public static Object[][] pathsDataProvider() { | ||
return new Object[][]{ | ||
{Sets.newHashSet((Object) Paths.get(rootFolderA)), | ||
Sets.newHashSet((Object) Paths.get(rootFolderA))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderB), Paths.get(rootFolderC)), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderB), Paths.get(rootFolderC))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderB, "a"), Paths.get(rootFolderC, "b", "d"), Paths.get(rootFolderC, "b")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderB, "a"), Paths.get(rootFolderC, "b"))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "b"), Paths.get(rootFolderC, "b")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderC, "b"))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "a"), Paths.get(rootFolderA, "b")), | ||
Sets.newHashSet((Object) Paths.get(rootFolderA))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "a"), Paths.get(rootFolderC, "b"), Paths.get(rootFolderC, "b", "fff"), Paths.get(rootFolderC, "f", "fff")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderC, "b"), Paths.get(rootFolderC, "f", "fff"))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "a/"), Paths.get(rootFolderC, "b"), Paths.get(rootFolderC, "b", "..", "b", "..", "b", "fff"), Paths.get(rootFolderC, "f", "fff")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderC, "b"), Paths.get(rootFolderC, "f", "fff"))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "a"), Paths.get(rootFolderC, "b", ".."), Paths.get(rootFolderC, "b", "..", "b", "..", "b", "fff"), Paths.get(rootFolderC, "f", "fff")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderC))}, | ||
}; | ||
} | ||
|
||
private boolean isWindows() { | ||
return System.getProperty("os.name").toLowerCase().contains("win"); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,74 +1,43 @@ | ||
package com.jfrog.ide.common.utils; | ||
|
||
import com.google.common.collect.Sets; | ||
import org.testng.annotations.BeforeTest; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Set; | ||
import static com.jfrog.ide.common.utils.Utils.resolveArtifactoryUrl; | ||
import static com.jfrog.ide.common.utils.Utils.resolveXrayUrl; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
import static org.testng.AssertJUnit.assertEquals; | ||
import static org.testng.AssertJUnit.assertTrue; | ||
|
||
/** | ||
* @author yahavi | ||
*/ | ||
public class UtilsTest { | ||
|
||
private static String rootFolderA, rootFolderB, rootFolderC; | ||
|
||
@BeforeTest | ||
public void setUp() { | ||
if (isWindows()) { | ||
rootFolderA = "C:\\"; | ||
rootFolderB = "D:\\"; | ||
rootFolderC = "E:\\"; | ||
} else { | ||
rootFolderA = "/a"; | ||
rootFolderB = "/b"; | ||
rootFolderC = "/c"; | ||
} | ||
@DataProvider | ||
public static Object[][] xrayUrlDataProvider() { | ||
return new Object[][]{ | ||
{"", "", ""}, | ||
{"", "https://acme.jfrog.io", "https://acme.jfrog.io/xray"}, | ||
{"", "https://acme.jfrog.io/", "https://acme.jfrog.io/xray"}, | ||
{"https://acme.jfrog.io/xray", "https://acme.jfrog.io", "https://acme.jfrog.io/xray"}, | ||
{"https://acme.jfrog.io/xray/", "https://acme.jfrog.io", "https://acme.jfrog.io/xray"} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "pathsDataProvider") | ||
public void testConsolidatePaths(Set<Path> given, Set<Path> expected) { | ||
Set<Path> results = Utils.consolidatePaths(given); | ||
assertEquals(expected.size(), results.size()); | ||
expected.forEach(path -> assertTrue(results.contains(path))); | ||
@Test(dataProvider = "xrayUrlDataProvider") | ||
public void testResolveXrayUrl(String inputXrayUrl, String inputPlatformUrl, String expectedXrayUrl) { | ||
assertEquals(resolveXrayUrl(inputXrayUrl, inputPlatformUrl), expectedXrayUrl); | ||
} | ||
|
||
@DataProvider | ||
public static Object[][] pathsDataProvider() { | ||
public static Object[][] artifactoryUrlDataProvider() { | ||
return new Object[][]{ | ||
{Sets.newHashSet((Object) Paths.get(rootFolderA)), | ||
Sets.newHashSet((Object) Paths.get(rootFolderA))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderB), Paths.get(rootFolderC)), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderB), Paths.get(rootFolderC))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderB, "a"), Paths.get(rootFolderC, "b", "d"), Paths.get(rootFolderC, "b")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderB, "a"), Paths.get(rootFolderC, "b"))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "b"), Paths.get(rootFolderC, "b")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderC, "b"))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "a"), Paths.get(rootFolderA, "b")), | ||
Sets.newHashSet((Object) Paths.get(rootFolderA))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "a"), Paths.get(rootFolderC, "b"), Paths.get(rootFolderC, "b", "fff"), Paths.get(rootFolderC, "f", "fff")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderC, "b"), Paths.get(rootFolderC, "f", "fff"))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "a/"), Paths.get(rootFolderC, "b"), Paths.get(rootFolderC, "b", "..", "b", "..", "b", "fff"), Paths.get(rootFolderC, "f", "fff")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderC, "b"), Paths.get(rootFolderC, "f", "fff"))}, | ||
|
||
{Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderA, "a"), Paths.get(rootFolderC, "b", ".."), Paths.get(rootFolderC, "b", "..", "b", "..", "b", "fff"), Paths.get(rootFolderC, "f", "fff")), | ||
Sets.newHashSet(Paths.get(rootFolderA), Paths.get(rootFolderC))}, | ||
{"", "", ""}, | ||
{"", "https://acme.jfrog.io", "https://acme.jfrog.io/artifactory"}, | ||
{"", "https://acme.jfrog.io/", "https://acme.jfrog.io/artifactory"}, | ||
{"https://acme.jfrog.io/artifactory", "https://acme.jfrog.io", "https://acme.jfrog.io/artifactory"}, | ||
{"https://acme.jfrog.io/artifactory/", "https://acme.jfrog.io", "https://acme.jfrog.io/artifactory"} | ||
}; | ||
} | ||
|
||
private boolean isWindows() { | ||
return System.getProperty("os.name").toLowerCase().contains("win"); | ||
@Test(dataProvider = "artifactoryUrlDataProvider") | ||
public void testResolveArtifactoryUrl(String inputArtifactoryUrl, String inputPlatformUrl, String expectedArtifactoryUrl) { | ||
assertEquals(resolveArtifactoryUrl(inputArtifactoryUrl, inputPlatformUrl), expectedArtifactoryUrl); | ||
} | ||
} | ||
} |