summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-24 02:27:20 (EST)
committer Winston Prakash2011-12-01 20:47:22 (EST)
commit812f429142e77c5ca7a695759d0369f9525b91f6 (patch)
tree919f6b2ce782a97f66cdf1b4dcb8256dd0b89572
parent41d738392261b88dd77df0b3ae15367766e569f7 (diff)
downloadorg.eclipse.hudson.core-812f429142e77c5ca7a695759d0369f9525b91f6.zip
org.eclipse.hudson.core-812f429142e77c5ca7a695759d0369f9525b91f6.tar.gz
org.eclipse.hudson.core-812f429142e77c5ca7a695759d0369f9525b91f6.tar.bz2
Added tests, fixed javadoc.
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/Functions.java4
-rw-r--r--hudson-core/src/test/java/hudson/FunctionsTest.java56
-rw-r--r--hudson-core/src/test/java/hudson/model/FreeStyleProjectMock.java18
3 files changed, 75 insertions, 3 deletions
diff --git a/hudson-core/src/main/java/hudson/Functions.java b/hudson-core/src/main/java/hudson/Functions.java
index b8381a6..ea17615 100644
--- a/hudson-core/src/main/java/hudson/Functions.java
+++ b/hudson-core/src/main/java/hudson/Functions.java
@@ -1434,7 +1434,7 @@ public class Functions {
}
/**
- * Updates the name of the project in the in all children cascading references.
+ * Updates the name of the project in all children cascading references.
* If this project uses some cascading parent, the name of this project will be renamed in the cascading children
* collection of the cascading parent project.
*
@@ -1453,7 +1453,7 @@ public class Functions {
}
/**
- * Updates the name of the project in the in all parent cascading references.
+ * Updates the name of the project in all parent cascading references.
* If this project is used as cascading parent, it's name will be renamed in all children projects.
*
* @param oldName old project name.
diff --git a/hudson-core/src/test/java/hudson/FunctionsTest.java b/hudson-core/src/test/java/hudson/FunctionsTest.java
index bcc6c07..65197f2 100644
--- a/hudson-core/src/test/java/hudson/FunctionsTest.java
+++ b/hudson-core/src/test/java/hudson/FunctionsTest.java
@@ -193,5 +193,61 @@ public class FunctionsTest {
assertTrue(project1.getCascadingChildrenNames().contains(cascadingName));
assertTrue(child1.getCascadingChildrenNames().contains(cascadingName));
}
+
+
+ @Test
+ public void testRenameCascadingChildLinks() {
+ String oldName = "oldCascadingProject";
+ String newName = "newCascadingProject";
+ FreeStyleProject project1 = new FreeStyleProjectMock("project1");
+ FreeStyleProjectMock project2 = new FreeStyleProjectMock("project2");
+ FreeStyleProjectMock project3 = new FreeStyleProjectMock(oldName);
+ project2.setCascadingProject(project1);
+ Functions.linkCascadingProjectsToChild(project1, "project2");
+ project3.setCascadingProject(project2);
+ Functions.linkCascadingProjectsToChild(project2, oldName);
+ assertTrue(project2.getCascadingChildrenNames().contains(oldName));
+ assertTrue(project1.getCascadingChildrenNames().contains(oldName));
+
+ Functions.renameCascadingChildLinks(project2, oldName, newName);
+
+ assertTrue(project2.getCascadingChildrenNames().contains(newName));
+ assertFalse(project2.getCascadingChildrenNames().contains(oldName));
+ assertTrue(project1.getCascadingChildrenNames().contains(newName));
+ assertFalse(project1.getCascadingChildrenNames().contains(oldName));
+ }
+
+
+ @Test
+ @PrepareForTest(Hudson.class)
+ public void testRenameCascadingParentLinks() {
+ String oldName = "oldCascadingProject";
+ String newName = "newCascadingProject";
+ List<Job> jobs = new ArrayList<Job>();
+ FreeStyleProject project1 = new FreeStyleProjectMock(oldName);
+ FreeStyleProjectMock project2 = new FreeStyleProjectMock("child");
+ project2.setCascadingProject(project1);
+ jobs.add(project1);
+ jobs.add(project2);
+ mockStatic(Hudson.class);
+ Hudson hudson = createMock(Hudson.class);
+ expect(hudson.getAllItems(Job.class)).andReturn(jobs);
+ expect(Hudson.getInstance()).andReturn(hudson);
+ replay(Hudson.class, hudson);
+ Functions.renameCascadingParentLinks(oldName, newName);
+ verify(Hudson.class, hudson);
+ assertEquals(newName, project2.getCascadingProjectName());
+ }
+
+ @Test
+ public void testRenameCascadingParentLinksNullNames() {
+ Functions.renameCascadingParentLinks(null, null);
+ }
+
+ @Test
+ public void testRenameCascadingParentLinksEmptyNames() {
+ Functions.renameCascadingParentLinks("", "");
+ }
+
}
diff --git a/hudson-core/src/test/java/hudson/model/FreeStyleProjectMock.java b/hudson-core/src/test/java/hudson/model/FreeStyleProjectMock.java
index b4093a5..222ea73 100644
--- a/hudson-core/src/test/java/hudson/model/FreeStyleProjectMock.java
+++ b/hudson-core/src/test/java/hudson/model/FreeStyleProjectMock.java
@@ -26,6 +26,13 @@ import org.eclipse.hudson.api.model.IProjectProperty;
*/
public class FreeStyleProjectMock extends FreeStyleProject {
+ //TODO find better solution
+ /**
+ * The name of the cascadingProject.
+ */
+ private String cascadingProjectName;
+
+
public FreeStyleProjectMock(String name) {
super((ItemGroup) null, name);
setAllowSave(false);
@@ -42,6 +49,15 @@ public class FreeStyleProjectMock extends FreeStyleProject {
*/
public void setCascadingProject(FreeStyleProject cascadingProject) {
this.cascadingProject = cascadingProject;
+ this.cascadingProjectName = cascadingProject != null ? cascadingProject.getName() : null;
+ }
+
+ public String getCascadingProjectName() {
+ return cascadingProjectName;
+ }
+
+ public void renameCascadingProjectNameTo(String cascadingProjectName) {
+ this.cascadingProjectName = cascadingProjectName;
}
/**
@@ -53,4 +69,4 @@ public class FreeStyleProjectMock extends FreeStyleProject {
public void putJobProperty(String key, IProjectProperty property) {
super.putJobProperty(key, property);
}
-} \ No newline at end of file
+}