Search in sources :

Example 11 with FreeStyleProjectMock

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

the class CascadingUtilTest method testBuildExternalProperties.

@Test
@PrepareForTest({ Hudson.class, StaplerRequest.class })
public void testBuildExternalProperties() throws Exception {
    Job job = new FreeStyleProjectMock("job");
    StaplerRequest req = createMock(StaplerRequest.class);
    String javadocArchiverKey = "hudson-tasks-JavadocArchiver";
    JSONObject archiver = new JSONObject();
    archiver.put("javadoc_dir", "dir");
    archiver.put("keep_all", true);
    JSONObject json = new JSONObject();
    json.put(javadocArchiverKey, archiver);
    Hudson hudson = createMock(Hudson.class);
    Descriptor<Publisher> javadocDescriptor = new JavadocArchiver.DescriptorImpl();
    expect(hudson.getDescriptorOrDie(JavadocArchiver.class)).andReturn(javadocDescriptor);
    JavadocArchiver javadocArchiver = new JavadocArchiver("dir", true);
    expect(req.bindJSON(JavadocArchiver.class, archiver)).andReturn(javadocArchiver).anyTimes();
    List<Descriptor<Publisher>> descriptors = new ArrayList<Descriptor<Publisher>>();
    descriptors.add(javadocDescriptor);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replay(Hudson.class, hudson, req);
    assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
    CascadingUtil.buildExternalProperties(req, archiver, descriptors, job);
    assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
    CascadingUtil.buildExternalProperties(req, json, descriptors, job);
    assertNotNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
    verifyAll();
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) StaplerRequest(org.kohsuke.stapler.StaplerRequest) ArrayList(java.util.ArrayList) Publisher(hudson.tasks.Publisher) JSONObject(net.sf.json.JSONObject) Descriptor(hudson.model.Descriptor) JavadocArchiver(hudson.tasks.JavadocArchiver) Job(hudson.model.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with FreeStyleProjectMock

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

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

Example 14 with FreeStyleProjectMock

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

the class BaseProjectPropertyTest method setUp.

@Before
public void setUp() {
    parent = new FreeStyleProjectMock("parent");
    project = new FreeStyleProjectMock("project");
    property = new BaseProjectProperty(project);
    property.setKey(propertyKey);
    parentProperty = new BaseProjectProperty(parent);
    parentProperty.setKey(propertyKey);
    parentProperty.setValue(parentPropertyValue);
    parent.putProjectProperty(propertyKey, parentProperty);
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Before(org.junit.Before)

Example 15 with FreeStyleProjectMock

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

the class CopyOnWriteListProjectPropertyTest method setUp.

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

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