-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into job-inclusion-job-property-test
- Loading branch information
Showing
2 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
...java/jenkins/advancedqueue/jobinclusion/strategy/FolderBasedJobInclusionStrategyTest.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,120 @@ | ||
package jenkins.advancedqueue.jobinclusion.strategy; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.cloudbees.hudson.plugins.folder.Folder; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.util.ListBoxModel; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import jenkins.advancedqueue.DecisionLogger; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class FolderBasedJobInclusionStrategyTest { | ||
|
||
@ClassRule | ||
public static JenkinsRule j = new JenkinsRule(); | ||
|
||
private static FolderBasedJobInclusionStrategy strategy; | ||
private static DecisionLogger decisionLogger; | ||
private static List<String> loggedMessages; | ||
|
||
@BeforeClass | ||
public static void createStrategy() throws Exception { | ||
strategy = new FolderBasedJobInclusionStrategy("testFolder"); | ||
} | ||
|
||
@BeforeClass | ||
public static void createDecisionLogger() throws Exception { | ||
decisionLogger = new DecisionLogger() { | ||
@Override | ||
public DecisionLogger addDecisionLog(int indent, String log) { | ||
loggedMessages.add(log); | ||
return this; | ||
} | ||
}; | ||
} | ||
|
||
@Before | ||
public void clearLoggedMessages() throws Exception { | ||
loggedMessages = new ArrayList<>(); | ||
} | ||
|
||
@After | ||
public void checkLoggedMessages() throws Exception { | ||
assertThat(loggedMessages, is(empty())); | ||
} | ||
|
||
@Test | ||
public void getDescriptor() { | ||
assertNotNull(strategy.getDescriptor()); | ||
assertTrue( | ||
strategy.getDescriptor() | ||
instanceof FolderBasedJobInclusionStrategy.FolderBasedJobInclusionStrategyDescriptor); | ||
} | ||
|
||
@Test | ||
public void all() { | ||
assertFalse(FolderBasedJobInclusionStrategy.all().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void getFolderName() { | ||
assertEquals("testFolder", strategy.getFolderName()); | ||
} | ||
|
||
@Test | ||
public void contains() throws Exception { | ||
FreeStyleProject project = this.j.createFreeStyleProject("testFolder_jobName"); | ||
|
||
assertTrue(strategy.contains(decisionLogger, project)); | ||
} | ||
|
||
@Test | ||
public void containsReturnsFalseForJobNotInFolder() throws Exception { | ||
FreeStyleProject project = j.createFreeStyleProject("otherFolder_jobName"); | ||
|
||
assertFalse(strategy.contains(decisionLogger, project)); | ||
} | ||
|
||
@Test | ||
public void containsReturnsTrueForJobInSubFolder() throws Exception { | ||
FreeStyleProject project = j.createFreeStyleProject("testFolder_subFolder_jobName"); | ||
|
||
assertTrue(strategy.contains(decisionLogger, project)); | ||
} | ||
|
||
@Test | ||
public void getListFolderItemsReturnsNonNullListBoxModel() { | ||
FolderBasedJobInclusionStrategy.FolderBasedJobInclusionStrategyDescriptor descriptor = | ||
new FolderBasedJobInclusionStrategy.FolderBasedJobInclusionStrategyDescriptor(); | ||
ListBoxModel items = descriptor.getListFolderItems(); | ||
assertNotNull(items); | ||
} | ||
|
||
@Test | ||
public void getListFolderItemsReturnsCorrectFolderNames() throws Exception { | ||
|
||
j.jenkins.createProject(Folder.class, "folder1"); | ||
j.jenkins.createProject(Folder.class, "folder2"); | ||
|
||
FolderBasedJobInclusionStrategy.FolderBasedJobInclusionStrategyDescriptor descriptor = | ||
new FolderBasedJobInclusionStrategy.FolderBasedJobInclusionStrategyDescriptor(); | ||
ListBoxModel items = descriptor.getListFolderItems(); | ||
|
||
assertEquals(2, items.size()); | ||
assertEquals("folder1", items.get(0).name); | ||
assertEquals("folder2", items.get(1).name); | ||
} | ||
} |
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