Skip to content
Permalink
Browse files
JENKINS-7824: Make the unit tests work (!) and order the list of users
such that the current user is selected by default
  • Loading branch information
ninian committed Jun 23, 2014
1 parent 8241d95 commit d8d105492041032941760adf256642236cffd557
Showing 3 changed files with 40 additions and 13 deletions.
@@ -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;
@@ -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;
@@ -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:
@@ -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 {

@@ -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")));

0 comments on commit d8d1054

Please sign in to comment.