Java Code Examples for org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode#addAction()

The following examples show how to use org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode#addAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testBuildStateForStageWithError() throws IOException {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    StepStartNode stageStartNode = mock(StepStartNode.class);
    ErrorAction error = mock(ErrorAction.class);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, mock(FlowNode.class));
    stageEndNode.addAction(error);

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    BuildStage.State state = instance.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.CompletedError, state);
}
 
Example 2
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testBuildStateForStageWithTag() throws IOException {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    StepStartNode stageStartNode = mock (StepStartNode.class);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, mock(FlowNode.class));
    TagsAction tag = mock(TagsAction.class);
    stageEndNode.addAction(tag);
    when(tag.getTagValue(StageStatus.TAG_NAME)).thenReturn("SKIPPED_FOR_FAILURE");

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    BuildStage.State state = instance.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.SkippedFailure, state);
}
 
Example 3
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void buildStateForStageError() {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    when(execution.iotaStr()).thenReturn("1", "2", "3", "4");
    FlowStartNode parentNode = new FlowStartNode(execution, "5");
    StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode);

    ErrorAction errorAction = mock(ErrorAction.class);
    stageEndNode.addAction(errorAction);

    BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.CompletedError, result);
}
 
Example 4
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void buildStateForStageSkippedUnstable() {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    when(execution.iotaStr()).thenReturn("1", "2", "3", "4");
    FlowStartNode parentNode = new FlowStartNode(execution, "5");
    StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode);

    TagsAction tagsAction = mock(TagsAction.class);
    when(tagsAction.getTagValue(StageStatus.TAG_NAME)).thenReturn(StageStatus.getSkippedForUnstable());
    stageEndNode.addAction(tagsAction);

    BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.SkippedUnstable, result);
}
 
Example 5
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void buildStateForStageSkippedConditional() {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    when(execution.iotaStr()).thenReturn("1", "2", "3", "4");
    FlowStartNode parentNode = new FlowStartNode(execution, "5");
    StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode);

    TagsAction tagsAction = mock(TagsAction.class);
    when(tagsAction.getTagValue(StageStatus.TAG_NAME)).thenReturn(StageStatus.getSkippedForConditional());
    stageEndNode.addAction(tagsAction);

    BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.SkippedConditional, result);
}
 
Example 6
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void buildStateForStageFailedAndContinued() {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    when(execution.iotaStr()).thenReturn("1", "2", "3", "4");
    FlowStartNode parentNode = new FlowStartNode(execution, "5");
    StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode);

    TagsAction tagsAction = mock(TagsAction.class);
    when(tagsAction.getTagValue(StageStatus.TAG_NAME)).thenReturn(StageStatus.getFailedAndContinued());
    stageEndNode.addAction(tagsAction);

    BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.CompletedError, result);
}
 
Example 7
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 4 votes vote down vote up
@Test
public void testStepEndNode() throws Exception {
    long time = 12345L;

    // Mocked objects
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    StepStartNode stageStartNode = mock(StepStartNode.class);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, mock(FlowNode.class));

    ErrorAction error = mock(ErrorAction.class);
    stageEndNode.addAction(error);

    TimingAction startTime = mock(TimingAction.class);
    TimingAction endTime = mock(TimingAction.class);
    stageEndNode.addAction(endTime);
    when(startTime.getStartTime()).thenReturn(0L);
    when(endTime.getStartTime()).thenReturn(time);

    BuildStatusAction buildStatus = mock(BuildStatusAction.class);
    FlowExecutionOwner owner = mock(FlowExecutionOwner.class);
    AbstractBuild build = mock(AbstractBuild.class);

    // get BuildStatusAction from StepEndNode
    when(execution.getOwner()).thenReturn(owner);
    when(owner.getExecutable()).thenReturn(build);
    when(build.getAction(BuildStatusAction.class)).thenReturn(buildStatus);

    // get StepStartNode from StepEndNode
    String startId = "15";
    when(stageStartNode.getId()).thenReturn(startId);
    when(execution.getNode(startId)).thenReturn(stageStartNode);

    // get time from StepStartNode to StepEndNode
    when(stageStartNode.getAction(TimingAction.class)).thenReturn(startTime);
    LabelAction labelAction = new LabelAction("some label");
    when(stageStartNode.getAction(LabelAction.class)).thenReturn(labelAction);
    when(stageStartNode.getAction(StageAction.class)).thenReturn(mock(StageAction.class));

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    instance.onNewHead(stageEndNode);
    verify(buildStatus).updateBuildStatusForStage(eq("some label"), eq(BuildStage.State.CompletedError), eq(time));
}