Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-11762] Changes to add a configurable display name to jobs
- Loading branch information
Showing
6 changed files
with
416 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2004-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt, | ||
Yahoo!, Inc. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
--> | ||
|
||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"> | ||
<st:documentation> | ||
Displays a link when given an AbstractItem. It is assumed that that Abstract | ||
Item is passed in ${it} | ||
</st:documentation> | ||
<a href="${it.absoluteUrl}" tooltip="${it.name}">${it.displayName}</a> | ||
</j:jelly> |
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,66 @@ | ||
/** | ||
* | ||
*/ | ||
package hudson.model; | ||
|
||
import java.util.Collection; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author kingfai | ||
* | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public class AbstractItemTest { | ||
|
||
private class StubAbstractItem extends AbstractItem { | ||
|
||
protected StubAbstractItem() { | ||
// sending in null as parent as I don't care for my current tests | ||
super(null, "StubAbatractItem"); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
@Override | ||
public Collection<? extends Job> getAllJobs() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Override save so that nothig happens when setDisplayName() is called | ||
*/ | ||
@Override | ||
public void save() { | ||
|
||
} | ||
} | ||
|
||
@Test | ||
public void testSetDisplayName() throws Exception { | ||
final String displayName = "testDisplayName"; | ||
StubAbstractItem i = new StubAbstractItem(); | ||
i.setDisplayName(displayName); | ||
Assert.assertEquals(displayName, i.getDisplayName()); | ||
} | ||
|
||
@Test | ||
public void testGetDefaultDisplayName() { | ||
final String name = "the item name"; | ||
StubAbstractItem i = new StubAbstractItem(); | ||
i.doSetName(name); | ||
// assert that if the displayname is not set, the name is actually returned | ||
Assert.assertEquals(name, i.getDisplayName()); | ||
|
||
} | ||
|
||
@Test | ||
public void testSearchNameIsName() throws Exception { | ||
final String name = "the item name jlrtlekjtekrjkjr"; | ||
StubAbstractItem i = new StubAbstractItem(); | ||
i.doSetName(name); | ||
|
||
Assert.assertEquals(i.getName(), i.getSearchName()); | ||
} | ||
} |
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,78 @@ | ||
package hudson.model; | ||
|
||
import java.util.SortedMap; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.Test; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
import org.mockito.Mockito; | ||
|
||
public class JobTest { | ||
|
||
private final String DISPLAY_NAME_PARAMETER_NAME = "displayName"; | ||
private final String DEFAULT_STUB_JOB_NAME = "StubJob"; | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
private class StubJob extends Job { | ||
|
||
public StubJob() { | ||
super(null, DEFAULT_STUB_JOB_NAME); | ||
} | ||
|
||
@Override | ||
public boolean isBuildable() { | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
@Override | ||
protected SortedMap _getRuns() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void removeRun(Run run) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
/** | ||
* Override save so that nothig happens when setDisplayName() is called | ||
*/ | ||
@Override | ||
public void save() { | ||
|
||
} | ||
} | ||
|
||
@Test | ||
public void testSetDisplayName() throws Exception { | ||
final String displayName = "testSetDisplayName"; | ||
// create a mock stapler request that returns a display name | ||
StaplerRequest req = Mockito.mock(StaplerRequest.class); | ||
Mockito.when(req.getParameter(DISPLAY_NAME_PARAMETER_NAME)).thenReturn(displayName); | ||
|
||
StubJob j = new StubJob(); | ||
// call setDisplayNameFromRequest | ||
j.setDisplayNameFromRequest(req); | ||
|
||
// make sure the displayname has been set | ||
Assert.assertEquals(displayName, j.getDisplayName()); | ||
} | ||
|
||
@Test | ||
public void testSetDisplayNameZeroLength() throws Exception { | ||
// create a mock stapler request that returns a "" | ||
StaplerRequest req = Mockito.mock(StaplerRequest.class); | ||
Mockito.when(req.getParameter(DISPLAY_NAME_PARAMETER_NAME)).thenReturn(""); | ||
|
||
StubJob j = new StubJob(); | ||
// call setDisplayNameFromRequest | ||
j.setDisplayNameFromRequest(req); | ||
|
||
// make sure the getDisplayName returns the project name | ||
Assert.assertEquals(DEFAULT_STUB_JOB_NAME, j.getDisplayName()); | ||
} | ||
} |
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,68 @@ | ||
package hudson.model; | ||
|
||
import hudson.search.SearchIndex; | ||
import hudson.search.SearchIndexBuilder; | ||
import hudson.search.SearchItem; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class ViewTest { | ||
|
||
/* | ||
* This test verifies that urls and displaynames in the TopLevelItem list | ||
* are added to the SearchIndexBuilder | ||
*/ | ||
@Test | ||
public void testAddDisplayNamesToSearchIndex() { | ||
final String url1 = "url1"; | ||
final String displayName1 = "displayName1"; | ||
final String url2 = "url2"; | ||
final String displayName2 = "displayName2"; | ||
|
||
SearchIndexBuilder sib = new SearchIndexBuilder(); | ||
// mock the items to be indexed | ||
TopLevelItem item1 = Mockito.mock(TopLevelItem.class); | ||
Mockito.when(item1.getSearchUrl()).thenReturn(url1); | ||
Mockito.when(item1.getDisplayName()).thenReturn(displayName1); | ||
TopLevelItem item2 = Mockito.mock(TopLevelItem.class); | ||
Mockito.when(item2.getSearchUrl()).thenReturn(url2); | ||
Mockito.when(item2.getDisplayName()).thenReturn(displayName2); | ||
Collection<TopLevelItem> items = new ArrayList<TopLevelItem>(); | ||
items.add(item1); | ||
items.add(item2); | ||
|
||
// mock the view class except for the addDisplayNamesToSearchIndex() call as that | ||
// is what we are testing | ||
View view = Mockito.mock(View.class); | ||
Mockito.doCallRealMethod().when(view).addDisplayNamesToSearchIndex(sib, items); | ||
|
||
// now make the actual call to index items | ||
view.addDisplayNamesToSearchIndex(sib, items); | ||
|
||
// make and index with sib | ||
SearchIndex index = sib.make(); | ||
|
||
// now make sure we can fetch item1 from the index | ||
List<SearchItem> result = new ArrayList<SearchItem>(); | ||
index.find(displayName1, result); | ||
Assert.assertEquals(1, result.size()); | ||
SearchItem actual = result.get(0); | ||
Assert.assertEquals(actual.getSearchName(), item1.getDisplayName()); | ||
Assert.assertEquals(actual.getSearchUrl(), item1.getSearchUrl()); | ||
|
||
// clear the result array for the next search result to test | ||
result.clear(); | ||
// make sure we can fetch item 2 from the index | ||
index.find(displayName2, result); | ||
Assert.assertEquals(1, result.size()); | ||
actual = result.get(0); | ||
Assert.assertEquals(actual.getSearchName(), item2.getDisplayName()); | ||
Assert.assertEquals(actual.getSearchUrl(), item2.getSearchUrl()); | ||
} | ||
} |
Oops, something went wrong.