forked from jenkinsci/pipeline-graph-view-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipelineStateTest.java
More file actions
77 lines (62 loc) · 3 KB
/
PipelineStateTest.java
File metadata and controls
77 lines (62 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package io.jenkins.plugins.pipelinegraphview.utils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
class PipelineStateTest {
@ParameterizedTest
@MethodSource("whenFinished")
void of_usesResultWhenStateIsFinished(BlueRun.BlueRunResult result, PipelineState expected) {
NodeRunStatus runStatus = new NodeRunStatus(result, BlueRun.BlueRunState.FINISHED);
PipelineState status = PipelineState.of(runStatus);
assertEquals(expected, status);
}
private static Stream<Arguments> whenFinished() {
return Stream.of(
Arguments.arguments(BlueRun.BlueRunResult.SUCCESS, PipelineState.SUCCESS),
Arguments.arguments(BlueRun.BlueRunResult.UNSTABLE, PipelineState.UNSTABLE),
Arguments.arguments(BlueRun.BlueRunResult.FAILURE, PipelineState.FAILURE),
Arguments.arguments(BlueRun.BlueRunResult.NOT_BUILT, PipelineState.NOT_BUILT),
Arguments.arguments(BlueRun.BlueRunResult.UNKNOWN, PipelineState.UNKNOWN),
Arguments.arguments(BlueRun.BlueRunResult.ABORTED, PipelineState.ABORTED));
}
@ParameterizedTest
@MethodSource("whenNotFinished")
void of_usesStateWhenStateIsNotFinished(BlueRun.BlueRunState state, PipelineState expected) {
NodeRunStatus runStatus = new NodeRunStatus(null, state);
PipelineState status = PipelineState.of(runStatus);
assertEquals(expected, status);
}
private static Stream<Arguments> whenNotFinished() {
return Stream.of(
Arguments.arguments(BlueRun.BlueRunState.QUEUED, PipelineState.QUEUED),
Arguments.arguments(BlueRun.BlueRunState.RUNNING, PipelineState.RUNNING),
Arguments.arguments(BlueRun.BlueRunState.PAUSED, PipelineState.PAUSED),
Arguments.arguments(BlueRun.BlueRunState.SKIPPED, PipelineState.SKIPPED),
Arguments.arguments(BlueRun.BlueRunState.NOT_BUILT, PipelineState.NOT_BUILT));
}
private static final ObjectMapper MAPPER = new ObjectMapper();
@ParameterizedTest
@CsvSource({
"QUEUED, queued",
"RUNNING, running",
"PAUSED, paused",
"SKIPPED, skipped",
"NOT_BUILT, not_built",
"FINISHED, finished",
"SUCCESS, success",
"UNSTABLE, unstable",
"FAILURE, failure",
"UNKNOWN, unknown",
"ABORTED, aborted"
})
void serialization(String input, String expected) throws JsonProcessingException {
PipelineState status = PipelineState.valueOf(input);
String serialized = MAPPER.writeValueAsString(status);
assertEquals("\"%s\"".formatted(expected), serialized);
}
}