forked from jenkinsci/pipeline-graph-view-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpstreamCauseRunDetailsItemTest.java
More file actions
69 lines (53 loc) · 2.22 KB
/
UpstreamCauseRunDetailsItemTest.java
File metadata and controls
69 lines (53 loc) · 2.22 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
package io.jenkins.plugins.pipelinegraphview.cards.items;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import hudson.model.Cause;
import hudson.model.CauseAction;
import hudson.model.Result;
import io.jenkins.plugins.pipelinegraphview.Messages;
import io.jenkins.plugins.pipelinegraphview.cards.RunDetailsItem;
import io.jenkins.plugins.pipelinegraphview.utils.TestUtils;
import java.util.Optional;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
@WithJenkins
class UpstreamCauseRunDetailsItemTest {
private static WorkflowRun run;
private static String baseUrl;
@BeforeAll
static void beforeAll(JenkinsRule j) throws Exception {
run = TestUtils.createAndRunJob(j, "simple", "singleStagePipeline.jenkinsfile", Result.SUCCESS);
baseUrl = j.getURL().toString();
}
@BeforeEach
void setUp() {
run.removeActions(CauseAction.class);
}
@Test
void get_noActionsOfType() {
Optional<RunDetailsItem> detailsItem = UpstreamCauseRunDetailsItem.get(run);
assertTrue(detailsItem.isEmpty());
}
@Test
void get_noUpstreamCause() {
run.addAction(new CauseAction(new Cause.UserIdCause("User Id")));
Optional<RunDetailsItem> detailsItem = UpstreamCauseRunDetailsItem.get(run);
assertTrue(detailsItem.isEmpty());
}
@Test
void get() {
run.addAction(new CauseAction(new Cause.UpstreamCause(run)));
Optional<RunDetailsItem> detailsItem = UpstreamCauseRunDetailsItem.get(run);
assertTrue(detailsItem.isPresent());
RunDetailsItem.RunDetail userDetails = (RunDetailsItem.RunDetail) detailsItem.get();
assertEquals(
new RunDetailsItem.ItemContent.LinkContent(
baseUrl + run.getUrl() + "pipeline-overview", Messages.cause_upstream("#1")),
userDetails.content());
assertEquals("symbol-play-circle-outline plugin-ionicons-api", userDetails.icon());
}
}