Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-47437] Allow sorting of users by their full name in the clai…
…m page.
- Loading branch information
Showing
7 changed files
with
129 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
1 change: 1 addition & 0 deletions
1
src/main/resources/hudson/plugins/claim/ClaimConfig/config.properties
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
SendEmails=Send emails when assigning/claiming builds | ||
StickyByDefault=Sets the default value for stickiness when claiming builds | ||
SortUsersByFullName=Sorts the users by their name rather than they ids when listing them | ||
GroovyScript=The Groovy script to run when claims are changed |
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,3 @@ | ||
<div> | ||
Checking this option will make users by sorted by their full name rather than id in the claim dialog user list. | ||
</div> |
84 changes: 84 additions & 0 deletions
84
src/test/java/hudson/plugins/claim/DescribableTestActionTest.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,84 @@ | ||
package hudson.plugins.claim; | ||
|
||
import hudson.model.User; | ||
import hudson.security.FullControlOnceLoggedInAuthorizationStrategy; | ||
import hudson.util.ListBoxModel; | ||
import jenkins.model.GlobalConfiguration; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
public class DescribableTestActionTest { | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
private User user0; | ||
private User user1; | ||
private User user2; | ||
private User user3; | ||
private User user4; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
j.jenkins.setAuthorizationStrategy(new FullControlOnceLoggedInAuthorizationStrategy()); | ||
j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); | ||
JenkinsRule.WebClient wc = j.createWebClient(); | ||
wc.login("user0", "user0"); | ||
wc.login("user1", "user1"); | ||
wc.login("user2", "user2"); | ||
wc.login("user3", "user3"); | ||
wc.login("user4", "user4"); | ||
wc.closeAllWindows(); | ||
|
||
(user0 = j.jenkins.getUser("user0")).setFullName("T-800"); | ||
(user1 = j.jenkins.getUser("user1")).setFullName("Sarah CONNOR"); | ||
(user2 = j.jenkins.getUser("user2")).setFullName("John CONNOR"); | ||
(user3 = j.jenkins.getUser("user3")).setFullName("Kyle REESE"); | ||
(user4 = j.jenkins.getUser("user4")).setFullName("T-800"); | ||
} | ||
|
||
private static class DescribableTestActionImpl extends DescribableTestAction | ||
{ | ||
@Override | ||
public String getIconFileName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getUrlName() { | ||
return null; | ||
} | ||
} | ||
|
||
@Test | ||
public void assignee_list_is_sorted_by_id_by_default() { | ||
DescribableTestActionImpl.DescriptorImpl descriptor = new DescribableTestActionImpl.DescriptorImpl(); | ||
ListBoxModel items = descriptor.doFillAssigneeItems(); | ||
Object[] users = getUsers(items); | ||
assertArrayEquals(new String[] {"SYSTEM", user0.getId(), user1.getId(), user2.getId(), user3.getId(), user4.getId()}, users); | ||
} | ||
|
||
@Test | ||
public void assignee_list_full_name_sorts_by_fullName_then_id() { | ||
DescribableTestActionImpl.DescriptorImpl descriptor = new DescribableTestActionImpl.DescriptorImpl(); | ||
((ClaimConfig)j.jenkins.getDescriptor(ClaimConfig.class)).setSortUsersByFullName(true); | ||
ListBoxModel items = descriptor.doFillAssigneeItems(); | ||
Object[] users = getUsers(items); | ||
assertArrayEquals(new String[] {"SYSTEM", user2.getId(), user3.getId(), user1.getId(), user0.getId(), user4.getId()}, users); | ||
} | ||
|
||
private String[] getUsers(ListBoxModel items) { | ||
return items.stream().map(o -> o.value).toArray(String[]::new); | ||
} | ||
} |