@Test @PrepareForTest(Hudson.class) public void testRenameCascadingParentLinks() throws Exception { 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); CascadingUtil.renameCascadingParentLinks(oldName, newName); verify(Hudson.class, hudson); assertEquals(newName, project2.getCascadingProjectName()); }
public static void renameCascadingParentLinks(final String oldName, final String newName) { if (StringUtils.isBlank(newName) || StringUtils.isBlank(oldName)) { return; } for (Job job : Hudson.getInstance().getAllItems(Job.class)) { if (oldName.equals(job.getCascadingProjectName())) { job.renameCascadingProjectNameTo(newName); } } }
CascadingUtil { public static void renameCascadingParentLinks(final String oldName, final String newName) { if (StringUtils.isBlank(newName) || StringUtils.isBlank(oldName)) { return; } for (Job job : Hudson.getInstance().getAllItems(Job.class)) { if (oldName.equals(job.getCascadingProjectName())) { job.renameCascadingProjectNameTo(newName); } } } }
CascadingUtil { public static void renameCascadingParentLinks(final String oldName, final String newName) { if (StringUtils.isBlank(newName) || StringUtils.isBlank(oldName)) { return; } for (Job job : Hudson.getInstance().getAllItems(Job.class)) { if (oldName.equals(job.getCascadingProjectName())) { job.renameCascadingProjectNameTo(newName); } } }  }
CascadingUtil { public static void renameCascadingParentLinks(final String oldName, final String newName) { if (StringUtils.isBlank(newName) || StringUtils.isBlank(oldName)) { return; } for (Job job : Hudson.getInstance().getAllItems(Job.class)) { if (oldName.equals(job.getCascadingProjectName())) { job.renameCascadingProjectNameTo(newName); } } }  static IProjectProperty getProjectProperty(Job currentJob, String key); static StringProjectProperty getStringProjectProperty(Job currentJob, String key); static BaseProjectProperty getBaseProjectProperty(Job currentJob, String key); static ExternalProjectProperty getExternalProjectProperty(Job currentJob, String key); static CopyOnWriteListProjectProperty getCopyOnWriteListProjectProperty(Job currentJob, String key); static ResultProjectProperty getResultProjectProperty(Job currentJob, String key); static BooleanProjectProperty getBooleanProjectProperty(Job currentJob, String key); static IntegerProjectProperty getIntegerProjectProperty(Job currentJob, String key); static LogRotatorProjectProperty getLogRotatorProjectProperty(Job currentJob, String key); static DescribableListProjectProperty getDescribableListProjectProperty(Job currentJob, String key); static AxisListProjectProperty getAxesListProjectProperty(Job currentJob, String key); static SCMProjectProperty getScmProjectProperty(Job currentJob, String key); static TriggerProjectProperty getTriggerProjectProperty(Job currentJob, String key); @SuppressWarnings("unchecked") static T getProjectProperty(ICascadingJob currentJob, String key, Class<T> clazz); @SuppressWarnings("unchecked") static boolean hasCyclicCascadingLink(Job cascadingCandidate, Set<String> cascadingChildren); static boolean unlinkProjectFromCascadingParents(ICascadingJob cascadingProject, String projectToUnlink); static void linkCascadingProjectsToChild(ICascadingJob cascadingProject, String childProjectName); static void renameCascadingChildLinks(ICascadingJob cascadingProject, String oldName, String newName); static void renameCascadingParentLinks(final String oldName, final String newName); @SuppressWarnings("unchecked") static List<Job> getCascadingParents(Class<T> type, Job currentJob); @SuppressWarnings("unchecked") static void buildExternalProperties(StaplerRequest req, JSONObject json,
                                                                          List<Descriptor<T>> descriptors, Job owner); @SuppressWarnings("unchecked") static void setChildrenTrigger(Job job, TriggerDescriptor descriptor, String key, StaplerRequest req,
                                          JSONObject json); @SuppressWarnings("unchecked") static void setParameterDefinitionProperties(Job job,
                                                        String key,
                                                        CopyOnWriteList<ParametersDefinitionProperty> parameterDefinitionProperties); static boolean isCascadableJobProperty(JobPropertyDescriptor d); }
CascadingUtil { public static void renameCascadingParentLinks(final String oldName, final String newName) { if (StringUtils.isBlank(newName) || StringUtils.isBlank(oldName)) { return; } for (Job job : Hudson.getInstance().getAllItems(Job.class)) { if (oldName.equals(job.getCascadingProjectName())) { job.renameCascadingProjectNameTo(newName); } } }  static IProjectProperty getProjectProperty(Job currentJob, String key); static StringProjectProperty getStringProjectProperty(Job currentJob, String key); static BaseProjectProperty getBaseProjectProperty(Job currentJob, String key); static ExternalProjectProperty getExternalProjectProperty(Job currentJob, String key); static CopyOnWriteListProjectProperty getCopyOnWriteListProjectProperty(Job currentJob, String key); static ResultProjectProperty getResultProjectProperty(Job currentJob, String key); static BooleanProjectProperty getBooleanProjectProperty(Job currentJob, String key); static IntegerProjectProperty getIntegerProjectProperty(Job currentJob, String key); static LogRotatorProjectProperty getLogRotatorProjectProperty(Job currentJob, String key); static DescribableListProjectProperty getDescribableListProjectProperty(Job currentJob, String key); static AxisListProjectProperty getAxesListProjectProperty(Job currentJob, String key); static SCMProjectProperty getScmProjectProperty(Job currentJob, String key); static TriggerProjectProperty getTriggerProjectProperty(Job currentJob, String key); @SuppressWarnings("unchecked") static T getProjectProperty(ICascadingJob currentJob, String key, Class<T> clazz); @SuppressWarnings("unchecked") static boolean hasCyclicCascadingLink(Job cascadingCandidate, Set<String> cascadingChildren); static boolean unlinkProjectFromCascadingParents(ICascadingJob cascadingProject, String projectToUnlink); static void linkCascadingProjectsToChild(ICascadingJob cascadingProject, String childProjectName); static void renameCascadingChildLinks(ICascadingJob cascadingProject, String oldName, String newName); static void renameCascadingParentLinks(final String oldName, final String newName); @SuppressWarnings("unchecked") static List<Job> getCascadingParents(Class<T> type, Job currentJob); @SuppressWarnings("unchecked") static void buildExternalProperties(StaplerRequest req, JSONObject json,
                                                                          List<Descriptor<T>> descriptors, Job owner); @SuppressWarnings("unchecked") static void setChildrenTrigger(Job job, TriggerDescriptor descriptor, String key, StaplerRequest req,
                                          JSONObject json); @SuppressWarnings("unchecked") static void setParameterDefinitionProperties(Job job,
                                                        String key,
                                                        CopyOnWriteList<ParametersDefinitionProperty> parameterDefinitionProperties); static boolean isCascadableJobProperty(JobPropertyDescriptor d);  }