Search in sources :

Example 6 with FreeStyleProjectMock

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

the class AxisListProjectPropertyTest method setUp.

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

Example 7 with FreeStyleProjectMock

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

the class CascadingParameterDefinitionPropertiesTest method setUp.

@Before
public void setUp() throws Exception {
    p1 = new FreeStyleProjectMock("p1");
    p2 = new FreeStyleProjectMock("p2");
    p3 = new FreeStyleProjectMock("p3");
    p2.setCascadingProject(p1);
    CascadingUtil.linkCascadingProjectsToChild(p1, "p2");
    p3.setCascadingProject(p2);
    CascadingUtil.linkCascadingProjectsToChild(p2, "p3");
    Hudson hudson = createMock(Hudson.class);
    expect(hudson.getItem("p2")).andReturn(p2).anyTimes();
    expect(hudson.getItem("p3")).andReturn(p3).anyTimes();
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replay(Hudson.class, hudson);
    propertyKey = Job.PARAMETERS_DEFINITION_JOB_PROPERTY_PROPERTY_NAME;
    List<ParameterDefinition> parameterDefinitionList = new ArrayList<ParameterDefinition>();
    parameterDefinitionList.add(new BooleanParameterDefinition("name", true, "d1"));
    ParametersDefinitionProperty property = new ParametersDefinitionProperty(parameterDefinitionList);
    copyOnWriteList = new CopyOnWriteList<ParametersDefinitionProperty>();
    copyOnWriteList.add(property);
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition) Before(org.junit.Before)

Example 8 with FreeStyleProjectMock

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

the class CascadingTriggersTest method setUp.

@Before
public void setUp() throws Exception {
    p1 = new FreeStyleProjectMock("p1");
    p2 = new FreeStyleProjectMock("p2");
    p3 = new FreeStyleProjectMock("p3");
    p2.setCascadingProject(p1);
    CascadingUtil.linkCascadingProjectsToChild(p1, "p2");
    p3.setCascadingProject(p2);
    CascadingUtil.linkCascadingProjectsToChild(p2, "p3");
    descriptor = new TimerTrigger.DescriptorImpl();
    propertyKey = descriptor.getJsonSafeClassName();
    req = createMock(StaplerRequest.class);
    json = new JSONObject();
    JSONObject refspec = new JSONObject();
    refspec.put("refspec", "* * * * *");
    json.put(propertyKey, refspec);
    expect(req.bindJSON(TimerTrigger.class, refspec)).andReturn(new TimerTrigger("* * * * *")).anyTimes();
    mockStatic(Hudson.class);
    Hudson hudson = createMock(Hudson.class);
    expect(hudson.getDescriptorOrDie(TimerTrigger.class)).andReturn(descriptor).anyTimes();
    expect(hudson.getItem("p2")).andReturn(p2).anyTimes();
    expect(hudson.getItem("p3")).andReturn(p3).anyTimes();
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replay(Hudson.class, hudson, req);
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) JSONObject(net.sf.json.JSONObject) Hudson(hudson.model.Hudson) StaplerRequest(org.kohsuke.stapler.StaplerRequest) TimerTrigger(hudson.triggers.TimerTrigger) Before(org.junit.Before)

Example 9 with FreeStyleProjectMock

use of hudson.model.FreeStyleProjectMock 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 10 with FreeStyleProjectMock

use of hudson.model.FreeStyleProjectMock 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)

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