Search in sources :

Example 46 with FreeStyleProject

use of hudson.model.FreeStyleProject in project hudson-2.x by hudson.

the class FunctionsTest method testGetTemplateWithNullTemplateName.

@Test
public void testGetTemplateWithNullTemplateName() {
    List<FreeStyleProject> items = new ArrayList<FreeStyleProject>();
    FreeStyleProject project = Functions.getItemByName(items, null);
    Assert.assertNull(project);
}
Also used : ArrayList(java.util.ArrayList) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 47 with FreeStyleProject

use of hudson.model.FreeStyleProject in project hudson-2.x by hudson.

the class CascadingUtilTest method testUnlinkProjectFromCascadingParents.

@Test
@PrepareForTest(Hudson.class)
public void testUnlinkProjectFromCascadingParents() throws Exception {
    //Prepare data
    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);
    //Can't unlink from null project
    assertFalse(CascadingUtil.unlinkProjectFromCascadingParents(null, cascadingName));
    //Can't unlink null cascading name
    assertFalse(CascadingUtil.unlinkProjectFromCascadingParents(project1, null));
    //Verify whether cascadingName is present in parent and child
    assertTrue(project1.getCascadingChildrenNames().contains(cascadingName));
    assertTrue(child1.getCascadingChildrenNames().contains(cascadingName));
    boolean result = CascadingUtil.unlinkProjectFromCascadingParents(child1, cascadingName);
    assertTrue(result);
    //Name should disappear from hierarchy.
    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));
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) FreeStyleProject(hudson.model.FreeStyleProject) Job(hudson.model.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 48 with FreeStyleProject

use of hudson.model.FreeStyleProject in project hudson-2.x by hudson.

the class CascadingUtilTest method testHasCyclicCascadingLink.

@Test
@PrepareForTest(Hudson.class)
public void testHasCyclicCascadingLink() throws Exception {
    FreeStyleProject project1 = new FreeStyleProjectMock("p1");
    FreeStyleProjectMock project2 = new FreeStyleProjectMock("p2");
    FreeStyleProjectMock project3 = new FreeStyleProjectMock("p3");
    FreeStyleProjectMock project4 = new FreeStyleProjectMock("p4");
    List<Job> jobs = new ArrayList<Job>();
    jobs.add(project1);
    jobs.add(project2);
    jobs.add(project3);
    jobs.add(project4);
    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);
    project2.setCascadingProject(project1);
    CascadingUtil.linkCascadingProjectsToChild(project1, "p2");
    project3.setCascadingProject(project1);
    CascadingUtil.linkCascadingProjectsToChild(project1, "p3");
    project4.setCascadingProject(project3);
    CascadingUtil.linkCascadingProjectsToChild(project3, "p4");
    verifyCyclicCascadingLink(true, project2, project1);
    verifyCyclicCascadingLink(true, project3, project1);
    verifyCyclicCascadingLink(true, project4, project3);
    verifyCyclicCascadingLink(true, project4, project1);
    verifyCyclicCascadingLink(false, project3, project2);
    verifyCyclicCascadingLink(false, project1, project2);
    verifyCyclicCascadingLink(false, project2, project3);
    verifyCyclicCascadingLink(false, null, project1);
    verifyCyclicCascadingLink(false, null, project4);
    verify(Hudson.class, hudson);
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) FreeStyleProject(hudson.model.FreeStyleProject) Job(hudson.model.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 49 with FreeStyleProject

use of hudson.model.FreeStyleProject in project hudson-2.x by hudson.

the class CascadingUtilTest method testUnlinkProjectFromCascadingParents2.

@Test
@PrepareForTest(Hudson.class)
public void testUnlinkProjectFromCascadingParents2() throws Exception {
    FreeStyleProject project1 = new FreeStyleProjectMock("p1");
    FreeStyleProjectMock project2 = new FreeStyleProjectMock("p2");
    FreeStyleProjectMock project3 = new FreeStyleProjectMock("p3");
    project2.setCascadingProject(project1);
    CascadingUtil.linkCascadingProjectsToChild(project1, "p2");
    project3.setCascadingProject(project2);
    CascadingUtil.linkCascadingProjectsToChild(project2, "p3");
    List<Job> jobs = new ArrayList<Job>();
    jobs.add(project1);
    jobs.add(project2);
    jobs.add(project3);
    Hudson hudson = createMock(Hudson.class);
    mockStatic(Hudson.class);
    expect(hudson.getAllItems(Job.class)).andReturn(jobs);
    expect(Hudson.getInstance()).andReturn(hudson);
    replay(Hudson.class, hudson);
    CascadingUtil.unlinkProjectFromCascadingParents(project1, "p2");
    //Project3 should disappear from project1's children.
    assertTrue(project1.getCascadingChildrenNames().isEmpty());
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) FreeStyleProject(hudson.model.FreeStyleProject) Job(hudson.model.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 50 with FreeStyleProject

use of hudson.model.FreeStyleProject in project hudson-2.x by hudson.

the class CascadingUtilTest method testLinkCascadingProjectsToChild.

@Test
public void testLinkCascadingProjectsToChild() throws Exception {
    FreeStyleProject project1 = new FreeStyleProjectMock("project1");
    FreeStyleProjectMock child1 = new FreeStyleProjectMock("child1");
    child1.setCascadingProject(project1);
    String cascadingName = "newCascadingProject";
    CascadingUtil.linkCascadingProjectsToChild(null, cascadingName);
    assertFalse(project1.getCascadingChildrenNames().contains(cascadingName));
    assertFalse(child1.getCascadingChildrenNames().contains(cascadingName));
    CascadingUtil.linkCascadingProjectsToChild(project1, cascadingName);
    assertTrue(project1.getCascadingChildrenNames().contains(cascadingName));
    project1 = new FreeStyleProjectMock("project1");
    child1 = new FreeStyleProjectMock("child1");
    child1.setCascadingProject(project1);
    CascadingUtil.linkCascadingProjectsToChild(child1, cascadingName);
    //Name should be included to all cascading parents up-hierarchy.
    assertTrue(project1.getCascadingChildrenNames().contains(cascadingName));
    assertTrue(child1.getCascadingChildrenNames().contains(cascadingName));
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) FreeStyleProject(hudson.model.FreeStyleProject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FreeStyleProject (hudson.model.FreeStyleProject)77 Test (org.junit.Test)49 FreeStyleBuild (hudson.model.FreeStyleBuild)39 Shell (hudson.tasks.Shell)17 Map (java.util.Map)16 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)13 ArrayList (java.util.ArrayList)11 StringParameterDefinition (hudson.model.StringParameterDefinition)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)8 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)7 Promotion (hudson.plugins.promoted_builds.Promotion)7 MockFolder (org.jvnet.hudson.test.MockFolder)7 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)6 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)6 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 Descriptor (hudson.model.Descriptor)5 Hudson (hudson.model.Hudson)5