Skip to content

Commit

Permalink
Assert exception message
Browse files Browse the repository at this point in the history
Also asserts that validateBuild passes in the success case
  • Loading branch information
MarkEWaite committed Dec 2, 2024
1 parent 78af867 commit 1af5e40
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,44 @@ public void testValidateBuildException() throws Exception {
Assert.assertTrue(buildWrapper instanceof TriggerNextBuildWrapper);
Assert.assertEquals(
BuildStepMonitor.BUILD, ((TriggerNextBuildWrapper) buildWrapper).getRequiredMonitorService());
Assert.assertThrows(IllegalStateException.class, () -> labelParam.validateBuild(build, null, null));

IllegalStateException e =
Assert.assertThrows(IllegalStateException.class, () -> labelParam.validateBuild(build, null, null));
Assert.assertEquals(
"The project is configured to run builds concurrent, but the node parameter [node] is configured to trigger new builds depending on the state of the last build only!",
e.getMessage());

j.jenkins.removeNode(slave);
}

@Test
public void testValidateBuildNoExceptionIfConcurrentBuildsAllowed() throws Exception {
String paramName = "node";
String label = "label-" + System.currentTimeMillis();

DumbSlave slave = j.createOnlineSlave(new LabelAtom(label));

FreeStyleProject projectA = j.createFreeStyleProject("projectA");
// If concurrent builds are allowed, then ALL_CASES is
// required to avoid IllegalStateException from validateBuild
projectA.setConcurrentBuild(true);
LabelParameterDefinition labelParam = new LabelParameterDefinition(
paramName,
"label parameter description",
"default label parameter value",
true,
false,
Constants.ALL_CASES);
projectA.addProperty(new ParametersDefinitionProperty(labelParam));

LabelParameterValue lpv = new LabelParameterValue(paramName, label, true, new AllNodeEligibility());
FreeStyleBuild build =
projectA.scheduleBuild2(0, new ParametersAction(lpv)).get();

j.assertBuildStatusSuccess(build);

// Confirm exception is not thrown wwhen triggerIfResult is ALL_CASES and concurrent builds are allowed
labelParam.validateBuild(build, null, null);

j.jenkins.removeNode(slave);
}
Expand Down

0 comments on commit 1af5e40

Please sign in to comment.