Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing view in the job group test #440

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading