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

Add test for JobInclusionFolderProperty class #416

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3814.v9563d972079a_</version>
<version>3850.vb_c5319efa_e29</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/jenkins/advancedqueue/sorter/ItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
this.itemStatus = ItemStatus.WAITING;
}

public ItemInfo(Item item, int priority) {
this.itemId = item.getId();
this.inQueueSince = item.getInQueueSince();
this.jobName = item.task.getName();
this.itemStatus = ItemStatus.WAITING;
}

Check warning on line 78 in src/main/java/jenkins/advancedqueue/sorter/ItemInfo.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 73-78 are not covered by tests

public PriorityConfigurationCallback setPrioritySelection(int priority, int jobGroupId, PriorityStrategy reason) {
this.priority = priority;
this.jobGroupId = jobGroupId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package jenkins.advancedqueue.jobinclusion.strategy;

import static org.junit.Assert.*;

import hudson.model.FreeStyleProject;
import hudson.model.Queue;
import jenkins.advancedqueue.jobrestrictions.PrioritySorterRestriction;
import jenkins.advancedqueue.sorter.ItemInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

public class JobInclusionFolderPropertyTest {
@Rule
public JenkinsRule jenkinsRule = new JenkinsRule();

private static ItemInfo itemInfo;
private PrioritySorterRestriction restriction;
private static final int LOWER_PRIORITY = 1;
private static FreeStyleProject j;
private static JobInclusionFolderProperty property;

@Before
public void setUp() throws Exception {
j = jenkinsRule.createFreeStyleProject();
j.scheduleBuild2(0).get(); // Schedule a build to ensure the queue item is created
property = new JobInclusionFolderProperty(true, "testGroup");

// Ensure the custom QueueSorter is used
j.getDescriptor();

Queue.Item queueItem = j.getQueueItem();
assertNull("Queue.Item should be null", queueItem);

if (queueItem != null) {
itemInfo = new ItemInfo(queueItem, LOWER_PRIORITY);
}
}

@After
public void tearDown() throws Exception {}

@Test
public void testGetJobGroupName() {
assertEquals("testGroup", property.getJobGroupName());
}

@Test
public void testIsUseJobGroup() {
assertTrue(property.isUseJobGroup());
}

@Test
public void testGetDescriptor() {
assertNotNull(property.getDescriptor());
}

@Test
public void testDescriptorImpl() {
JobInclusionFolderProperty.DescriptorImpl descriptor = new JobInclusionFolderProperty.DescriptorImpl();
assertEquals("XXX", descriptor.getDisplayName());
assertNotNull(descriptor.getJobGroups());
assertFalse(descriptor.isUsed());
}

@Test
public void testAllJobsJobInclusionStrategy() {
AllJobsJobInclusionStrategy strategy = new AllJobsJobInclusionStrategy();
assertTrue(strategy.contains(null, j));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package jenkins.advancedqueue.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import hudson.util.ListBoxModel;
import org.junit.Test;

public class PrioritySorterUtilTest {

@Test
public void assertPriorityItemsHasExpectedSize() {
ListBoxModel testList = PrioritySorterUtil.fillPriorityItems(3);
assertEquals(3, testList.size());
}

@Test
public void assertEmptyListWhenToParameterIsZero() {
ListBoxModel testList = PrioritySorterUtil.fillPriorityItems(0);
assertTrue(testList.isEmpty());
}
}
Loading