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());
}
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);
}
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);
}
}
}
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();
}
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());
}
Aggregations