@Test @PrepareForTest(Hudson.class) public void testUnlinkProjectFromCascadingParents() throws Exception { FreeStyleProject project1 = new FreeStyleProjectMock("project1"); FreeStyleProjectMock child1 = new FreeStyleProjectMock("child1"); String cascadingName = "newCascadingProject"; FreeStyleProjectMock child = new FreeStyleProjectMock(cascadingName); child1.setCascadingProject(project1); CascadingUtil.linkCascadingProjectsToChild(child1, cascadingName); List<Job> jobs = new ArrayList<Job>(); jobs.add(project1); jobs.add(child1); jobs.add(child); Hudson hudson = createMock(Hudson.class); mockStatic(Hudson.class); expect(hudson.getAllItems(Job.class)).andReturn(jobs).anyTimes(); expect(Hudson.getInstance()).andReturn(hudson).anyTimes(); replay(Hudson.class, hudson); assertFalse(CascadingUtil.unlinkProjectFromCascadingParents(null, cascadingName)); assertFalse(CascadingUtil.unlinkProjectFromCascadingParents(project1, null)); assertTrue(project1.getCascadingChildrenNames().contains(cascadingName)); assertTrue(child1.getCascadingChildrenNames().contains(cascadingName)); boolean result = CascadingUtil.unlinkProjectFromCascadingParents(child1, cascadingName); assertTrue(result); assertFalse(project1.getCascadingChildrenNames().contains(cascadingName)); assertFalse(child1.getCascadingChildrenNames().contains(cascadingName)); CascadingUtil.linkCascadingProjectsToChild(project1, cascadingName); assertTrue(project1.getCascadingChildrenNames().contains(cascadingName)); result = CascadingUtil.unlinkProjectFromCascadingParents(child1, cascadingName); assertTrue(result); assertFalse(project1.getCascadingChildrenNames().contains(cascadingName)); }
public static boolean unlinkProjectFromCascadingParents(ICascadingJob cascadingProject, String projectToUnlink) throws IOException { if (null != cascadingProject && null != projectToUnlink) { Job job = Functions.getItemByName(Hudson.getInstance().getAllItems(Job.class), projectToUnlink); if (null != job) { Set<String> set = new HashSet<String>(job.getCascadingChildrenNames()); set.add(projectToUnlink); return unlinkProjectFromCascadingParents(cascadingProject, set); } } return false; }
CascadingUtil { public static boolean unlinkProjectFromCascadingParents(ICascadingJob cascadingProject, String projectToUnlink) throws IOException { if (null != cascadingProject && null != projectToUnlink) { Job job = Functions.getItemByName(Hudson.getInstance().getAllItems(Job.class), projectToUnlink); if (null != job) { Set<String> set = new HashSet<String>(job.getCascadingChildrenNames()); set.add(projectToUnlink); return unlinkProjectFromCascadingParents(cascadingProject, set); } } return false; } }
CascadingUtil { public static boolean unlinkProjectFromCascadingParents(ICascadingJob cascadingProject, String projectToUnlink) throws IOException { if (null != cascadingProject && null != projectToUnlink) { Job job = Functions.getItemByName(Hudson.getInstance().getAllItems(Job.class), projectToUnlink); if (null != job) { Set<String> set = new HashSet<String>(job.getCascadingChildrenNames()); set.add(projectToUnlink); return unlinkProjectFromCascadingParents(cascadingProject, set); } } return false; }  }
CascadingUtil { public static boolean unlinkProjectFromCascadingParents(ICascadingJob cascadingProject, String projectToUnlink) throws IOException { if (null != cascadingProject && null != projectToUnlink) { Job job = Functions.getItemByName(Hudson.getInstance().getAllItems(Job.class), projectToUnlink); if (null != job) { Set<String> set = new HashSet<String>(job.getCascadingChildrenNames()); set.add(projectToUnlink); return unlinkProjectFromCascadingParents(cascadingProject, set); } } return false; }  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 boolean unlinkProjectFromCascadingParents(ICascadingJob cascadingProject, String projectToUnlink) throws IOException { if (null != cascadingProject && null != projectToUnlink) { Job job = Functions.getItemByName(Hudson.getInstance().getAllItems(Job.class), projectToUnlink); if (null != job) { Set<String> set = new HashSet<String>(job.getCascadingChildrenNames()); set.add(projectToUnlink); return unlinkProjectFromCascadingParents(cascadingProject, set); } } return false; }  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);  }