Skip to content
Permalink
Browse files

[JENKINS-22318] Added tests for empty choice in FilenameChoiceListPro…

…vider.
  • Loading branch information
ikedam committed Apr 29, 2015
1 parent d1674e4 commit cb7d9e3af64dce10af4103c3ad0f623ff57a49ea
@@ -24,7 +24,8 @@
package jp.ikedam.jenkins.plugins.extensible_choice_parameter;

import static org.junit.Assert.*;

import hudson.model.FreeStyleProject;
import hudson.model.ParametersDefinitionProperty;
import hudson.util.FormValidation;

import java.io.File;
@@ -70,6 +71,77 @@ public void testGetBaseDir()
return (FilenameChoiceListProvider.DescriptorImpl)Jenkins.getInstance().getDescriptor(FilenameChoiceListProvider.class);
}

@Test
public void testConfiguration() throws Exception
{
{
FreeStyleProject p = j.createFreeStyleProject();
FilenameChoiceListProvider expected = new FilenameChoiceListProvider(
"/some/path",
"**/*",
"**/*.java",
FilenameChoiceListProvider.ScanType.File,
false,
FilenameChoiceListProvider.EmptyChoiceType.None
);
p.addProperty(new ParametersDefinitionProperty(new ExtensibleChoiceParameterDefinition(
"Choice",
expected,
false,
""
)));
j.submit(j.createWebClient().getPage(p, "configure").getFormByName("config"));
j.assertEqualDataBoundBeans(
expected,
((ExtensibleChoiceParameterDefinition)p.getProperty(ParametersDefinitionProperty.class).getParameterDefinition("Choice")).getChoiceListProvider()
);
}
{
FreeStyleProject p = j.createFreeStyleProject();
FilenameChoiceListProvider expected = new FilenameChoiceListProvider(
"C:\\some\\path",
"**/*.java",
"**/*Test.java",
FilenameChoiceListProvider.ScanType.Directory,
true,
FilenameChoiceListProvider.EmptyChoiceType.AtTop
);
p.addProperty(new ParametersDefinitionProperty(new ExtensibleChoiceParameterDefinition(
"Choice",
expected,
false,
""
)));
j.submit(j.createWebClient().getPage(p, "configure").getFormByName("config"));
j.assertEqualDataBoundBeans(
expected,
((ExtensibleChoiceParameterDefinition)p.getProperty(ParametersDefinitionProperty.class).getParameterDefinition("Choice")).getChoiceListProvider()
);
}
{
FreeStyleProject p = j.createFreeStyleProject();
FilenameChoiceListProvider expected = new FilenameChoiceListProvider(
"relative/path",
"**/*",
"",
FilenameChoiceListProvider.ScanType.FileAndDirectory,
true,
FilenameChoiceListProvider.EmptyChoiceType.AtEnd
);
p.addProperty(new ParametersDefinitionProperty(new ExtensibleChoiceParameterDefinition(
"Choice",
expected,
false,
""
)));
j.submit(j.createWebClient().getPage(p, "configure").getFormByName("config"));
j.assertEqualDataBoundBeans(
expected,
((ExtensibleChoiceParameterDefinition)p.getProperty(ParametersDefinitionProperty.class).getParameterDefinition("Choice")).getChoiceListProvider()
);
}
}

@Test
public void testDescriptor_doCheckBaseDirPath() throws IOException
{
@@ -34,6 +34,7 @@
import org.apache.commons.io.FileUtils;
import org.junit.Test;

import jp.ikedam.jenkins.plugins.extensible_choice_parameter.FilenameChoiceListProvider.EmptyChoiceType;
import jp.ikedam.jenkins.plugins.extensible_choice_parameter.FilenameChoiceListProvider.ScanType;

/**
@@ -161,10 +162,17 @@ public void testFilenameChoiceListProvider()
{
private static final long serialVersionUID = 5830671030985340194L;

public FilenameChoiceListProviderForTest(String baseDirPath,
String includePattern, String excludePattern, ScanType scanType, boolean reverseOrder,
EmptyChoiceType emptyChoideType)
{
super(baseDirPath, includePattern, excludePattern, scanType, reverseOrder, emptyChoideType);
}

public FilenameChoiceListProviderForTest(String baseDirPath,
String includePattern, String excludePattern, ScanType scanType, boolean reverseOrder)
{
super(baseDirPath, includePattern, excludePattern, scanType, reverseOrder);
this(baseDirPath, includePattern, excludePattern, scanType, reverseOrder, null);
}

public static List<String> getFileList(
@@ -538,6 +546,120 @@ public void testGetFileList() throws IOException
);
assertFileListEquals("null for scanType", expected, fileList);
}

// No empty choice.
{
List<String> expected = Arrays.asList(
"test1.txt",
"test2.dat",
"dir1",
"dir1/test3.txt",
"dir2",
"dir2/dir3",
"dir2/dir3/test4.dat"
);
List<String> fileList = FilenameChoiceListProviderForTest.getFileList(
tempDir,
"**/*",
"",
ScanType.FileAndDirectory,
false,
EmptyChoiceType.None
);
assertFileListEquals("No empty choice", expected, fileList);
}

// Empty choice at the top.
{
List<String> expected = Arrays.asList(
"",
"test1.txt",
"test2.dat",
"dir1",
"dir1/test3.txt",
"dir2",
"dir2/dir3",
"dir2/dir3/test4.dat"
);
List<String> fileList = FilenameChoiceListProviderForTest.getFileList(
tempDir,
"**/*",
"",
ScanType.FileAndDirectory,
false,
EmptyChoiceType.AtTop
);
assertFileListEquals("Empty choice at the top", expected, fileList);
}

// Empty choice at the end.
{
List<String> expected = Arrays.asList(
"test1.txt",
"test2.dat",
"dir1",
"dir1/test3.txt",
"dir2",
"dir2/dir3",
"dir2/dir3/test4.dat",
""
);
List<String> fileList = FilenameChoiceListProviderForTest.getFileList(
tempDir,
"**/*",
"",
ScanType.FileAndDirectory,
false,
EmptyChoiceType.AtEnd
);
assertFileListEquals("Empty choice at the end", expected, fileList);
}

// Empty choice at the top and reversed
{
List<String> expected = Arrays.asList(
"",
"dir2/dir3/test4.dat",
"dir2/dir3",
"dir2",
"dir1/test3.txt",
"dir1",
"test2.dat",
"test1.txt"
);
List<String> fileList = FilenameChoiceListProviderForTest.getFileList(
tempDir,
"**/*",
"",
ScanType.FileAndDirectory,
true,
EmptyChoiceType.AtTop
);
assertFileListEquals("Empty choice at the top and reversed", expected, fileList);
}

// Empty choice at the end and reversed.
{
List<String> expected = Arrays.asList(
"dir2/dir3/test4.dat",
"dir2/dir3",
"dir2",
"dir1/test3.txt",
"dir1",
"test2.dat",
"test1.txt",
""
);
List<String> fileList = FilenameChoiceListProviderForTest.getFileList(
tempDir,
"**/*",
"",
ScanType.FileAndDirectory,
true,
EmptyChoiceType.AtEnd
);
assertFileListEquals("Empty choice at the end and reversed", expected, fileList);
}
}
finally
{

0 comments on commit cb7d9e3

Please sign in to comment.
You can’t perform that action at this time.