Search in sources :

Example 61 with FreeStyleProject

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

the class PromotionProcessTest method testIsVisibleFalseReturnsNotVisible.

public void testIsVisibleFalseReturnsNotVisible() throws Exception {
    FreeStyleProject project = createFreeStyleProject("project");
    JobPropertyImpl jobProperty = new JobPropertyImpl(project);
    project.addProperty(jobProperty);
    PromotionProcess promotionProcess = jobProperty.addProcess("Promotion");
    promotionProcess.isVisible = "false";
    assertFalse(promotionProcess.isVisible());
}
Also used : FreeStyleProject(hudson.model.FreeStyleProject)

Example 62 with FreeStyleProject

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

the class PromotionProcessTest method testPromotionWithoutFingerprint.

/**
     * Tests a promotion induced by the pseudo upstream/downstream cause relationship
     */
public void testPromotionWithoutFingerprint() throws Exception {
    FreeStyleProject up = createFreeStyleProject("up");
    FreeStyleProject down = createFreeStyleProject();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(up);
    up.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    // trigger downstream automatically to create relationship
    up.getPublishersList().add(new BuildTrigger(down.getName(), Result.SUCCESS));
    hudson.rebuildDependencyGraph();
    // this is the downstream job
    down.getBuildersList().add(new Shell(// expr exits with non-zero status if result is zero
    "expr $BUILD_NUMBER % 2 - 1\n"));
    // not yet promoted while the downstream is failing
    FreeStyleBuild up1 = assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    waitForCompletion(down, 1);
    assertEquals(0, proc.getBuilds().size());
    // do it one more time and this time it should work
    FreeStyleBuild up2 = assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    waitForCompletion(down, 2);
    assertEquals(1, proc.getBuilds().size());
    {
        // verify that it promoted the right stuff
        Promotion pb = proc.getBuilds().get(0);
        assertSame(pb.getTarget(), up2);
        PromotedBuildAction badge = (PromotedBuildAction) up2.getBadgeActions().get(0);
        assertTrue(badge.contains(proc));
    }
}
Also used : Shell(hudson.tasks.Shell) DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) BuildTrigger(hudson.tasks.BuildTrigger) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject)

Example 63 with FreeStyleProject

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

the class PromotionTargetActionTest method test1.

/**
     * When a project is created, built, and renamed, then the old build is created,
     * that results in NPE.
     */
public void test1() throws Exception {
    FreeStyleProject up = createFreeStyleProject("up");
    up.setCustomWorkspace(createTmpDir().getPath());
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(up);
    up.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new ManualCondition());
    FreeStyleBuild b = assertBuildStatusSuccess(up.scheduleBuild2(0));
    b.addAction(new ManualApproval(proc.getName(), Collections.<ParameterValue>emptyList()));
    b.save();
    // check for promotion
    Promotion p = assertBuildStatusSuccess(proc.considerPromotion2(b));
    up.renameTo("up2");
    assertSame(b, p.getTarget());
}
Also used : ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject)

Example 64 with FreeStyleProject

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

the class RemoteApiTest method delete.

@Test
public void delete() throws Exception {
    FreeStyleProject p = r.createFreeStyleProject("p");
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    promotion.addProcess("promo").save();
    assertEquals(1, promotion.getItems().size());
    assertEquals(1, promotion.getActiveItems().size());
    JenkinsRule.WebClient wc = r.createWebClient();
    wc.getPage(wc.addCrumb(new WebRequest(new URL(r.getURL(), "job/p/promotion/process/promo/doDelete"), HttpMethod.POST)));
    assertEquals(0, promotion.getItems().size());
    assertEquals(0, promotion.getActiveItems().size());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) URL(java.net.URL) Test(org.junit.Test)

Example 65 with FreeStyleProject

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

the class RemoteApiTest method acl.

@Test
public void acl() throws Exception {
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    ProjectMatrixAuthorizationStrategy pmas = new ProjectMatrixAuthorizationStrategy();
    r.jenkins.setAuthorizationStrategy(pmas);
    pmas.add(Jenkins.READ, "anonymous");
    FreeStyleProject p = r.createFreeStyleProject("p");
    Map<Permission, Set<String>> perms = new HashMap<Permission, Set<String>>();
    perms.put(Item.READ, Collections.singleton("alice"));
    perms.put(Item.CONFIGURE, Collections.singleton("alice"));
    perms.put(Item.DISCOVER, Collections.singleton("bob"));
    p.addProperty(new AuthorizationMatrixProperty(perms));
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    promotion.addProcess("promo").save();
    JenkinsRule.WebClient wc = r.createWebClient();
    wc.assertFails("job/p/promotion/process/promo/config.xml", HttpURLConnection.HTTP_NOT_FOUND);
    wc.login("bob");
    wc.assertFails("job/p/promotion/process/promo/config.xml", HttpURLConnection.HTTP_FORBIDDEN);
    wc.login("alice");
    wc.goToXml("job/p/config.xml");
    wc.goToXml("job/p/promotion/process/promo/config.xml");
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) Permission(hudson.security.Permission) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) FreeStyleProject(hudson.model.FreeStyleProject) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty) Test(org.junit.Test)

Aggregations

FreeStyleProject (hudson.model.FreeStyleProject)88 Test (org.junit.Test)61 FreeStyleBuild (hudson.model.FreeStyleBuild)42 Shell (hudson.tasks.Shell)21 Map (java.util.Map)20 ImmutableMap (com.google.common.collect.ImmutableMap)17 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)14 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)13 ArrayList (java.util.ArrayList)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 StringParameterDefinition (hudson.model.StringParameterDefinition)10 MockFolder (org.jvnet.hudson.test.MockFolder)10 List (java.util.List)9 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)8 ImmutableList (com.google.common.collect.ImmutableList)7 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)7 Promotion (hudson.plugins.promoted_builds.Promotion)7 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)6 Run (hudson.model.Run)6 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)6