diff --git a/src/main/resources/alex/jenkins/plugins/FileSystemListParameterGlobalConfiguration/help-enabledUserContent.html b/src/main/resources/alex/jenkins/plugins/FileSystemListParameterGlobalConfiguration/help-enabledUserContent.html
index c478596..e43a8ab 100644
--- a/src/main/resources/alex/jenkins/plugins/FileSystemListParameterGlobalConfiguration/help-enabledUserContent.html
+++ b/src/main/resources/alex/jenkins/plugins/FileSystemListParameterGlobalConfiguration/help-enabledUserContent.html
@@ -1,3 +1,3 @@
- Default base dir for allowed paths for the plugin. Allows JENKINS_HOME/userContent on built-in and nodes.
+ Default base dir for allowed paths for the plugin. Allows JENKINS_HOME/userContent on built-in.
\ No newline at end of file
diff --git a/src/test/java/alex/jenkins/plugins/ChangeSequenceTest.java b/src/test/java/alex/jenkins/plugins/ChangeSequenceTest.java
index c4be7fb..2da0346 100644
--- a/src/test/java/alex/jenkins/plugins/ChangeSequenceTest.java
+++ b/src/test/java/alex/jenkins/plugins/ChangeSequenceTest.java
@@ -7,18 +7,29 @@
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
+
+import alex.jenkins.plugins.FileSystemListParameterDefinition.FilesLister;
public class ChangeSequenceTest {
- String path;
+ @Rule
+ public JenkinsRule j = new JenkinsRule();
- @Before
+ String path;
+ FileSystemListParameterGlobalConfiguration globalConfigAllowedPaths;
+
+ @Before
public void setup(){
URL resource = getClass().getResource("/1");
Assert.assertNotNull("Test test directory missing", resource);
path = resource.getPath();
+
+ TestUtils tu = new TestUtils();
+ globalConfigAllowedPaths = tu.createTestGC(path);
}
@Test
@@ -35,7 +46,8 @@ public void testSorting() {
map.put(f1.getName(), (long) 2);
map.put(f2.getName(), (long) 1);
- List sortedList = FileSystemListParameterDefinition.createTimeSortedList(map);
+
+ List sortedList = Utils.createTimeSortedList(map);
Assert.assertEquals(test2,sortedList.get(0));
Assert.assertEquals(test1,sortedList.get(1));
@@ -47,8 +59,10 @@ public void testSorting() {
public void testReverseOrder() {
boolean sortByLastModified = true;
boolean sortReverseOrder = true;
- boolean includePathInValue = false;
- FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", "path", "", "FILE","SINGLE_SELECT", "", "", sortByLastModified, sortReverseOrder, includePathInValue);
+ boolean includePathInValue = false;
+ FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path, "", "FILE","SINGLE_SELECT", "", "", sortByLastModified, sortReverseOrder, includePathInValue);
+ FileSystemListParameterDefinition.addTestGC(globalConfigAllowedPaths);
+ FilesLister fl = new FilesLister(pd.getSelectedEnumType(), pd.getRegexIncludePattern(), pd.getRegexExcludePattern(), pd.getPath(), pd.isSortByLastModified(), pd.isSortReverseOrder());
TreeMap map = new TreeMap<>();
String test1 = "test1";
@@ -59,7 +73,7 @@ public void testReverseOrder() {
map.put(f1.getName(), (long) 2);
map.put(f2.getName(), (long) 1);
- List sortedList = pd.sortList(map);
+ List sortedList = fl.sortList(map);
Assert.assertEquals(test1,sortedList.get(0));
Assert.assertEquals(test2,sortedList.get(1));
@@ -71,8 +85,10 @@ public void testReverseOrder() {
public void testAlphabeticOrder() {
boolean sortByLastModified = false;
boolean sortReverseOrder = false;
- boolean includePathInValue = false;
- FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", "path", "", "FILE","SINGLE_SELECT", "", "", sortByLastModified, sortReverseOrder, includePathInValue);
+ boolean includePathInValue = false;
+ FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path, "", "FILE","SINGLE_SELECT", "", "", sortByLastModified, sortReverseOrder, includePathInValue);
+ FileSystemListParameterDefinition.addTestGC(globalConfigAllowedPaths);
+ FilesLister fl = new FilesLister(pd.getSelectedEnumType(), pd.getRegexIncludePattern(), pd.getRegexExcludePattern(), pd.getPath(), pd.isSortByLastModified(), pd.isSortReverseOrder());
TreeMap map = new TreeMap<>();
String test1 = "test1";
@@ -86,7 +102,7 @@ public void testAlphabeticOrder() {
map.put(f3.getName(), (long) 3);
map.put(f2.getName(), (long) 2);
- List sortedList = pd.sortList(map);
+ List sortedList = fl.sortList(map);
Assert.assertEquals(test1,sortedList.get(0));
Assert.assertEquals(test2,sortedList.get(1));
@@ -100,12 +116,13 @@ public void testGetExistingDefaultValue() throws Exception {
boolean sortByLastModified = false;
boolean sortReverseOrder = false;
- boolean includePathInValue = false;
+ boolean includePathInValue = false;
String includePattern = "";
String excludePattern = "";
String definition_default = "test2.txt";
FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path, definition_default, "FILE","SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder, includePathInValue);
-
+ FileSystemListParameterDefinition.addTestGC(globalConfigAllowedPaths);
+
String result_default = (String) pd.getDefaultParameterValue().getValue();
Assert.assertEquals(definition_default, result_default);
@@ -121,7 +138,7 @@ public void testGetNonExistingDefaultValue() {
String excludePattern = "";
String definition_default = "test4.txt";
FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path, definition_default, "FILE","SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder, includePathInValue);
-
+ FileSystemListParameterDefinition.addTestGC(globalConfigAllowedPaths);
String result_default = (String) pd.getDefaultParameterValue().getValue();
Assert.assertNotEquals(definition_default, result_default);
diff --git a/src/test/java/alex/jenkins/plugins/NotAllowedBaseDirTest.java b/src/test/java/alex/jenkins/plugins/NotAllowedBaseDirTest.java
index 82deb29..af46bb9 100644
--- a/src/test/java/alex/jenkins/plugins/NotAllowedBaseDirTest.java
+++ b/src/test/java/alex/jenkins/plugins/NotAllowedBaseDirTest.java
@@ -50,8 +50,11 @@ public void setup(){
list.add(additionalBaseDirs);
gc.setAdditionalBaseDirs(list);
gc.setEnabledUserContent(true);
+ FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", "path", "", "FILE","SINGLE_SELECT", "", "", false, false, false);
+ pd.getDefaultValue();
+ FileSystemListParameterDefinition.addTestGC(gc);
}
-
+
private String getAbsolutePath(String path) {
URL resource = getClass().getResource(path);
Assert.assertNotNull("Test test directory missing", resource);
@@ -64,19 +67,19 @@ public void testPaths() {
assertFalse(allowedPath.startsWith(notAllowedPath));
}
-
+
@Test
public void testAdditionalBaseDir() {
- assertTrue(FileSystemListParameterDefinition.isAllowedPath(allowedPath, jenkinsTmpRoot, gc));
- assertFalse(FileSystemListParameterDefinition.isAllowedPath(allowedSimilarFile, jenkinsTmpRoot, gc));
- assertFalse(FileSystemListParameterDefinition.isAllowedPath(notAllowedFile, jenkinsTmpRoot, gc));
- assertFalse(FileSystemListParameterDefinition.isAllowedPath(notAllowedSimilarFile, jenkinsTmpRoot, gc));
+ assertTrue(Utils.isAllowedPath(allowedPath, jenkinsTmpRoot, gc));
+ assertFalse(Utils.isAllowedPath(allowedSimilarFile, jenkinsTmpRoot, gc));
+ assertFalse(Utils.isAllowedPath(notAllowedFile, jenkinsTmpRoot, gc));
+ assertFalse(Utils.isAllowedPath(notAllowedSimilarFile, jenkinsTmpRoot, gc));
}
@Test
public void testUserContent() {
- assertTrue(FileSystemListParameterDefinition.isAllowedPath(userContentAllowedFile, jenkinsTmpRoot, gc));
+ assertTrue(Utils.isAllowedPath(userContentAllowedFile, jenkinsTmpRoot, gc));
gc.setEnabledUserContent(false);
- assertFalse(FileSystemListParameterDefinition.isAllowedPath(userContentAllowedFile, jenkinsTmpRoot, gc));
+ assertFalse(Utils.isAllowedPath(userContentAllowedFile, jenkinsTmpRoot, gc));
}
}
diff --git a/src/test/java/alex/jenkins/plugins/RegexFilterTest.java b/src/test/java/alex/jenkins/plugins/RegexFilterTest.java
index 43c2c53..c5d9f98 100644
--- a/src/test/java/alex/jenkins/plugins/RegexFilterTest.java
+++ b/src/test/java/alex/jenkins/plugins/RegexFilterTest.java
@@ -5,87 +5,98 @@
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
public class RegexFilterTest {
+ @Rule
+ public JenkinsRule j = new JenkinsRule();
+
String path;
-
+ FileSystemListParameterGlobalConfiguration globalConfigAllowedPaths;
@Before
- public void setup(){
+ public void setup() {
URL resource = getClass().getResource("/1");
Assert.assertNotNull("Test test directory missing", resource);
path = resource.getPath();
+
+ TestUtils tu = new TestUtils();
+ globalConfigAllowedPaths = tu.createTestGC(path);
}
-
+
@Test
public void testRegexEmptyFilter() throws Exception {
boolean sortByLastModified = false;
boolean sortReverseOrder = false;
- boolean includePathInValue = false;
+ boolean includePathInValue = false;
String includePattern = "";
String excludePattern = "";
- FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path, "", "FILE","SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder, includePathInValue);
-
+ FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path,
+ "", "FILE", "SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder,
+ includePathInValue);
+ FileSystemListParameterDefinition.addTestGC(globalConfigAllowedPaths);
List list = pd.getFsObjectsList();
-
- Assert.assertEquals(3,list.size());
-
+
+ Assert.assertEquals(3, list.size());
+
}
-
-
+
@Test
public void testRegexFilterNotfound() throws Exception {
boolean sortByLastModified = false;
boolean sortReverseOrder = false;
- boolean includePathInValue = false;
+ boolean includePathInValue = false;
String includePattern = "notFound";
String excludePattern = "";
- FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path, "", "FILE","SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder, includePathInValue);
-
+ FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path,
+ "", "FILE", "SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder,
+ includePathInValue);
+ FileSystemListParameterDefinition.addTestGC(globalConfigAllowedPaths);
List list = pd.getFsObjectsList();
-
- Assert.assertEquals(1,list.size());
+
+ Assert.assertEquals(1, list.size());
Assert.assertTrue("Contains no objects found message", list.get(0).contains("No objects of type"));
-
+
}
-
-
+
@Test
public void testRegexIncludeFilter() throws Exception {
boolean sortByLastModified = false;
boolean sortReverseOrder = false;
- boolean includePathInValue = false;
+ boolean includePathInValue = false;
String includePattern = "[\\w]*3[.]txt";
String excludePattern = "";
- FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path, "", "FILE","SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder, includePathInValue);
-
+ FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path,
+ "", "FILE", "SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder,
+ includePathInValue);
+ FileSystemListParameterDefinition.addTestGC(globalConfigAllowedPaths);
List list = pd.getFsObjectsList();
-
- Assert.assertEquals(1,list.size());
- Assert.assertEquals("test3.txt",list.get(0));
-
-
+
+ Assert.assertEquals(1, list.size());
+ Assert.assertEquals("test3.txt", list.get(0));
+
}
-
@Test
public void testRegexExcludeFilter() throws Exception {
boolean sortByLastModified = false;
boolean sortReverseOrder = false;
- boolean includePathInValue = false;
+ boolean includePathInValue = false;
String includePattern = "";
String excludePattern = "[\\w]*3[.]txt";
- FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path, "", "FILE","SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder, includePathInValue);
-
+ FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "master", path,
+ "", "FILE", "SINGLE_SELECT", includePattern, excludePattern, sortByLastModified, sortReverseOrder,
+ includePathInValue);
+ FileSystemListParameterDefinition.addTestGC(globalConfigAllowedPaths);
List list = pd.getFsObjectsList();
-
- Assert.assertEquals(2,list.size());
- Assert.assertEquals("test1.txt",list.get(0));
- Assert.assertEquals("test2.txt",list.get(1));
-
-
+
+ Assert.assertEquals(2, list.size());
+ Assert.assertEquals("test1.txt", list.get(0));
+ Assert.assertEquals("test2.txt", list.get(1));
+
}
-
+
}
diff --git a/src/test/java/alex/jenkins/plugins/TestUtils.java b/src/test/java/alex/jenkins/plugins/TestUtils.java
new file mode 100644
index 0000000..37ba090
--- /dev/null
+++ b/src/test/java/alex/jenkins/plugins/TestUtils.java
@@ -0,0 +1,18 @@
+package alex.jenkins.plugins;
+
+import java.util.List;
+
+import jenkins.model.GlobalConfiguration;
+
+public class TestUtils {
+
+ public FileSystemListParameterGlobalConfiguration createTestGC(String allowedPath) {
+ FileSystemListParameterGlobalConfiguration globalConfigAllowedPaths = new FileSystemListParameterGlobalConfiguration();
+ GlobalConfiguration.all().get(FileSystemListParameterGlobalConfiguration.class);
+ List list = globalConfigAllowedPaths.getAdditionalBaseDirs();
+ AdditionalBaseDirPath additionalBaseDirs = new AdditionalBaseDirPath(allowedPath);
+ list.add(additionalBaseDirs);
+ globalConfigAllowedPaths.setAdditionalBaseDirs(list);
+ return globalConfigAllowedPaths;
+ }
+}