Skip to content

Commit

Permalink
Use existing view in the job group test (#440)
Browse files Browse the repository at this point in the history
* Use existing view in the job group test

Restore a loss that I caused in the original test created by @yashpal2104.
Thanks very much to @yashpal2104 for detecting the loss!

* Broaden tests for existing and non-existing views
  • Loading branch information
MarkEWaite authored Jan 11, 2025
1 parent 3128cf1 commit 5232cf8
Showing 1 changed file with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,17 @@ public void descriptorImpl_getPrioritiesReturnsNonEmptyList() {

private final Random random = new Random();

private JobGroup createJobGroup() {
private JobGroup createJobGroup(String viewName) {
JobGroup jobGroup = new JobGroup();
jobGroup.setDescription("testGroup-" + testName.getMethodName());
jobGroup.setRunExclusive(random.nextBoolean());
jobGroup.setUsePriorityStrategies(random.nextBoolean());
jobGroup.setId(random.nextInt());
jobGroup.setJobGroupStrategy(new ViewBasedJobInclusionStrategy("existingView")); // Use the newly created view
jobGroup.setJobGroupStrategy(new ViewBasedJobInclusionStrategy(viewName));
return jobGroup;
}

@Test
public void descriptorImpl_isUsedReturnsTrueWhenJobGroupUsesPriorityStrategies() throws IOException {
public void isUsedWhenViewExists() throws IOException {
// Create a new FreeStyleProject
FreeStyleProject project = j.createFreeStyleProject();

Expand All @@ -103,7 +102,7 @@ public void descriptorImpl_isUsedReturnsTrueWhenJobGroupUsesPriorityStrategies()
// Set up the PriorityJobProperty.DescriptorImpl
PriorityConfiguration configuration = PriorityConfiguration.get();
List<JobGroup> jobGroups = configuration.getJobGroups();
JobGroup jobGroup = createJobGroup();
JobGroup jobGroup = createJobGroup(view.getViewName());
jobGroup.setUsePriorityStrategies(true);

// Add a PriorityStrategyHolder with a JobPropertyStrategy to the JobGroup
Expand All @@ -115,16 +114,36 @@ public void descriptorImpl_isUsedReturnsTrueWhenJobGroupUsesPriorityStrategies()
jobGroups.add(jobGroup);
configuration.setJobGroups(jobGroups);

// Assert the descriptor is used
// Assert the strategy is used when priority strategies are used and view exists
assertTrue(descriptor.isUsed(project));

// Replace the jobGroup with one that does not use priority strategies
jobGroups.remove(jobGroup);
jobGroup.setUsePriorityStrategies(false);
jobGroups.add(jobGroup);
configuration.setJobGroups(jobGroups);

// Assert the strategy is not used when priority strategies are not used even if view exists
assertFalse(descriptor.isUsed(project));
}

@Test
public void descriptorImpl_isUsedReturnsFalseWhenJobGroupDoesNotUsePriorityStrategies() throws IOException {
public void isUsedWhenViewDoesNotExist() throws IOException {
FreeStyleProject project = j.createFreeStyleProject();
PriorityConfiguration configuration = PriorityConfiguration.get();
List<JobGroup> jobGroups = configuration.getJobGroups();
JobGroup jobGroup = createJobGroup();
JobGroup jobGroup = createJobGroup("intentionally-non-existent-view");

// Use priority strategies does not make a non-existing view used
jobGroup.setUsePriorityStrategies(true);
jobGroups.add(jobGroup);
configuration.setJobGroups(jobGroups);
assertFalse(descriptor.isUsed(project));

// Not using priority strategies does not make a non-existing view used
// Replace the jobGroup with one that does not use priority strategies
jobGroups.remove(jobGroup);
jobGroup.setUsePriorityStrategies(false);
jobGroups.add(jobGroup);
configuration.setJobGroups(jobGroups);
assertFalse(descriptor.isUsed(project));
Expand Down

0 comments on commit 5232cf8

Please sign in to comment.