Skip to content

Commit

Permalink
JENKINS-7824: Make the unit tests work (!) and order the list of users
Browse files Browse the repository at this point in the history
such that the current user is selected by default
  • Loading branch information
ninian committed Jun 23, 2014
1 parent 8241d95 commit d8d1054
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
28 changes: 23 additions & 5 deletions src/main/java/hudson/plugins/claim/DescribableTestAction.java
Expand Up @@ -3,6 +3,7 @@
import hudson.Extension;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.User;
import hudson.tasks.junit.TestAction;
import hudson.util.ListBoxModel;
Expand Down Expand Up @@ -38,12 +39,29 @@ public ListBoxModel doFillAssigneeItems() {
ListBoxModel items = new ListBoxModel();

// sort in case the users are not already in sort order
// with the current user at the top of the list
String currentUserId = Hudson.getAuthentication().getName();
User currentUser = null;
if (currentUserId != null) {
currentUser = User.get(currentUserId);
}
if (currentUser != null) {
items.add(currentUser.getDisplayName(), currentUser.getId());
}

Collection<User> c = User.getAll();
List<User> l = new ArrayList<User>(c);

Collections.sort(l, comparator);
for (User u : l) {
items.add(u.getDisplayName(), u.getId());
if (c != null && currentUser != null) {
if (c.contains(currentUser)) {
c.remove(currentUser);
}
}

if (c!= null ) {
List<User> l = new ArrayList<User>(c);
Collections.sort(l, comparator);
for (User u : l) {
items.add(u.getDisplayName(), u.getId());
}
}

return items;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/hudson/plugins/claim/ClaimReportTest.java
Expand Up @@ -52,6 +52,7 @@ private FreeStyleProject createFailingJobWithName(String jobName) throws IOExcep
public void job_is_visible_in_claim_report() throws Exception {
// Given:
view.add(job);
//j.interactiveBreak();
// When:
HtmlPage page = j.createWebClient().goTo("claims/");
// Then:
Expand Down
24 changes: 16 additions & 8 deletions src/test/java/hudson/plugins/claim/ClaimTest.java
Expand Up @@ -23,21 +23,25 @@
*/
package hudson.plugins.claim;

import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import hudson.model.Build;
import hudson.model.Project;
import hudson.security.FullControlOnceLoggedInAuthorizationStrategy;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.FailureBuilder;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlOption;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;

public class ClaimTest {

Expand Down Expand Up @@ -176,7 +180,11 @@ private ClaimBuildAction applyClaim(String claimElement, String assignee, String

form.getTextAreaByName("reason").setText(reason);
if ( assignee!=null ) {
j.last(form.getInputsByName("assignee")).setValueAttribute(assignee);
HtmlSelect select = form.getSelectByName("_.assignee");
if (! assignee.isEmpty()) {
HtmlOption option = select.getOptionByValue(assignee);
select.setSelectedAttribute(option, true);
}
}

form.submit((HtmlButton) j.last(form.getHtmlElementsByTagName("button")));
Expand Down

0 comments on commit d8d1054

Please sign in to comment.