Search in sources :

Example 21 with FreeStyleProject

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

the class PromotedEnvVarTokenMacroTest method testEnvironmentVariableExpansion.

@Test
public void testEnvironmentVariableExpansion() throws Exception {
    // Assemble
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    User u = User.get("foo");
    u.setFullName("Foobar");
    SecurityContextHolder.getContext().setAuthentication(u.impersonate());
    MockFolder parent = r.createFolder("Folder");
    FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
    JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
    PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
    promotionProcess.conditions.clear();
    ManualCondition manualCondition = new ManualCondition();
    manualCondition.getParameterDefinitions().add(new StringParameterDefinition("PROMOTION_PARAM", "defaultValue"));
    promotionProcess.conditions.add(manualCondition);
    Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new LinkedList<ParameterValue>());
    TokenMacroExpressionRecorder recorder = new TokenMacroExpressionRecorder("${PROMOTION_ENV,var=\"PROMOTION_PARAM\"}");
    promotionProcess.getBuildSteps().add(recorder);
    // Act & promote
    FreeStyleBuild build = project.scheduleBuild2(0).get();
    build.addAction(approvalAction);
    build.save();
    Promotion promotion = promotionProcess.considerPromotion2(build, Arrays.asList((ParameterValue) new StringParameterValue("PROMOTION_PARAM", "FOO"))).get();
    // Check results
    EnvVars env = promotion.getEnvironment(TaskListener.NULL);
    assertEquals("The PROMOTION_PARAM variable has not been injected", "FOO", env.get("PROMOTION_PARAM"));
    assertEquals("The promotion variable value has not been resolved by the PROMOTION_PARAM macro", "FOO", recorder.getCaptured());
}
Also used : Action(hudson.model.Action) User(hudson.model.User) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Test(org.junit.Test)

Example 22 with FreeStyleProject

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

the class ItemPathResolverTest method shouldCorrectlyResolveItemsWithEqualNames.

@Test
public void shouldCorrectlyResolveItemsWithEqualNames() throws Exception {
    // FOO exists on both top level and within the folder
    final MockFolder folder = rule.createFolder("F");
    final FreeStyleProject prjInRoot = rule.createFreeStyleProject("FOO");
    final FreeStyleProject prjInFolder = folder.createProject(FreeStyleProject.class, "FOO");
    // Additional spot-checks for the absolute addressing
    assertsPath("F/FOO", null, prjInFolder);
    assertsPath("/F/FOO", null, prjInFolder);
    assertsPath("/FOO", null, prjInRoot);
}
Also used : MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 23 with FreeStyleProject

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

the class PromotedBuildActionTest method testDeletedPromotionProcess.

public void testDeletedPromotionProcess() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess foo = base.addProcess("foo");
    // promote a build
    FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
    foo.promote(b1, new UserCause(), new ManualPromotionBadge());
    // now delete the promotion process
    p.removeProperty(base);
    p.addProperty(base = new JobPropertyImpl(p));
    assertTrue(base.getActiveItems().isEmpty());
    // make sure that the page renders OK without any error
    HtmlPage page = createWebClient().getPage(p);
    List<?> candidates = page.getByXPath("//IMG");
    for (Object candidate : candidates) {
        if (!(candidate instanceof HtmlImage)) {
            continue;
        }
        HtmlImage img = (HtmlImage) candidate;
        try {
            img.getHeight();
        } catch (IOException e) {
            throw new IOException2("Failed to load " + img.getSrcAttribute(), e);
        }
    }
}
Also used : HtmlImage(com.gargoylesoftware.htmlunit.html.HtmlImage) UserCause(hudson.model.Cause.UserCause) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) FreeStyleBuild(hudson.model.FreeStyleBuild) IOException(java.io.IOException) FreeStyleProject(hudson.model.FreeStyleProject) IOException2(hudson.util.IOException2)

Example 24 with FreeStyleProject

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

the class PromotionEnvironmentVariablesTest method shouldSetJobAndJobFullNames.

@Test
public void shouldSetJobAndJobFullNames() throws Descriptor.FormException, IOException, InterruptedException, ExecutionException, Exception {
    // Assemble
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    User u = User.get("foo");
    u.setFullName("Foobar");
    SecurityContextHolder.getContext().setAuthentication(u.impersonate());
    MockFolder parent = r.createFolder("Folder");
    FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
    JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
    PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
    promotionProcess.conditions.clear();
    promotionProcess.conditions.add(new ManualCondition());
    Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new ArrayList<ParameterValue>());
    // Act
    FreeStyleBuild build = project.scheduleBuild2(0).get();
    build.setDisplayName("1234");
    build.addAction(approvalAction);
    build.save();
    Promotion promotion = promotionProcess.considerPromotion2(build).get();
    EnvVars env = promotion.getEnvironment(TaskListener.NULL);
    // Assert
    assertEquals("Folder/Project", env.get("PROMOTED_JOB_FULL_NAME"));
    assertEquals("Project", env.get("PROMOTED_JOB_NAME"));
    assertEquals("Foobar", env.get("PROMOTED_USER_NAME"));
    assertEquals("foo", env.get("PROMOTED_USER_ID"));
    assertEquals("1234", env.get("PROMOTED_DISPLAY_NAME"));
    project.delete();
    parent.delete();
}
Also used : Action(hudson.model.Action) User(hudson.model.User) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) Test(org.junit.Test)

Example 25 with FreeStyleProject

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

the class PromotionProcessTest method testIsVisibleResolvesDefaultParameterValueIndirectly.

public void testIsVisibleResolvesDefaultParameterValueIndirectly() throws Exception {
    FreeStyleProject project = createFreeStyleProject("project");
    final List<ParameterDefinition> parameters = new ArrayList<ParameterDefinition>();
    ParametersDefinitionProperty parametersProperty = new ParametersDefinitionProperty(parameters);
    parameters.add(new StringParameterDefinition("IndirectVisibility", "false"));
    parameters.add(new StringParameterDefinition("Visibility", "${IndirectVisibility}"));
    project.addProperty(parametersProperty);
    JobPropertyImpl jobProperty = new JobPropertyImpl(project);
    project.addProperty(jobProperty);
    PromotionProcess promotionProcess = jobProperty.addProcess("Promotion");
    promotionProcess.isVisible = "${Visibility}";
    assertFalse(promotionProcess.isVisible());
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) ArrayList(java.util.ArrayList) FreeStyleProject(hudson.model.FreeStyleProject) StringParameterDefinition(hudson.model.StringParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition)

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