Skip to content

Commit

Permalink
Add test for addOrReplaceAction
Browse files Browse the repository at this point in the history
  • Loading branch information
mrginglymus committed Jan 9, 2021
1 parent d82d7e4 commit 187b91c
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,15 @@ public void nodeWithNoParentsInBruteForceScanForEnclosingBlock() {
});
}

@Test
public void addOrReplaceActionWorks() {
rr.then(r -> {
WorkflowJob j = r.createProject(WorkflowJob.class);
j.setDefinition(new CpsFlowDefinition("doubleWarning()", true));
r.buildAndAssertSuccess(j);
});
}

private void assertWarning(FlowNode node, Result expectedResult, BallColor expectedColor) {
WarningAction warningAction = node.getPersistentAction(WarningAction.class);
assertNotNull(warningAction);
Expand Down Expand Up @@ -572,5 +581,36 @@ public Set<? extends Class<?>> getRequiredContext() {
}
}
}

public static class DoubleWarningStep extends Step {

@DataBoundConstructor
public DoubleWarningStep() {}

@Override
public StepExecution start(StepContext context) throws Exception {
return new StepExecution(context) {
@Override
public boolean start() throws Exception {
getContext().get(FlowNode.class).addAction(new WarningAction(Result.FAILURE).withMessage("First"));
getContext().get(FlowNode.class).addOrReplaceAction(new WarningAction(Result.FAILURE).withMessage("Second"));
getContext().onSuccess(null);
return true;
}
};
}
@TestExtension("addOrReplaceActionWorks")
public static class DescriptorImpl extends StepDescriptor {
@Override
public String getFunctionName() {
return "doubleWarning";
}

@Override
public Set<? extends Class<?>> getRequiredContext() {
return Collections.singleton(FlowNode.class);
}
}
}
}

0 comments on commit 187b91c

Please sign in to comment.