Skip to content

Commit

Permalink
[JENKINS-40718] Consider insensitiveSearch user configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Zajączkowski committed Feb 1, 2017
1 parent 785a8cf commit 0a221d0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/src/main/java/jenkins/widgets/HistoryPageFilter.java
Expand Up @@ -31,6 +31,7 @@
import hudson.model.ParametersAction;
import hudson.model.Queue;
import hudson.model.Run;
import hudson.search.UserSearchProperty;
import hudson.widgets.HistoryWidget;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -365,15 +366,19 @@ private boolean fitsSearchString(Object data) {
return true;
}

if (data != null) {
if (data instanceof Number) {
return data.toString().equals(searchString);
} else {
if (data == null) {
return false;
}

if (data instanceof Number) {
return data.toString().equals(searchString);
} else {
if (UserSearchProperty.isCaseInsensitive()) {
return data.toString().toLowerCase().contains(searchString.toLowerCase());
} else {
return data.toString().contains(searchString);
}
}

return false;
}

private boolean fitsSearchBuildVariables(AbstractBuild<?, ?> runAsBuild) {
Expand Down
22 changes: 22 additions & 0 deletions core/src/test/java/jenkins/widgets/HistoryPageFilterTest.java
Expand Up @@ -37,6 +37,7 @@
import hudson.model.StringParameterValue;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;

Expand Down Expand Up @@ -323,8 +324,27 @@ public void test_search_runs_by_build_number() throws IOException {
}

@Test
public void test_search_should_be_case_sensitive_for_anonymous_user() throws IOException {
//given
HistoryPageFilter<ModelObject> historyPageFilter = newPage(5, null, null);
//and
historyPageFilter.setSearchString("failure");
//and
List<ModelObject> runs = Lists.<ModelObject>newArrayList(new MockRun(2, Result.FAILURE), new MockRun(1, Result.SUCCESS));
List<Queue.Item> queueItems = newQueueItems(3, 4);

//when
historyPageFilter.add(runs, queueItems);

//then
Assert.assertEquals(0, historyPageFilter.runs.size());
}

@Test
@Ignore //User with insensitiveSearch enabled needs to be injected
public void test_search_runs_by_build_result() throws IOException {
//given
//TODO: Set user with insensitiveSearch enabled
HistoryPageFilter<ModelObject> historyPageFilter = newPage(5, null, null);
//and
historyPageFilter.setSearchString("failure");
Expand All @@ -341,8 +361,10 @@ public void test_search_runs_by_build_result() throws IOException {
}

@Test
@Ignore //User with insensitiveSearch enabled needs to be injected
public void test_case_insensitivity_in_search_runs() throws IOException {
//given
//TODO: Set user with insensitiveSearch enabled
HistoryPageFilter<ModelObject> historyPageFilter = newPage(5, null, null);
List<ModelObject> runs = Lists.<ModelObject>newArrayList(new MockRun(2, Result.FAILURE), new MockRun(1, Result.SUCCESS));
List<Queue.Item> queueItems = newQueueItems(3, 4);
Expand Down

0 comments on commit 0a221d0

Please sign in to comment.