mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
[JENKINS-11762] Fix displayname issues when renaming or cloning a job. We now clear the display name when cloning or renaming a job.
This commit is contained in:
1 parent
484d952029
commit
efcdf14ccb
5 files changed
+330
-36
No files matched your search
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2004-2011, 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.
|
||||
*/
|
||||
package hudson.model;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class DisplayNameListenerTest {
|
||||
|
||||
@Test
|
||||
public void testOnCopied() throws Exception {
|
||||
DisplayNameListener listener = new DisplayNameListener();
|
||||
StubJob src = new StubJob();
|
||||
src.doSetName("src");
|
||||
StubJob dest = new StubJob();
|
||||
dest.doSetName("dest");
|
||||
dest.setDisplayName("this should be cleared");
|
||||
|
||||
// make sure the displayname and the name are different at this point
|
||||
Assert.assertFalse(dest.getName().equals(dest.getDisplayName()));
|
||||
|
||||
listener.onCopied(src, dest);
|
||||
// make sure the displayname is equals to the name as it should be null
|
||||
Assert.assertEquals(dest.getName(), dest.getDisplayName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnRenamedOldNameEqualsDisplayName() throws Exception {
|
||||
DisplayNameListener listener = new DisplayNameListener();
|
||||
final String oldName = "old job name";
|
||||
final String newName = "new job name";
|
||||
StubJob src = new StubJob();
|
||||
src.doSetName(newName);
|
||||
src.setDisplayName(oldName);
|
||||
|
||||
listener.onRenamed(src, oldName, newName);
|
||||
|
||||
Assert.assertEquals(newName, src.getDisplayName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnRenamedOldNameNotEqualDisplayName() throws Exception {
|
||||
DisplayNameListener listener = new DisplayNameListener();
|
||||
final String oldName = "old job name";
|
||||
final String newName = "new job name";
|
||||
final String displayName = "the display name";
|
||||
StubJob src = new StubJob();
|
||||
src.doSetName(newName);
|
||||
src.setDisplayName(displayName);
|
||||
|
||||
listener.onRenamed(src, oldName, oldName);
|
||||
|
||||
// make sure displayname is still intact
|
||||
Assert.assertEquals(displayName, src.getDisplayName());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package hudson.model;
|
||||
|
||||
import java.util.SortedMap;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
@@ -11,41 +10,7 @@ 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 {
|
||||
@@ -73,6 +38,6 @@ public class JobTest {
|
||||
j.setDisplayNameFromRequest(req);
|
||||
|
||||
// make sure the getDisplayName returns the project name
|
||||
Assert.assertEquals(DEFAULT_STUB_JOB_NAME, j.getDisplayName());
|
||||
Assert.assertEquals(StubJob.DEFAULT_STUB_JOB_NAME, j.getDisplayName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2004-2011, 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.
|
||||
*/
|
||||
package hudson.model;
|
||||
|
||||
import java.util.SortedMap;
|
||||
|
||||
/**
|
||||
* @author kingfai
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
class StubJob extends Job {
|
||||
|
||||
public final static String DEFAULT_STUB_JOB_NAME = "StubJob";
|
||||
|
||||
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() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user