Search in sources :

Example 1 with FreeStyleProjectMock

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

the class CascadingUtilTest method testRenameCascadingParentLinks.

@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());
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) Job(hudson.model.Job) FreeStyleProject(hudson.model.FreeStyleProject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with FreeStyleProjectMock

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

the class CascadingUtilTest method testGetAllItems.

@Test
@PrepareForTest(Hudson.class)
public void testGetAllItems() 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");
    List<Job> jobs1 = CascadingUtil.getCascadingParents(Job.class, project1);
    List<Job> jobs2 = CascadingUtil.getCascadingParents(Job.class, project2);
    List<Job> jobs3 = CascadingUtil.getCascadingParents(Job.class, project3);
    List<Job> jobs4 = CascadingUtil.getCascadingParents(Job.class, project4);
    verify(Hudson.class, hudson);
    assertEquals(0, jobs1.size());
    assertFalse(jobs1.contains(project1));
    assertFalse(jobs1.contains(project2));
    assertFalse(jobs1.contains(project3));
    assertFalse(jobs1.contains(project4));
    assertEquals(3, jobs2.size());
    assertTrue(jobs2.contains(project1));
    assertFalse(jobs2.contains(project2));
    assertTrue(jobs2.contains(project3));
    assertTrue(jobs2.contains(project4));
    assertEquals(2, jobs3.size());
    assertTrue(jobs3.contains(project1));
    assertTrue(jobs3.contains(project2));
    assertFalse(jobs3.contains(project3));
    assertFalse(jobs3.contains(project4));
    assertEquals(3, jobs4.size());
    assertTrue(jobs4.contains(project1));
    assertTrue(jobs4.contains(project2));
    assertTrue(jobs4.contains(project3));
    assertFalse(jobs4.contains(project4));
}
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 3 with FreeStyleProjectMock

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

the class ExternalProjectPropertyTest method setUp.

@Before
public void setUp() {
    project = new FreeStyleProjectMock("project");
    final String propertyKey = "propertyKey";
    property = new ExternalProjectProperty(project);
    property.setKey(propertyKey);
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Before(org.junit.Before)

Example 4 with FreeStyleProjectMock

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

the class SCMProjectPropertyTest method setUp.

@Before
public void setUp() {
    project = new FreeStyleProjectMock("project");
    final String propertyKey = "propertyKey";
    property = new SCMProjectProperty(project);
    property.setKey(propertyKey);
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Before(org.junit.Before)

Example 5 with FreeStyleProjectMock

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

the class CascadingUtilTest method testRenameCascadingChildLinks.

@Test
public void testRenameCascadingChildLinks() throws Exception {
    String oldName = "oldCascadingProject";
    String newName = "newCascadingProject";
    FreeStyleProject project1 = new FreeStyleProjectMock("project1");
    FreeStyleProjectMock project2 = new FreeStyleProjectMock("project2");
    FreeStyleProjectMock project3 = new FreeStyleProjectMock(oldName);
    project2.setCascadingProject(project1);
    CascadingUtil.linkCascadingProjectsToChild(project1, "project2");
    project3.setCascadingProject(project2);
    CascadingUtil.linkCascadingProjectsToChild(project2, oldName);
    assertTrue(project2.getCascadingChildrenNames().contains(oldName));
    assertTrue(project1.getCascadingChildrenNames().contains(oldName));
    CascadingUtil.renameCascadingChildLinks(project2, oldName, newName);
    assertTrue(project2.getCascadingChildrenNames().contains(newName));
    assertFalse(project2.getCascadingChildrenNames().contains(oldName));
    assertTrue(project1.getCascadingChildrenNames().contains(newName));
    assertFalse(project1.getCascadingChildrenNames().contains(oldName));
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) FreeStyleProject(hudson.model.FreeStyleProject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)17 Before (org.junit.Before)9 Hudson (hudson.model.Hudson)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 FreeStyleProject (hudson.model.FreeStyleProject)7 ArrayList (java.util.ArrayList)7 Job (hudson.model.Job)6 JSONObject (net.sf.json.JSONObject)2 StaplerRequest (org.kohsuke.stapler.StaplerRequest)2 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)1 Descriptor (hudson.model.Descriptor)1 ParameterDefinition (hudson.model.ParameterDefinition)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1 JavadocArchiver (hudson.tasks.JavadocArchiver)1 Publisher (hudson.tasks.Publisher)1 TimerTrigger (hudson.triggers.TimerTrigger)1