Search in sources :

Example 1 with FreeStyleProject

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

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

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

the class FunctionsTest method testGetTemplatePresentTemplate.

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

Example 4 with FreeStyleProject

use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.

the class AbstractRunImplTest method testArtifactZipFileLink.

@Test
public void testArtifactZipFileLink() throws Exception {
    String JOB_NAME = "artifactTest";
    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new Shell("touch {{a..z},{A..Z},{0..99}}.txt"));
    p.getPublishersList().add(new ArtifactArchiver("*"));
    Run r = p.scheduleBuild2(0).waitForStart();
    r = j.waitForCompletion(r);
    Map m = request().get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/").build(Map.class);
    Assert.assertEquals(m.get("artifactsZipFile"), "/job/artifactTest/1/artifact/*zip*/archive.zip");
}
Also used : Shell(hudson.tasks.Shell) ArtifactArchiver(hudson.tasks.ArtifactArchiver) Run(hudson.model.Run) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) Test(org.junit.Test)

Example 5 with FreeStyleProject

use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method resolveMbpLink.

@Test
public void resolveMbpLink() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    FreeStyleProject f = j.jenkins.createProject(FreeStyleProject.class, "f");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    mp.scheduleBuild2(0).getFuture().get();
    j.waitUntilNoActivity();
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/", LinkResolver.resolveLink(mp).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/", LinkResolver.resolveLink(mp.getBranch("master")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature%252Fux-1/", LinkResolver.resolveLink(mp.getBranch("feature%2Fux-1")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/", LinkResolver.resolveLink(mp.getBranch("feature2")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/f/", LinkResolver.resolveLink(f).getHref());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) FreeStyleProject(hudson.model.FreeStyleProject) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) 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