actionClass, String id) {
101 | super(context);
102 | this.actionClass = actionClass;
103 | this.id = id;
104 | }
105 |
106 | @Override
107 | protected Void run() throws Exception {
108 | Run, ?> run = getContext().get(Run.class);
109 | run.getAllActions().stream().filter(this::matches).forEach(run::removeAction);
110 |
111 | TaskListener listener = getContext().get(TaskListener.class);
112 | PrintStream logger = listener.getLogger();
113 | logger.println(
114 | "Step 'removeHtmlBadges' is deprecated - please consider using 'addBadges' and 'removeBadges' instead.");
115 |
116 | return null;
117 | }
118 |
119 | private boolean matches(Action a) {
120 | return actionClass.isAssignableFrom(a.getClass())
121 | && (id == null || id.equals(((HtmlBadgeAction) a).getId()));
122 | }
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkinsci/plugins/badge/dsl/RemoveSummariesStep.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import com.jenkinsci.plugins.badge.action.AbstractBadgeAction;
27 | import com.jenkinsci.plugins.badge.action.BadgeSummaryAction;
28 | import edu.umd.cs.findbugs.annotations.NonNull;
29 | import hudson.Extension;
30 | import org.kohsuke.stapler.DataBoundConstructor;
31 |
32 | /**
33 | * Removes all summaries or the summaries with a given id.
34 | */
35 | public class RemoveSummariesStep extends AbstractRemoveBadgesStep {
36 |
37 | @DataBoundConstructor
38 | public RemoveSummariesStep() {
39 | this(null);
40 | }
41 |
42 | protected RemoveSummariesStep(String id) {
43 | super(id);
44 | }
45 |
46 | @Override
47 | protected Class extends AbstractBadgeAction> getActionClass() {
48 | return BadgeSummaryAction.class;
49 | }
50 |
51 | @Extension
52 | public static class DescriptorImpl extends AbstractTaskListenerDescriptor {
53 |
54 | @Override
55 | public String getFunctionName() {
56 | return "removeSummaries";
57 | }
58 |
59 | @NonNull
60 | @Override
61 | public String getDisplayName() {
62 | return "Remove Summaries";
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly:
--------------------------------------------------------------------------------
1 |
2 |
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 | ${it.text}
58 |
59 |
60 |
61 |
62 |
63 |
64 | ${it.text}
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeSummaryAction/summary.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | |
42 |
43 |
44 |
45 |
46 |
47 |
48 | ${it.text}
49 |
50 |
51 |
52 |
53 |
54 |
55 | ${it.text}
56 |
57 |
58 |
59 | |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/action/HtmlBadgeAction/badge.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 | ${it.html}
29 |
30 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/assets.css:
--------------------------------------------------------------------------------
1 | .badge-text--background {
2 | display: inline-block;
3 | border-radius: 6px;
4 | font-size: 0.75rem;
5 | font-weight: 500;
6 | padding: 0 0.4rem !important;
7 | margin: 0 0.1rem 0 0;
8 | text-decoration: none;
9 | text-align: center;
10 | white-space: nowrap;
11 | vertical-align: middle;
12 | position: relative;
13 | }
14 |
15 | .badge-text--background::before {
16 | inset: -0px -0px;
17 | border-radius: 6px;
18 | background: currentColor;
19 | opacity: .2;
20 | content: "";
21 | position: absolute;
22 | }
23 |
24 | .badge-text--background::after {
25 | inset: -5px -0px;
26 | box-shadow: 0 0 0 10px currentColor;
27 | opacity: 0;
28 | content: "";
29 | position: absolute;
30 | }
31 |
32 | .badge-text--bordered {
33 | display: inline-block;
34 | border: 0.1rem solid currentColor;
35 | font-size: 0.75rem;
36 | font-weight: 500;
37 | padding: 0 0.2rem !important;
38 | margin: 0 0.1rem 0 0;
39 | text-decoration: none;
40 | text-align: center;
41 | white-space: nowrap;
42 | vertical-align: middle;
43 | position: relative;
44 | }
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddBadgeStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
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 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddBadgeStep/help-cssClass.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Optional CSS class for the badge. Classes will be applied to the enclosing <span>
of a badge.
4 | User can also reference Jenkins built-in CSS classes such as icon-sm
- see Jenkins Design Library for more details.
5 |
6 |
7 | This plugin includes pre-defined CSS classes for text only badges:
8 |
9 | badge-text--background
- Adds colored background with rounded corners.
10 | badge-text--bordered
- Adds border that is the same color as the text.
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddBadgeStep/help-icon.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | The plugin supports symbols from the Ionicons API as well as the Emoji Symbols API.
4 | More symbols can be added by installing additional plugins, such as Font Awesome API or IT Symbols API.
5 | Symbols from plugins are referenced as "symbol-icon-name plugin-plugin-name" and Jenkins Core icons as "icon-icon-name" or "symbol-icon-name" - see Jenkins Design Library for more details.
6 | For example, the following are all valid references to symbols:
7 |
8 | addBadge icon: 'symbol-alert-circle-outline plugin-ionicons-api', text: 'This is an alert symbol'
9 | addBadge icon: 'symbol-bar-chart-filled plugin-ionicons-api', text: 'This is a bar chart symbol'
10 | addBadge icon: 'symbol-emoji_sloth plugin-emoji-symbols-api', text: 'This is a sloth symbol'
11 | addBadge icon: 'symbol-solid/flag-checkered plugin-font-awesome-api', text: 'This is a checkered flag from font-awesome. Note the slash between the icon family and the name.
12 | addBadge icon: 'symbol-cube', text: 'This is a Jenkins Core symbol'
13 | addBadge icon: 'icon-gear', text: 'This is a Jenkins Core icon'
14 |
15 |
16 |
17 |
18 | The plugin allows you to also reference images from within Jenkins as well as relative and remote URL:
19 |
20 | addBadge icon: '/jenkins.png', text: 'This is a relative image'
21 | addBadge icon: 'https://foo.bar/icon.png', text: 'This is a remote icon'
22 | addBadge icon: 'blue.png', text: 'This is a icon from Jenkins'
23 |
24 |
25 |
26 |
27 | The plugin also supports the 16x16 icons that are offered by Jenkins.
28 | These icons are listed in the plugin documentation and are referenced as "image-name.gif".
29 | For example, the following are all valid references to icons included with the plugin:
30 |
31 | addBadge icon: 'aborted.gif', text: 'This is a aborted symbol'
32 | addBadge icon: 'folder-open.gif', text: 'This is a folder icon'
33 | addBadge icon: 'document_edit.gif', text: 'This is a document icon'
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddBadgeStep/help-id.html:
--------------------------------------------------------------------------------
1 |
2 | Optional identifier for the badge in case later operations in the Pipeline job need to delete it.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddBadgeStep/help-link.html:
--------------------------------------------------------------------------------
1 |
2 | Optional URL that will be opened when the user clicks the badge.
3 | Can also be a relative path or mailto:
reference.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddBadgeStep/help-style.html:
--------------------------------------------------------------------------------
1 |
2 | Optional CSS style for the badge. Styles will be applied to the enclosing
<span>
of a badge.
3 | User can also reference Jenkins built-in styles such as
color: var(--warning-color)
- see
Jenkins Design Library for more details.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddBadgeStep/help-target.html:
--------------------------------------------------------------------------------
1 |
2 | Optional target frame that is used when http link is opened.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddBadgeStep/help-text.html:
--------------------------------------------------------------------------------
1 |
2 | Optional text that will be displayed to the user as either short text or hover of an icon.
3 | Text can be plain text or HTML depending on the selected
Markdown Formatter
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddBadgeStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Adds one or more badges to the current Pipeline build.
4 | Badges are symbols or icons with an optional text message and an optional clickable hyperlink.
5 | Badges are often used to provide a visual indicator of additional status information about a Pipeline build.
6 | Badges added by addBadge
are displayed in the build history of the Pipeline job.
7 |
8 |
9 |
10 | The plugin supports symbols from the ionicons library through the ionicons-api-plugin.
11 | More symbols can be added by installing additional plugins, such as font-awesome-api-plugin or custom-folder-icon-plugin.
12 | Symbols from plugins are referenced as "symbol-icon-name plugin-plugin-name" and Jenkins Core icons as "icon-icon-name" or "symbol-icon-name".
13 | For example, the following are all valid references to symbols:
14 |
15 | addBadge icon: 'symbol-alert-circle-outline plugin-ionicons-api', text: 'This is an alert symbol'
16 | addBadge icon: 'symbol-bar-chart-filled plugin-ionicons-api', text: 'This is a bar chart symbol'
17 | addBadge icon: 'symbol-battery-half-sharp plugin-ionicons-api', text: 'This is a half filled battery symbol'
18 | addBadge icon: 'symbol-emoji_sloth plugin-emoji-symbols-api', text: 'This is a sloth symbol'
19 | addBadge icon: 'symbol-solid/flag-checkered plugin-font-awesome-api', text: 'This is a checkered flag from font-awesome. Note the slash between the icon family and the name.
20 | addBadge icon: 'symbol-cube', text: 'This is a Jenkins Core symbol'
21 | addBadge icon: 'icon-gear', text: 'This is a Jenkins Core icon'
22 |
23 |
24 |
25 |
26 | The plugin allows you to also reference images from within Jenkins as well as relative and remote URL:
27 |
28 | addBadge icon: '/jenkins.png', text: 'This is a relative image'
29 | addBadge icon: 'https://foo.bar/icon.png', text: 'This is a remote icon'
30 | addBadge icon: 'blue.png', text: 'This is a icon from Jenkins'
31 |
32 |
33 |
34 |
35 | The plugin includes icons as GIF images and also supports the 16x16 icons that are offered by Jenkins.
36 | These icons are listed in the plugin documentation and are referenced as "image-name.gif".
37 | For example, the following are all valid references to icons included with the plugin:
38 |
39 | addBadge icon: 'completed.gif', text: 'This is a completed symbol'
40 | addBadge icon: 'success.gif', text: 'This is a success icon'
41 | addBadge icon: 'warning.gif', text: 'This is a warning icon'
42 |
43 |
44 |
45 |
Example: Badge with completed icon
46 |
47 | The following example adds a "completed" checkmark icon with the text, "This is completed":
48 |
addBadge icon: 'completed.gif', text: 'This is completed'
49 |
50 |
51 |
Example: Badge with alarm symbol
52 |
53 | The following example adds an alarm symbol with the text, "This is alarming":
54 |
addBadge icon: 'symbol-alarm-outline plugin-ionicons-api', text: 'This is alarming'
55 |
56 |
57 |
Example: Badge with red bug symbol
58 |
59 | The following example adds a red bug symbol with the text, "This is a red bug with a link", and a link:
60 |
addBadge icon: 'symbol-bug plugin-ionicons-api', text: 'This is a red bug with a link', style: 'color: red', link: 'https://issues.jenkins.io/browse/JENKINS-59646', target: '_blank'
61 |
62 |
63 |
Example: Text badge with CSS styles
64 |
65 | The following example adds text only badge that uses included CSS styles:
66 |
67 | // Add shaded background color with rounded corners
68 | addBadge text: 'ok', style: 'color: var(--success-color)', cssClass: 'badge-text--background'
69 | // Add additional border around badge
70 | addBadge text: '1.0.0', cssClass: 'badge-text--background badge-text--bordered'
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep/help-id.html:
--------------------------------------------------------------------------------
1 |
2 | Optional identifier for the badge in case later operations in the Pipeline job need to delete it.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep/help-link.html:
--------------------------------------------------------------------------------
1 |
2 | Optional URL that will be opened when the user clicks the badge.
3 | Can also be a relative path or mailto:
reference.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep/help-target.html:
--------------------------------------------------------------------------------
1 |
2 | Optional target frame that is used when http link is opened.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep/help-text.html:
--------------------------------------------------------------------------------
1 |
2 | Optional text that will be displayed to the user as either short text or hover of an icon.
3 | Text can be plain text or HTML depending on the selected
Markdown Formatter
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Adds one or more error badges to the current Pipeline build.
4 | Error badges text messages with an icon and an optional clickable hyperlink.
5 | Error badges are often used to provide a visual indicator of additional status information about a Pipeline build.
6 | Error badges added by addErrorBadge
are displayed in the build history of the Pipeline job.
7 |
8 |
9 |
Example: Badge with text
10 |
11 | The following example adds an error badge with the text, "This is alarming":
12 |
addErrorBadge text: 'This is alarming'
13 |
14 |
15 |
Example: Badge with text and link
16 |
17 | The following example adds an error badge with the text, "This is alarming" and a link:
18 |
addErrorBadge text: 'This is alarming', link: 'https://issues.jenkins.io/browse/JENKINS-59646', target: '_blank'
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddHtmlBadgeStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | This step has been deprecated and should be replaced by addBadge
.
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep/help-id.html:
--------------------------------------------------------------------------------
1 |
2 | Optional identifier for the badge in case later operations in the Pipeline job need to delete it.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep/help-link.html:
--------------------------------------------------------------------------------
1 |
2 | Optional URL that will be opened when the user clicks the badge.
3 | Can also be a relative path or mailto:
reference.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep/help-target.html:
--------------------------------------------------------------------------------
1 |
2 | Optional target frame that is used when http link is opened.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep/help-text.html:
--------------------------------------------------------------------------------
1 |
2 | Optional text that will be displayed to the user as either short text or hover of an icon.
3 | Text can be plain text or HTML depending on the selected
Markdown Formatter
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Adds one or more info badges to the current Pipeline build.
4 | Info badges text messages with an icon and an optional clickable hyperlink.
5 | Info badges are often used to provide a visual indicator of additional status information about a Pipeline build.
6 | Info badges added by addInfoBadge
are displayed in the build history of the Pipeline job.
7 |
8 |
9 |
Example: Badge with text
10 |
11 | The following example adds an info badge with the text, "This is interesting":
12 |
addInfoBadge text: 'This is interesting'
13 |
14 |
15 |
Example: Badge with text and link
16 |
17 | The following example adds an info badge with the text, "This is interesting" and a link:
18 |
addInfoBadge text: 'This is interesting', link: 'https://plugins.jenkins.io/custom-folder-icon', target: '_blank'
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddShortTextStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | This step has been deprecated and should be replaced by addBadge
.
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddSummaryStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
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 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddSummaryStep/help-cssClass.html:
--------------------------------------------------------------------------------
1 |
2 | Optional CSS class for the badge. Classes will be applied to the enclosing
<span>
of a summary.
3 | User can also reference Jenkins built-in CSS classes such as
icon-sm
- see
Jenkins Design Library for more details.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddSummaryStep/help-icon.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | The plugin supports symbols from the Ionicons API as well as the Emoji Symbols API.
4 | More symbols can be added by installing additional plugins, such as Font Awesome API or IT Symbols API.
5 | Symbols from plugins are referenced as "symbol-icon-name plugin-plugin-name" and Jenkins Core icons as "icon-icon-name" or "symbol-icon-name" - see Jenkins Design Library for more details.
6 | For example, the following are all valid references to symbols:
7 |
8 | addSummary icon: 'symbol-alert-circle-outline plugin-ionicons-api', text: 'This is an alert symbol'
9 | addSummary icon: 'symbol-bar-chart-filled plugin-ionicons-api', text: 'This is a bar chart symbol'
10 | addSummary icon: 'symbol-emoji_sloth plugin-emoji-symbols-api', text: 'This is a sloth symbol'
11 | addSummary icon: 'symbol-solid/flag-checkered plugin-font-awesome-api', text: 'This is a checkered flag from font-awesome. Note the slash between the icon family and the name.
12 | addSummary icon: 'symbol-cube', text: 'This is a Jenkins Core symbol'
13 | addSummary icon: 'icon-gear', text: 'This is a Jenkins Core icon'
14 |
15 |
16 |
17 |
18 | The plugin allows you to also reference images from within Jenkins as well as relative and remote URL:
19 |
20 | addSummary icon: '/jenkins.png', text: 'This is a relative image'
21 | addSummary icon: 'https://foo.bar/icon.png', text: 'This is a remote icon'
22 | addSummary icon: 'blue.png', text: 'This is a icon from Jenkins'
23 |
24 |
25 |
26 |
27 | The plugin includes icons as GIF images and also supports the 16x16 icons that are offered by Jenkins.
28 | These icons are listed in the plugin documentation and are referenced as "image-name.gif".
29 | For example, the following are all valid references to icons that can be used with the plugin:
30 |
31 | addSummary icon: 'aborted.gif', text: 'This is a aborted symbol'
32 | addSummary icon: 'folder-open.gif', text: 'This is a folder icon'
33 | addSummary icon: 'document_edit.gif', text: 'This is a document icon'
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddSummaryStep/help-id.html:
--------------------------------------------------------------------------------
1 |
2 | Optional identifier for the summary in case later operations in the Pipeline job need to delete it.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddSummaryStep/help-link.html:
--------------------------------------------------------------------------------
1 |
2 | Optional URL that will be opened when the user clicks the summary text.
3 | Can also be a relative path or mailto:
reference.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddSummaryStep/help-style.html:
--------------------------------------------------------------------------------
1 |
2 | Optional CSS style for the badge. Styles will be applied to the enclosing
<span>
of a summary.
3 | User can also reference Jenkins built-in styles such as
color: var(--warning-color)
- see
Jenkins Design Library for more details.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddSummaryStep/help-target.html:
--------------------------------------------------------------------------------
1 |
2 | Optional target frame that is used when http link is opened.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddSummaryStep/help-text.html:
--------------------------------------------------------------------------------
1 |
2 | Optional text that will be displayed next to an icon.
3 | Text can be plain text or HTML depending on the selected
Markdown Formatter
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddSummaryStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Adds one or more summaries to the current Pipeline build.
4 | Summaries are symbols or icons with an optional text message and an optional clickable hyperlink.
5 | Summaries are often used to provide a visual indicator of additional status information about a Pipeline build.
6 | Summaries added by addSummary
are displayed in the build overview of the Pipeline job.
7 |
8 |
9 |
10 | The plugin supports symbols from the ionicons library through the ionicons-api-plugin.
11 | More symbols can be added by installing additional plugins, such as font-awesome-api-plugin or custom-folder-icon-plugin.
12 | Symbols from plugins are referenced as "symbol-icon-name plugin-plugin-name" and Jenkins Core icons as "icon-icon-name" or "symbol-icon-name".
13 | For example, the following are all valid references to symbols:
14 |
15 | addSummary icon: 'symbol-alert-circle-outline plugin-ionicons-api', text: 'This is an alert symbol'
16 | addSummary icon: 'symbol-bar-chart-filled plugin-ionicons-api', text: 'This is a bar chart symbol'
17 | addSummary icon: 'symbol-battery-half-sharp plugin-ionicons-api', text: 'This is a half filled battery symbol'
18 | addSummary icon: 'symbol-emoji_sloth plugin-emoji-symbols-api', text: 'This is a sloth symbol'
19 | addSummary icon: 'symbol-solid/flag-checkered plugin-font-awesome-api', text: 'This is a checkered flag from font-awesome. Note the slash between the icon family and the name.
20 | addSummary icon: 'symbol-cube', text: 'This is a Jenkins Core symbol'
21 | addSummary icon: 'icon-gear', text: 'This is a Jenkins Core icon'
22 |
23 |
24 |
25 |
26 | The plugin allows you to also reference images from within Jenkins as well as relative and remote URL:
27 |
28 | addSummary icon: '/jenkins.png', text: 'This is a relative image'
29 | addSummary icon: 'https://foo.bar/icon.png', text: 'This is a remote icon'
30 | addSummary icon: 'blue.png', text: 'This is a icon from Jenkins'
31 |
32 |
33 |
34 |
35 | The plugin includes icons as GIF images and also supports the 16x16 icons that are offered by Jenkins.
36 | These icons are listed in the plugin documentation and are referenced as "image-name.gif".
37 | For example, the following are all valid references to icons included with the plugin:
38 |
39 | addSummary icon: 'completed.gif', text: 'This is a completed symbol'
40 | addSummary icon: 'success.gif', text: 'This is a success icon'
41 | addSummary icon: 'warning.gif', text: 'This is a warning icon'
42 |
43 |
44 |
45 |
Example: Summary with completed icon
46 |
47 | The following example adds a "completed" checkmark icon with the text, "This is completed":
48 |
addSummary icon: 'completed.gif', text: 'This is completed'
49 |
50 |
51 |
Example: Summary with alarm symbol
52 |
53 | The following example adds an alarm symbol with the text, "This is alarming":
54 |
addSummary icon: 'symbol-alarm-outline plugin-ionicons-api', text: 'This is alarming'
55 |
56 |
57 |
Example: Summary with red bug symbol
58 |
59 | The following example adds a red bug badge symbol the text, "This is a red bug with a link", and a link:
60 |
addSummary icon: 'symbol-bug plugin-ionicons-api', text: 'This is a red bug with a link', style: 'color: red', link: 'https://issues.jenkins.io/browse/JENKINS-59646', target: '_blank'
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep/help-id.html:
--------------------------------------------------------------------------------
1 |
2 | Optional identifier for the badge in case later operations in the Pipeline job need to delete it.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep/help-link.html:
--------------------------------------------------------------------------------
1 |
2 | Optional URL that will be opened when the user clicks the badge.
3 | Can also be a relative path or mailto:
reference.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep/help-target.html:
--------------------------------------------------------------------------------
1 |
2 | Optional target frame that is used when http link is opened.
3 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep/help-text.html:
--------------------------------------------------------------------------------
1 |
2 | Optional text that will be displayed to the user as either short text or hover of an icon.
3 | Text can be plain text or HTML depending on the selected
Markdown Formatter
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Adds one or more error badges to the current Pipeline build.
4 | Warning badges text messages with an icon and an optional clickable hyperlink.
5 | Warning badges are often used to provide a visual indicator of additional status information about a Pipeline build.
6 | Warning badges added by addWarningBadge
are displayed in the build history of the Pipeline job.
7 |
8 |
9 |
Example: Badge with text
10 |
11 | The following example adds a warning badge with the text, "This is alarming":
12 |
addWarningBadge text: 'This is alarming'
13 |
14 |
15 |
Example: Badge with text and link
16 |
17 | The following example adds a warning badge with the text, "This is alarming" and a link:
18 |
addWarningBadge text: 'This is alarming', link: 'https://issues.jenkins.io/browse/JENKINS-59646', target: '_blank'
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/CreateSummaryStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | This step has been deprecated and should be replaced by addSummary
.
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/RemoveBadgesStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/RemoveBadgesStep/help-id.html:
--------------------------------------------------------------------------------
1 |
2 | Optional identifier for the badge to remove.
3 | If not set, all badges will be removed.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/RemoveBadgesStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Removes badges with the given id
from the Pipeline build.
4 | If no id
is given, all badges will be removed from the Pipeline build.
5 |
6 |
7 |
Example: Remove badge with id
8 |
9 | The following example removes a badge with the id, "test":
10 |
removeBadges id: 'test'
11 |
12 |
13 |
Example: Remove all badges
14 |
15 | The following example removes all badges:
16 |
removeBadges()
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/RemoveHtmlBadgesStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | This step has been deprecated and should be replaced by addBadge
and removeBadges
.
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/RemoveSummariesStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/RemoveSummariesStep/help-id.html:
--------------------------------------------------------------------------------
1 |
2 | Optional identifier for the summary to remove.
3 | If not set, all summaries will be removed.
4 |
--------------------------------------------------------------------------------
/src/main/resources/com/jenkinsci/plugins/badge/dsl/RemoveSummariesStep/help.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Removes summaries with the given id
from the build overview.
4 | If no id
is given, all summaries will be removed from the build overview.
5 |
6 |
7 |
Example: Remove summary with id
8 |
9 | The following example removes a summary with the id, "test":
10 |
removeSummaries id: 'test'
11 |
12 |
13 |
Example: Remove all summaries
14 |
15 | The following example removes all summaries:
16 |
removeSummaries()
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/resources/index.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 | Add Badges for a build and extend the build summary
29 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/action/ActionClassHierarchyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.action;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertFalse;
27 | import static org.junit.jupiter.api.Assertions.assertTrue;
28 |
29 | import hudson.model.Action;
30 | import hudson.model.BuildBadgeAction;
31 | import org.junit.jupiter.api.Nested;
32 | import org.junit.jupiter.api.Test;
33 |
34 | class ActionClassHierarchyTest {
35 |
36 | @Nested
37 | class Badge {
38 |
39 | @Test
40 | void abstractBadgeAction() {
41 | assertTrue(Action.class.isAssignableFrom(AbstractBadgeAction.class));
42 | assertFalse(BuildBadgeAction.class.isAssignableFrom(AbstractBadgeAction.class));
43 | }
44 |
45 | @Test
46 | void badgeAction() {
47 | assertTrue(Action.class.isAssignableFrom(BadgeAction.class));
48 | assertTrue(BuildBadgeAction.class.isAssignableFrom(BadgeAction.class));
49 | assertTrue(AbstractBadgeAction.class.isAssignableFrom(BadgeAction.class));
50 | }
51 | }
52 |
53 | @Nested
54 | class Summary {
55 |
56 | @Test
57 | void badgeSummaryAction() {
58 | assertTrue(Action.class.isAssignableFrom(BadgeSummaryAction.class));
59 | assertFalse(BuildBadgeAction.class.isAssignableFrom(BadgeSummaryAction.class));
60 | assertTrue(AbstractBadgeAction.class.isAssignableFrom(BadgeSummaryAction.class));
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/action/BadgeActionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.action;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertNull;
27 |
28 | import org.junit.jupiter.api.Test;
29 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
30 |
31 | @WithJenkins
32 | class BadgeActionTest extends AbstractBadgeActionTest {
33 |
34 | @Override
35 | @Test
36 | @Deprecated
37 | void deprecatedConstructor() {
38 | BadgeAction action = new BadgeAction("id", "icon", "text", "cssClass", "style", "link");
39 | assertNull(action.getTarget());
40 | }
41 |
42 | @Override
43 | protected AbstractBadgeAction createAction(
44 | String id, String icon, String text, String cssClass, String style, String link, String target) {
45 | return new BadgeAction(id, icon, text, cssClass, style, link, target);
46 | }
47 |
48 | @Override
49 | protected String getDisplayName() {
50 | return "Badge Action";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/action/BadgeSummaryActionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.action;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertNull;
27 |
28 | import org.junit.jupiter.api.Test;
29 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
30 |
31 | @WithJenkins
32 | class BadgeSummaryActionTest extends AbstractBadgeActionTest {
33 |
34 | @Override
35 | @Test
36 | @Deprecated
37 | void deprecatedConstructor() {
38 | BadgeSummaryAction action = new BadgeSummaryAction("id", "icon", "text", "cssClass", "style", "link");
39 | assertNull(action.getTarget());
40 | }
41 |
42 | @Override
43 | protected AbstractBadgeAction createAction(
44 | String id, String icon, String text, String cssClass, String style, String link, String target) {
45 | return new BadgeSummaryAction(id, icon, text, cssClass, style, link, target);
46 | }
47 |
48 | @Override
49 | protected String getDisplayName() {
50 | return "Badge Summary Action";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/action/HtmlBadgeActionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.action;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 | import static org.junit.jupiter.api.Assertions.assertNull;
28 |
29 | import edu.umd.cs.findbugs.annotations.NonNull;
30 | import hudson.markup.MarkupFormatter;
31 | import java.io.IOException;
32 | import java.io.Writer;
33 | import java.util.UUID;
34 | import org.junit.jupiter.api.BeforeAll;
35 | import org.junit.jupiter.api.Test;
36 | import org.jvnet.hudson.test.JenkinsRule;
37 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
38 |
39 | @WithJenkins
40 | @Deprecated(since = "2.0", forRemoval = true)
41 | class HtmlBadgeActionTest {
42 |
43 | private static JenkinsRule r;
44 |
45 | @BeforeAll
46 | static void setUp(JenkinsRule rule) {
47 | r = rule;
48 | }
49 |
50 | @Test
51 | void html() {
52 | HtmlBadgeAction action = HtmlBadgeAction.createHtmlBadge(null);
53 | assertEquals("", action.getHtml());
54 |
55 | String html = UUID.randomUUID().toString();
56 | action = HtmlBadgeAction.createHtmlBadge(html);
57 | assertEquals(html, action.getHtml());
58 |
59 | MarkupFormatter formatter = new MarkupFormatter() {
60 | @Override
61 | public void translate(String markup, @NonNull Writer output) throws IOException {
62 | throw new IOException("Oh no!");
63 | }
64 | };
65 | r.jenkins.setMarkupFormatter(formatter);
66 | assertEquals(
67 | "Error preparing HTML content for UI",
68 | action.getHtml());
69 | }
70 |
71 | @Test
72 | void urlName() {
73 | HtmlBadgeAction action = HtmlBadgeAction.createHtmlBadge(null);
74 | assertEquals("", action.getUrlName());
75 | }
76 |
77 | @Test
78 | void displayName() {
79 | HtmlBadgeAction action = HtmlBadgeAction.createHtmlBadge(null);
80 | assertEquals("", action.getDisplayName());
81 | }
82 |
83 | @Test
84 | void iconFileName() {
85 | HtmlBadgeAction action = HtmlBadgeAction.createHtmlBadge(null);
86 | assertNull(action.getIconFileName());
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/action/LegacyConfigurationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.action;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertNotNull;
27 | import static org.junit.jupiter.api.Assertions.assertNull;
28 |
29 | import hudson.XmlFile;
30 | import java.io.File;
31 | import org.junit.jupiter.api.BeforeAll;
32 | import org.junit.jupiter.api.Test;
33 | import org.jvnet.hudson.test.JenkinsRule;
34 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
35 |
36 | @WithJenkins
37 | @Deprecated(since = "2.0", forRemoval = true)
38 | class LegacyConfigurationTest {
39 |
40 | private static JenkinsRule r;
41 |
42 | @BeforeAll
43 | static void setUp(JenkinsRule rule) {
44 | r = rule;
45 | }
46 |
47 | @Test
48 | void badgeAction() throws Exception {
49 | BadgeAction action = readConfiguration("badge-action.xml");
50 | assertNotNull(action.getIcon());
51 | assertNotNull(action.getStyle());
52 |
53 | action = readConfiguration("badge-action-null.xml");
54 | assertNull(action.getIcon());
55 | assertNull(action.getStyle());
56 |
57 | action = readConfiguration("badge-action-borderColor-null.xml");
58 | assertNotNull(action.getStyle());
59 |
60 | action = readConfiguration("badge-action-jenkins.xml");
61 | assertNotNull(action.getStyle());
62 |
63 | action = readConfiguration("badge-action-jenkins-color.xml");
64 | assertNotNull(action.getStyle());
65 | }
66 |
67 | @Test
68 | void badgeSummaryAction() throws Exception {
69 | BadgeSummaryAction action = readConfiguration("summary-action.xml");
70 | assertNotNull(action.getText());
71 |
72 | action = readConfiguration("summary-action-null.xml");
73 | assertNull(action.getText());
74 | }
75 |
76 | @SuppressWarnings("unchecked")
77 | private static T readConfiguration(String file) throws Exception {
78 | return (T) new XmlFile(new File("src/test/resources/legacy-configuration", file)).read();
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/AbstractAddBadgeStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.*;
27 |
28 | import org.junit.jupiter.api.BeforeAll;
29 | import org.junit.jupiter.api.Test;
30 | import org.jvnet.hudson.test.JenkinsRule;
31 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
32 |
33 | @WithJenkins
34 | abstract class AbstractAddBadgeStepTest {
35 |
36 | protected static JenkinsRule r;
37 |
38 | @BeforeAll
39 | static void setUp(JenkinsRule rule) {
40 | r = rule;
41 | }
42 |
43 | @Test
44 | abstract void defaultConstructor();
45 |
46 | @Test
47 | void id() {
48 | AbstractAddBadgeStep step = createStep(null, "icon", "text", "cssClass", "style", "link", "target");
49 | assertNull(step.getId());
50 |
51 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
52 | assertEquals("id", step.getId());
53 |
54 | step = createStep("", "icon", "text", "cssClass", "style", "link", "target");
55 | assertEquals("", step.getId());
56 | }
57 |
58 | @Test
59 | void icon() {
60 | AbstractAddBadgeStep step = createStep("id", null, "text", "cssClass", "style", "link", "target");
61 | assertNull(step.getIcon());
62 |
63 | step.setIcon("");
64 | assertEquals("", step.getIcon());
65 |
66 | step.setIcon("icon");
67 | assertEquals("icon", step.getIcon());
68 | }
69 |
70 | @Test
71 | void text() {
72 | AbstractAddBadgeStep step = createStep("id", "icon", null, "cssClass", "style", "link", "target");
73 | assertNull(step.getText());
74 |
75 | step.setText("");
76 | assertEquals("", step.getText());
77 |
78 | step.setText("text");
79 | assertEquals("text", step.getText());
80 | }
81 |
82 | @Test
83 | void cssClass() {
84 | AbstractAddBadgeStep step = createStep("id", "icon", "text", null, "style", "link", "target");
85 | assertNull(step.getCssClass());
86 |
87 | step.setCssClass("");
88 | assertEquals("", step.getCssClass());
89 |
90 | step.setCssClass("cssClass");
91 | assertEquals("cssClass", step.getCssClass());
92 | }
93 |
94 | @Test
95 | void style() {
96 | AbstractAddBadgeStep step = createStep("id", "icon", "text", "cssClass", null, "link", "target");
97 | assertNull(step.getStyle());
98 |
99 | step.setStyle("");
100 | assertEquals("", step.getStyle());
101 |
102 | step.setStyle("style");
103 | assertEquals("style", step.getStyle());
104 | }
105 |
106 | @Test
107 | void link() {
108 | AbstractAddBadgeStep step = createStep("id", "icon", "text", "cssClass", "style", null, "target");
109 | assertNull(step.getLink());
110 |
111 | step.setLink("");
112 | assertEquals("", step.getLink());
113 |
114 | step.setLink("link");
115 | assertEquals("link", step.getLink());
116 | }
117 |
118 | @Test
119 | void target() {
120 | AbstractAddBadgeStep step = createStep("id", "icon", "text", "cssClass", "style", "link", null);
121 | assertNull(step.getTarget());
122 |
123 | step.setTarget("");
124 | assertEquals("", step.getTarget());
125 |
126 | step.setTarget("target");
127 | assertEquals("target", step.getTarget());
128 | }
129 |
130 | @Test
131 | void string() {
132 | AbstractAddBadgeStep step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
133 | assertNotNull(step.toString());
134 | assertTrue(step.toString().startsWith(step.getDescriptor().getFunctionName()));
135 |
136 | step = createStep(null, null, null, null, null, null, null);
137 | assertNotNull(step.toString());
138 | assertEquals(step.getDescriptor().getFunctionName() + "()", step.toString());
139 | }
140 |
141 | protected abstract AbstractAddBadgeStep createStep(
142 | String id, String icon, String text, String cssClass, String style, String link, String target);
143 | }
144 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/AbstractRemoveBadgesStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 | import static org.junit.jupiter.api.Assertions.assertNotNull;
28 | import static org.junit.jupiter.api.Assertions.assertNull;
29 |
30 | import org.junit.jupiter.api.BeforeAll;
31 | import org.junit.jupiter.api.Test;
32 | import org.jvnet.hudson.test.JenkinsRule;
33 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
34 |
35 | @WithJenkins
36 | abstract class AbstractRemoveBadgesStepTest {
37 |
38 | protected static JenkinsRule r;
39 |
40 | @BeforeAll
41 | static void setUp(JenkinsRule rule) {
42 | r = rule;
43 | }
44 |
45 | @Test
46 | abstract void defaultConstructor();
47 |
48 | @Test
49 | void id() {
50 | AbstractRemoveBadgesStep step = createRemoveStep(null);
51 | assertNull(step.getId());
52 |
53 | step = createRemoveStep("id");
54 | assertEquals("id", step.getId());
55 |
56 | step = createRemoveStep("");
57 | assertEquals("", step.getId());
58 | }
59 |
60 | @Test
61 | void string() {
62 | AbstractRemoveBadgesStep step = createRemoveStep("id");
63 | assertNotNull(step.toString());
64 | assertEquals(step.getDescriptor().getFunctionName() + "(id: '" + step.getId() + "')", step.toString());
65 |
66 | step = createRemoveStep(null);
67 | assertNotNull(step.toString());
68 | assertEquals(step.getDescriptor().getFunctionName() + "()", step.toString());
69 | }
70 |
71 | protected abstract AbstractRemoveBadgesStep createRemoveStep(String id);
72 | }
73 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 | import static org.junit.jupiter.api.Assertions.assertNull;
28 |
29 | import org.junit.jupiter.api.Test;
30 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
31 |
32 | @WithJenkins
33 | class AddErrorBadgeStepTest extends AddBadgeStepTest {
34 |
35 | @Override
36 | @Test
37 | void defaultConstructor() {
38 | AbstractAddBadgeStep step = new AddErrorBadgeStep();
39 | assertNull(step.getId());
40 | assertEquals("symbol-remove-circle plugin-ionicons-api", step.getIcon());
41 | assertNull(step.getText());
42 | assertNull(step.getCssClass());
43 | assertEquals("color: var(--error-color)", step.getStyle());
44 | assertNull(step.getLink());
45 | assertNull(step.getTarget());
46 | }
47 |
48 | @Override
49 | @Test
50 | void icon() {
51 | AbstractAddBadgeStep step = createStep("id", null, "text", "cssClass", "style", "link", "target");
52 | assertEquals("symbol-remove-circle plugin-ionicons-api", step.getIcon());
53 |
54 | step = createStep("id", "", "text", "cssClass", "style", "link", "target");
55 | assertEquals("symbol-remove-circle plugin-ionicons-api", step.getIcon());
56 |
57 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
58 | assertEquals("symbol-remove-circle plugin-ionicons-api", step.getIcon());
59 | }
60 |
61 | @Override
62 | @Test
63 | void cssClass() {
64 | AbstractAddBadgeStep step = createStep("id", "icon", "text", null, "style", "link", "target");
65 | assertNull(step.getCssClass());
66 |
67 | step = createStep("id", "icon", "text", "", "style", "link", "target");
68 | assertNull(step.getCssClass());
69 |
70 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
71 | assertNull(step.getCssClass());
72 | }
73 |
74 | @Override
75 | @Test
76 | void style() {
77 | AbstractAddBadgeStep step = createStep("id", "icon", "text", "cssClass", null, "link", "target");
78 | assertEquals("color: var(--error-color)", step.getStyle());
79 |
80 | step = createStep("id", "icon", "text", "cssClass", "", "link", "target");
81 | assertEquals("color: var(--error-color)", step.getStyle());
82 |
83 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
84 | assertEquals("color: var(--error-color)", step.getStyle());
85 | }
86 |
87 | @Override
88 | protected AbstractAddBadgeStep createStep(
89 | String id, String icon, String text, String cssClass, String style, String link, String target) {
90 | return new AddErrorBadgeStep(id, text, link, target);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/AddHtmlBadgeStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 | import static org.junit.jupiter.api.Assertions.assertNull;
28 | import static org.junit.jupiter.api.Assertions.assertTrue;
29 |
30 | import com.jenkinsci.plugins.badge.action.HtmlBadgeAction;
31 | import hudson.markup.RawHtmlMarkupFormatter;
32 | import hudson.model.BuildBadgeAction;
33 | import java.util.List;
34 | import java.util.UUID;
35 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
36 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
37 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
38 | import org.junit.jupiter.api.BeforeAll;
39 | import org.junit.jupiter.api.Test;
40 | import org.jvnet.hudson.test.JenkinsRule;
41 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
42 |
43 | @WithJenkins
44 | @Deprecated(since = "2.0", forRemoval = true)
45 | class AddHtmlBadgeStepTest {
46 |
47 | private static JenkinsRule r;
48 |
49 | @BeforeAll
50 | static void setUp(JenkinsRule rule) {
51 | r = rule;
52 | }
53 |
54 | @Test
55 | void id() {
56 | AddHtmlBadgeStep step = new AddHtmlBadgeStep(null);
57 | assertNull(step.getId());
58 |
59 | String id = UUID.randomUUID().toString();
60 | step.setId(id);
61 | assertEquals(id, step.getId());
62 | }
63 |
64 | @Test
65 | void html() {
66 | AddHtmlBadgeStep step = new AddHtmlBadgeStep(null);
67 | assertNull(step.getHtml());
68 |
69 | String html = UUID.randomUUID().toString();
70 | step = new AddHtmlBadgeStep(html);
71 | assertEquals(html, step.getHtml());
72 | }
73 |
74 | @Test
75 | void deprecated() {
76 | AddHtmlBadgeStep step = new AddHtmlBadgeStep(null);
77 | assertTrue(step.getDescriptor().isAdvanced());
78 | }
79 |
80 | @Test
81 | void addHtmlBadge() throws Exception {
82 | String html = UUID.randomUUID().toString();
83 | testAddHtmlBadge(html, html);
84 | }
85 |
86 | @Test
87 | void addHtmlBadge_remove_script() throws Exception {
88 | r.jenkins.setMarkupFormatter(RawHtmlMarkupFormatter.INSTANCE);
89 | String uuid = UUID.randomUUID().toString();
90 | String html = uuid + "";
91 | testAddHtmlBadge(html, uuid);
92 | }
93 |
94 | private static void testAddHtmlBadge(String html, String expected) throws Exception {
95 | WorkflowJob p = r.createProject(WorkflowJob.class);
96 |
97 | String script = "addHtmlBadge(\"" + html + "\")";
98 |
99 | p.setDefinition(new CpsFlowDefinition(script, true));
100 | WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
101 |
102 | List badgeActions = b.getBadgeActions();
103 | assertEquals(1, badgeActions.size());
104 |
105 | HtmlBadgeAction action = (HtmlBadgeAction) badgeActions.get(0);
106 | assertEquals(expected, action.getHtml());
107 | assertEquals(html, action.getRawHtml());
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 | import static org.junit.jupiter.api.Assertions.assertNull;
28 |
29 | import org.junit.jupiter.api.Test;
30 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
31 |
32 | @WithJenkins
33 | class AddInfoBadgeStepTest extends AddBadgeStepTest {
34 |
35 | @Override
36 | @Test
37 | void defaultConstructor() {
38 | AbstractAddBadgeStep step = new AddInfoBadgeStep();
39 | assertNull(step.getId());
40 | assertEquals("symbol-information-circle plugin-ionicons-api", step.getIcon());
41 | assertNull(step.getText());
42 | assertNull(step.getCssClass());
43 | assertEquals("color: var(--blue)", step.getStyle());
44 | assertNull(step.getLink());
45 | assertNull(step.getTarget());
46 | }
47 |
48 | @Override
49 | @Test
50 | void icon() {
51 | AbstractAddBadgeStep step = createStep("id", null, "text", "cssClass", "style", "link", "target");
52 | assertEquals("symbol-information-circle plugin-ionicons-api", step.getIcon());
53 |
54 | step = createStep("id", "", "text", "cssClass", "style", "link", "target");
55 | assertEquals("symbol-information-circle plugin-ionicons-api", step.getIcon());
56 |
57 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
58 | assertEquals("symbol-information-circle plugin-ionicons-api", step.getIcon());
59 | }
60 |
61 | @Override
62 | @Test
63 | void cssClass() {
64 | AbstractAddBadgeStep step = createStep("id", "icon", "text", null, "style", "link", "target");
65 | assertNull(step.getCssClass());
66 |
67 | step = createStep("id", "icon", "text", "", "style", "link", "target");
68 | assertNull(step.getCssClass());
69 |
70 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
71 | assertNull(step.getCssClass());
72 | }
73 |
74 | @Override
75 | @Test
76 | void style() {
77 | AbstractAddBadgeStep step = createStep("id", "icon", "text", "cssClass", null, "link", "target");
78 | assertEquals("color: var(--blue)", step.getStyle());
79 |
80 | step = createStep("id", "icon", "text", "cssClass", "", "link", "target");
81 | assertEquals("color: var(--blue)", step.getStyle());
82 |
83 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
84 | assertEquals("color: var(--blue)", step.getStyle());
85 | }
86 |
87 | @Override
88 | protected AbstractAddBadgeStep createStep(
89 | String id, String icon, String text, String cssClass, String style, String link, String target) {
90 | return new AddInfoBadgeStep(id, text, link, target);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/AddSummaryStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertNull;
27 |
28 | import org.junit.jupiter.api.Test;
29 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
30 |
31 | @WithJenkins
32 | class AddSummaryStepTest extends AddBadgeStepTest {
33 |
34 | @Override
35 | @Test
36 | void defaultConstructor() {
37 | AbstractAddBadgeStep step = new AddSummaryStep();
38 | assertNull(step.getId());
39 | assertNull(step.getIcon());
40 | assertNull(step.getText());
41 | assertNull(step.getCssClass());
42 | assertNull(step.getStyle());
43 | assertNull(step.getLink());
44 | assertNull(step.getTarget());
45 | }
46 |
47 | @Override
48 | protected AbstractAddBadgeStep createStep(
49 | String id, String icon, String text, String cssClass, String style, String link, String target) {
50 | return new AddSummaryStep(id, icon, text, cssClass, style, link, target);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 | import static org.junit.jupiter.api.Assertions.assertNull;
28 |
29 | import org.junit.jupiter.api.Test;
30 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
31 |
32 | @WithJenkins
33 | class AddWarningBadgeStepTest extends AddBadgeStepTest {
34 |
35 | @Override
36 | @Test
37 | void defaultConstructor() {
38 | AbstractAddBadgeStep step = new AddWarningBadgeStep();
39 | assertNull(step.getId());
40 | assertEquals("symbol-warning plugin-ionicons-api", step.getIcon());
41 | assertNull(step.getText());
42 | assertNull(step.getCssClass());
43 | assertEquals("color: var(--warning-color)", step.getStyle());
44 | assertNull(step.getLink());
45 | assertNull(step.getTarget());
46 | }
47 |
48 | @Override
49 | @Test
50 | void icon() {
51 | AbstractAddBadgeStep step = createStep("id", null, "text", "cssClass", "style", "link", "target");
52 | assertEquals("symbol-warning plugin-ionicons-api", step.getIcon());
53 |
54 | step = createStep("id", "", "text", "cssClass", "style", "link", "target");
55 | assertEquals("symbol-warning plugin-ionicons-api", step.getIcon());
56 |
57 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
58 | assertEquals("symbol-warning plugin-ionicons-api", step.getIcon());
59 | }
60 |
61 | @Override
62 | @Test
63 | void cssClass() {
64 | AbstractAddBadgeStep step = createStep("id", "icon", "text", null, "style", "link", "target");
65 | assertNull(step.getCssClass());
66 |
67 | step = createStep("id", "icon", "text", "", "style", "link", "target");
68 | assertNull(step.getCssClass());
69 |
70 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
71 | assertNull(step.getCssClass());
72 | }
73 |
74 | @Override
75 | @Test
76 | void style() {
77 | AbstractAddBadgeStep step = createStep("id", "icon", "text", "cssClass", null, "link", "target");
78 | assertEquals("color: var(--warning-color)", step.getStyle());
79 |
80 | step = createStep("id", "icon", "text", "cssClass", "", "link", "target");
81 | assertEquals("color: var(--warning-color)", step.getStyle());
82 |
83 | step = createStep("id", "icon", "text", "cssClass", "style", "link", "target");
84 | assertEquals("color: var(--warning-color)", step.getStyle());
85 | }
86 |
87 | @Override
88 | protected AbstractAddBadgeStep createStep(
89 | String id, String icon, String text, String cssClass, String style, String link, String target) {
90 | return new AddWarningBadgeStep(id, text, link, target);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/CreateSummaryStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static java.util.UUID.randomUUID;
27 | import static org.junit.jupiter.api.Assertions.assertEquals;
28 | import static org.junit.jupiter.api.Assertions.assertNull;
29 | import static org.junit.jupiter.api.Assertions.assertTrue;
30 |
31 | import com.jenkinsci.plugins.badge.action.BadgeSummaryAction;
32 | import hudson.markup.RawHtmlMarkupFormatter;
33 | import java.util.List;
34 | import java.util.UUID;
35 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
36 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
37 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
38 | import org.junit.jupiter.api.BeforeAll;
39 | import org.junit.jupiter.api.Test;
40 | import org.jvnet.hudson.test.JenkinsRule;
41 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
42 |
43 | @WithJenkins
44 | @Deprecated(since = "2.0", forRemoval = true)
45 | class CreateSummaryStepTest {
46 |
47 | private static JenkinsRule r;
48 |
49 | @BeforeAll
50 | static void setUp(JenkinsRule rule) {
51 | r = rule;
52 | }
53 |
54 | @Test
55 | void id() {
56 | CreateSummaryStep step = new CreateSummaryStep(null);
57 | assertNull(step.getId());
58 |
59 | String id = UUID.randomUUID().toString();
60 | step.setId(id);
61 | assertEquals(id, step.getId());
62 | }
63 |
64 | @Test
65 | void icon() {
66 | CreateSummaryStep step = new CreateSummaryStep(null);
67 | assertNull(step.getIcon());
68 |
69 | String icon = UUID.randomUUID().toString();
70 | step = new CreateSummaryStep(icon);
71 | assertEquals(icon, step.getIcon());
72 | }
73 |
74 | @Test
75 | void text() {
76 | CreateSummaryStep step = new CreateSummaryStep(null);
77 | assertNull(step.getText());
78 |
79 | String text = UUID.randomUUID().toString();
80 | step.setText(text);
81 | assertEquals(text, step.getText());
82 | }
83 |
84 | @Test
85 | void deprecated() {
86 | CreateSummaryStep step = new CreateSummaryStep(null);
87 | assertTrue(step.getDescriptor().isAdvanced());
88 | }
89 |
90 | @Test
91 | void createSummary_plain() throws Exception {
92 | String text = randomUUID().toString();
93 | BadgeSummaryAction action = createSummary("summary.appendText('" + text + "')");
94 | assertEquals(text, action.getText());
95 | }
96 |
97 | @Test
98 | void createSummary_html_unescaped() throws Exception {
99 | r.jenkins.setMarkupFormatter(RawHtmlMarkupFormatter.INSTANCE);
100 | String text = randomUUID().toString();
101 | BadgeSummaryAction action = createSummary("summary.appendText('', false)");
102 | assertEquals("", action.getText());
103 | }
104 |
105 | @Test
106 | void createSummary_html_unescaped_remove_script() throws Exception {
107 | r.jenkins.setMarkupFormatter(RawHtmlMarkupFormatter.INSTANCE);
108 | String text = randomUUID().toString();
109 | String html = "";
110 | BadgeSummaryAction action = createSummary("summary.appendText('" + html + "', false);");
111 | assertEquals("", action.getText());
112 | }
113 |
114 | @Test
115 | void createSummary_html_escaped() throws Exception {
116 | r.jenkins.setMarkupFormatter(RawHtmlMarkupFormatter.INSTANCE);
117 | String text = randomUUID().toString();
118 | BadgeSummaryAction action = createSummary("summary.appendText('', true)");
119 | assertEquals("<ul><li>" + text + "</li></ul>", action.getText());
120 | }
121 |
122 | @Test
123 | void createSummary_all() throws Exception {
124 | r.jenkins.setMarkupFormatter(RawHtmlMarkupFormatter.INSTANCE);
125 | String text = randomUUID().toString();
126 | BadgeSummaryAction action = createSummary("summary.appendText('" + text + "', false, true, true, 'grey')");
127 | assertEquals("" + text + "", action.getText());
128 | }
129 |
130 | @Test
131 | void createSummary_with_text() throws Exception {
132 | String icon = randomUUID().toString();
133 | String text = randomUUID().toString();
134 |
135 | WorkflowJob p = r.createProject(WorkflowJob.class);
136 | p.setDefinition(new CpsFlowDefinition(
137 | "def summary = createSummary(icon:\"" + icon + "\", text:\"" + text + "\")", true));
138 | WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
139 | List summaryActions = b.getActions(BadgeSummaryAction.class);
140 | assertEquals(1, summaryActions.size());
141 |
142 | BadgeSummaryAction action = summaryActions.get(0);
143 | assertTrue(action.getIcon().endsWith(icon));
144 | assertEquals(text, action.getText());
145 | }
146 |
147 | private static BadgeSummaryAction createSummary(String script) throws Exception {
148 | String icon = randomUUID().toString();
149 |
150 | WorkflowJob p = r.createProject(WorkflowJob.class);
151 | p.setDefinition(new CpsFlowDefinition("def summary = createSummary(\"" + icon + "\")\n" + script, true));
152 | WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
153 | List summaryActions = b.getActions(BadgeSummaryAction.class);
154 | assertEquals(1, summaryActions.size());
155 |
156 | BadgeSummaryAction action = summaryActions.get(0);
157 | assertTrue(action.getIcon().endsWith(icon));
158 | return action;
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/LegacyPipelineTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertAll;
27 | import static org.junit.jupiter.api.Assertions.assertEquals;
28 |
29 | import com.jenkinsci.plugins.badge.action.BadgeAction;
30 | import com.jenkinsci.plugins.badge.action.BadgeSummaryAction;
31 | import hudson.markup.RawHtmlMarkupFormatter;
32 | import hudson.model.BuildBadgeAction;
33 | import java.util.Arrays;
34 | import java.util.List;
35 | import java.util.stream.Stream;
36 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
37 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
38 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
39 | import org.junit.jupiter.api.BeforeAll;
40 | import org.junit.jupiter.api.Test;
41 | import org.junit.jupiter.api.function.Executable;
42 | import org.jvnet.hudson.test.JenkinsRule;
43 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
44 |
45 | @WithJenkins
46 | @Deprecated(since = "2.0", forRemoval = true)
47 | class LegacyPipelineTest {
48 |
49 | private static JenkinsRule r;
50 |
51 | @BeforeAll
52 | static void setUp(JenkinsRule rule) {
53 | r = rule;
54 | }
55 |
56 | @Test
57 | void color() {
58 | List colors = Arrays.asList(
59 | "blue", "brown", "cyan", "green", "indigo", "orange", "pink", "purple", "red", "yellow", "white",
60 | "black");
61 | Stream> palette =
62 | colors.stream().map(c -> Arrays.asList("'" + c + "'", "color: var(--" + c + ");"));
63 | Stream> paletteLight =
64 | colors.stream().map(c -> Arrays.asList("'light-" + c + "'", "color: var(--light-" + c + ");"));
65 | Stream> paletteDark =
66 | colors.stream().map(c -> Arrays.asList("'dark-" + c + "'", "color: var(--dark-" + c + ");"));
67 |
68 | List semantics = Arrays.asList(
69 | "accent", "text", "error", "warning", "success", "destructive", "build", "danger", "info");
70 | Stream> semantic =
71 | semantics.stream().map(c -> Arrays.asList("'" + c + "'", "color: var(--" + c + "-color);"));
72 |
73 | Stream> other = Stream.of(
74 | Arrays.asList("'light-'", "color: light-;"),
75 | Arrays.asList("'dark-'", "color: dark-;"),
76 | Arrays.asList("'#ff0000'", "color: #ff0000;"),
77 | Arrays.asList("'tortoise'", "color: tortoise;"),
78 | Arrays.asList("'jenkins-!-color-red'", "color: var(--red);"),
79 | Arrays.asList("'jenkins-!-warning-color'", "color: var(--warning-color);"),
80 | Arrays.asList("''", "color: ;"),
81 | Arrays.asList("null", null));
82 |
83 | assertAll("palette", colorTests(palette));
84 | assertAll("palette-light", colorTests(paletteLight));
85 | assertAll("palette-dark", colorTests(paletteDark));
86 | assertAll("semantic", colorTests(semantic));
87 | assertAll("other", colorTests(other));
88 | }
89 |
90 | private static Stream colorTests(Stream> tests) {
91 | return tests.map(params -> () -> {
92 | WorkflowRun run = runJob("addBadge(color: " + params.get(0) + ")");
93 |
94 | List badgeActions = run.getBadgeActions();
95 | assertEquals(1, badgeActions.size());
96 |
97 | BadgeAction action = (BadgeAction) badgeActions.get(0);
98 | assertEquals(params.get(1), action.getStyle());
99 | });
100 | }
101 |
102 | @Test
103 | void appendText() throws Exception {
104 | WorkflowRun run = runJob("createSummary(text: 'Test Text')");
105 |
106 | List actions = run.getActions(BadgeSummaryAction.class);
107 | assertEquals(1, actions.size());
108 |
109 | BadgeSummaryAction action = actions.get(0);
110 | assertEquals("Test Text", action.getText());
111 |
112 | run = runJob("def summary = createSummary(text: 'Test Text')\n" + "summary.appendText(' More Text', true)");
113 |
114 | actions = run.getActions(BadgeSummaryAction.class);
115 | assertEquals(1, actions.size());
116 |
117 | action = actions.get(0);
118 | assertEquals("Test Text More Text", action.getText());
119 |
120 | run = runJob("def summary = createSummary(text: 'Test Text')\n" + "summary.appendText(' More Text', false)");
121 |
122 | actions = run.getActions(BadgeSummaryAction.class);
123 | assertEquals(1, actions.size());
124 |
125 | action = actions.get(0);
126 | assertEquals("Test Text More Text", action.getText());
127 |
128 | run = runJob(
129 | """
130 | def summary = createSummary(text: 'Test Text')
131 | summary.appendText(' More Text', false, false, false, null)
132 | """);
133 |
134 | actions = run.getActions(BadgeSummaryAction.class);
135 | assertEquals(1, actions.size());
136 |
137 | action = actions.get(0);
138 | assertEquals("Test Text More Text", action.getText());
139 |
140 | r.jenkins.setMarkupFormatter(RawHtmlMarkupFormatter.INSTANCE);
141 | run = runJob(
142 | """
143 | def summary = createSummary(text: 'Test Text')
144 | summary.appendText(' More Text', true, true, true, 'red')
145 | """);
146 |
147 | actions = run.getActions(BadgeSummaryAction.class);
148 | assertEquals(1, actions.size());
149 |
150 | action = actions.get(0);
151 | assertEquals("Test Text More Text", action.getText());
152 | }
153 |
154 | private static WorkflowRun runJob(String script) throws Exception {
155 | WorkflowJob project = r.createProject(WorkflowJob.class);
156 | project.setDefinition(new CpsFlowDefinition(script, true));
157 | return r.assertBuildStatusSuccess(project.scheduleBuild2(0));
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/RemoveBadgesStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 | import static org.junit.jupiter.api.Assertions.assertNull;
28 |
29 | import com.jenkinsci.plugins.badge.action.AbstractBadgeAction;
30 | import java.util.List;
31 | import java.util.UUID;
32 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
33 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
34 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
35 | import org.junit.jupiter.api.Test;
36 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
37 |
38 | @WithJenkins
39 | class RemoveBadgesStepTest extends AbstractRemoveBadgesStepTest {
40 |
41 | @Override
42 | @Test
43 | void defaultConstructor() {
44 | AbstractRemoveBadgesStep step = new RemoveBadgesStep();
45 | assertNull(step.getId());
46 | }
47 |
48 | @Test
49 | void removeByIdInScriptedPipeline() throws Exception {
50 | String badgeId = UUID.randomUUID().toString();
51 | AbstractAddBadgeStep addStep = createAddStep(badgeId);
52 | AbstractRemoveBadgesStep removeStep = createRemoveStep(badgeId);
53 | runRemoveJob(addStep, removeStep, 0, false, false);
54 | }
55 |
56 | @Test
57 | void removeByIdInScriptedPipelineInNode() throws Exception {
58 | String badgeId = UUID.randomUUID().toString();
59 | AbstractAddBadgeStep addStep = createAddStep(badgeId);
60 | AbstractRemoveBadgesStep removeStep = createRemoveStep(badgeId);
61 | runRemoveJob(addStep, removeStep, 0, true, false);
62 | }
63 |
64 | @Test
65 | void removeByIdInDeclarativePipeline() throws Exception {
66 | String badgeId = UUID.randomUUID().toString();
67 | AbstractAddBadgeStep addStep = createAddStep(badgeId);
68 | AbstractRemoveBadgesStep removeStep = createRemoveStep(badgeId);
69 | runRemoveJob(addStep, removeStep, 0, false, true);
70 | }
71 |
72 | @Test
73 | void removeAllInScriptedPipeline() throws Exception {
74 | String badgeId = UUID.randomUUID().toString();
75 | AbstractAddBadgeStep addStep = createAddStep(badgeId);
76 | AbstractRemoveBadgesStep removeStep = createRemoveStep(null);
77 | runRemoveJob(addStep, removeStep, 0, false, false);
78 | }
79 |
80 | @Test
81 | void removeAllInScriptedPipelineInNode() throws Exception {
82 | String badgeId = UUID.randomUUID().toString();
83 | AbstractAddBadgeStep addStep = createAddStep(badgeId);
84 | AbstractRemoveBadgesStep removeStep = createRemoveStep(null);
85 | runRemoveJob(addStep, removeStep, 0, true, false);
86 | }
87 |
88 | @Test
89 | void removeAllInDeclarativePipeline() throws Exception {
90 | String badgeId = UUID.randomUUID().toString();
91 | AbstractAddBadgeStep addStep = createAddStep(badgeId);
92 | AbstractRemoveBadgesStep removeStep = createRemoveStep(null);
93 | runRemoveJob(addStep, removeStep, 0, false, true);
94 | }
95 |
96 | @Test
97 | void removeInvalidIdInScriptedPipeline() throws Exception {
98 | String badgeId = UUID.randomUUID().toString();
99 | AbstractAddBadgeStep addStep = createAddStep(badgeId);
100 | AbstractRemoveBadgesStep removeStep = createRemoveStep(UUID.randomUUID().toString());
101 | runRemoveJob(addStep, removeStep, 1, false, false);
102 | }
103 |
104 | @Test
105 | void removeInvalidIdInScriptedPipelineInNode() throws Exception {
106 | String badgeId = UUID.randomUUID().toString();
107 | AbstractAddBadgeStep addStep = createAddStep(badgeId);
108 | AbstractRemoveBadgesStep removeStep = createRemoveStep(UUID.randomUUID().toString());
109 | runRemoveJob(addStep, removeStep, 1, true, false);
110 | }
111 |
112 | @Test
113 | void removeInvalidIdInDeclarativePipeline() throws Exception {
114 | String badgeId = UUID.randomUUID().toString();
115 | AbstractAddBadgeStep addStep = createAddStep(badgeId);
116 | AbstractRemoveBadgesStep removeStep = createRemoveStep(UUID.randomUUID().toString());
117 | runRemoveJob(addStep, removeStep, 1, false, true);
118 | }
119 |
120 | protected void runRemoveJob(
121 | AbstractAddBadgeStep addStep,
122 | AbstractRemoveBadgesStep removeStep,
123 | int expected,
124 | boolean inNode,
125 | boolean declarativePipeline)
126 | throws Exception {
127 | WorkflowJob project = r.createProject(WorkflowJob.class);
128 |
129 | String script = addStep.toString() + "\n";
130 | script += removeStep.toString();
131 |
132 | if (inNode) {
133 | script = "node() { " + script + " }";
134 | }
135 |
136 | if (declarativePipeline) {
137 | script =
138 | """
139 | pipeline {
140 | agent any
141 | stages {
142 | stage('Testing') {
143 | steps {
144 | script {
145 | %s
146 | }
147 | }
148 | }
149 | }
150 | }"""
151 | .formatted(script);
152 | }
153 |
154 | project.setDefinition(new CpsFlowDefinition(script, true));
155 | WorkflowRun run = r.assertBuildStatusSuccess(project.scheduleBuild2(0));
156 |
157 | assertActionExists(run, expected);
158 | }
159 |
160 | protected void assertActionExists(WorkflowRun run, int expected) {
161 | List badgeActions = run.getActions(AbstractBadgeAction.class);
162 | assertEquals(expected, badgeActions.size());
163 | }
164 |
165 | protected AbstractAddBadgeStep createAddStep(String id) {
166 | return new AddBadgeStep(
167 | id,
168 | "symbol-rocket plugin-ionicons-api",
169 | "Test Text",
170 | "icon-md",
171 | "color: green",
172 | "https://jenkins.io",
173 | "_blank");
174 | }
175 |
176 | @Override
177 | protected AbstractRemoveBadgesStep createRemoveStep(String id) {
178 | return new RemoveBadgesStep(id);
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/RemoveHtmlBadgesStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 | import static org.junit.jupiter.api.Assertions.assertTrue;
28 |
29 | import hudson.model.BuildBadgeAction;
30 | import java.util.List;
31 | import java.util.UUID;
32 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
33 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
34 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
35 | import org.junit.jupiter.api.BeforeAll;
36 | import org.junit.jupiter.api.Test;
37 | import org.jvnet.hudson.test.JenkinsRule;
38 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
39 |
40 | @WithJenkins
41 | @Deprecated(since = "2.0", forRemoval = true)
42 | class RemoveHtmlBadgesStepTest {
43 |
44 | private static JenkinsRule r;
45 |
46 | @BeforeAll
47 | static void setUp(JenkinsRule rule) {
48 | r = rule;
49 | }
50 |
51 | @Test
52 | void removeById() throws Exception {
53 | String badgeId = UUID.randomUUID().toString();
54 | AddHtmlBadgeStep addStep = createAddStep(badgeId);
55 | RemoveHtmlBadgesStep removeStep = createRemoveStep(badgeId);
56 | runRemoveJob(addStep, removeStep, 0);
57 | }
58 |
59 | @Test
60 | void removeAll() throws Exception {
61 | String badgeId = UUID.randomUUID().toString();
62 | AddHtmlBadgeStep addStep = createAddStep(badgeId);
63 | RemoveHtmlBadgesStep removeStep = createRemoveStep(null);
64 | runRemoveJob(addStep, removeStep, 0);
65 | }
66 |
67 | @Test
68 | void removeInvalidId() throws Exception {
69 | String badgeId = UUID.randomUUID().toString();
70 | AddHtmlBadgeStep addStep = createAddStep(badgeId);
71 | RemoveHtmlBadgesStep removeStep = createRemoveStep(UUID.randomUUID().toString());
72 | runRemoveJob(addStep, removeStep, 1);
73 | }
74 |
75 | @Test
76 | void deprecated() {
77 | RemoveHtmlBadgesStep removeStep = createRemoveStep(null);
78 | assertTrue(removeStep.getDescriptor().isAdvanced());
79 | }
80 |
81 | private static void runRemoveJob(AddHtmlBadgeStep addStep, RemoveHtmlBadgesStep removeStep, int expected)
82 | throws Exception {
83 | WorkflowJob project = r.createProject(WorkflowJob.class);
84 |
85 | String script = addStep.getDescriptor().getFunctionName() + "("
86 | + (addStep.getId() != null ? "id: '" + addStep.getId() + "', " : "") + "html: '" + addStep.getHtml()
87 | + "')\n";
88 | script += removeStep.getDescriptor().getFunctionName() + "("
89 | + (removeStep.getId() != null ? "id: '" + removeStep.getId() + "'" : "") + ")";
90 |
91 | project.setDefinition(new CpsFlowDefinition(script, true));
92 | WorkflowRun run = r.assertBuildStatusSuccess(project.scheduleBuild2(0));
93 |
94 | assertActionExists(run, expected);
95 | }
96 |
97 | private static void assertActionExists(WorkflowRun run, int expected) {
98 | List badgeActions = run.getBadgeActions();
99 | assertEquals(expected, badgeActions.size());
100 | }
101 |
102 | private static AddHtmlBadgeStep createAddStep(String id) {
103 | AddHtmlBadgeStep step = new AddHtmlBadgeStep("Test Text");
104 | step.setId(id);
105 | return step;
106 | }
107 |
108 | private static RemoveHtmlBadgesStep createRemoveStep(String id) {
109 | RemoveHtmlBadgesStep step = new RemoveHtmlBadgesStep();
110 | step.setId(id);
111 | return step;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/RemoveSummariesStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertNull;
27 |
28 | import org.junit.jupiter.api.Test;
29 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
30 |
31 | @WithJenkins
32 | class RemoveSummariesStepTest extends RemoveBadgesStepTest {
33 |
34 | @Override
35 | @Test
36 | void defaultConstructor() {
37 | AbstractRemoveBadgesStep step = new RemoveSummariesStep();
38 | assertNull(step.getId());
39 | }
40 |
41 | @Override
42 | protected AbstractAddBadgeStep createAddStep(String id) {
43 | return new AddSummaryStep(
44 | id,
45 | "symbol-rocket plugin-ionicons-api",
46 | "Test Text",
47 | "icon-md",
48 | "color: green",
49 | "https://jenkins.io",
50 | "_blank");
51 | }
52 |
53 | @Override
54 | protected AbstractRemoveBadgesStep createRemoveStep(String id) {
55 | return new RemoveSummariesStep(id);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/ShortTextStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 | import static org.junit.jupiter.api.Assertions.assertNull;
28 | import static org.junit.jupiter.api.Assertions.assertTrue;
29 |
30 | import com.jenkinsci.plugins.badge.action.BadgeAction;
31 | import hudson.model.BuildBadgeAction;
32 | import java.util.List;
33 | import java.util.Random;
34 | import java.util.UUID;
35 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
36 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
37 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
38 | import org.junit.jupiter.api.BeforeAll;
39 | import org.junit.jupiter.api.Test;
40 | import org.jvnet.hudson.test.JenkinsRule;
41 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
42 |
43 | @WithJenkins
44 | @Deprecated(since = "2.0", forRemoval = true)
45 | class ShortTextStepTest {
46 |
47 | private static JenkinsRule r;
48 |
49 | @BeforeAll
50 | static void setUp(JenkinsRule rule) {
51 | r = rule;
52 | }
53 |
54 | @Test
55 | void text() {
56 | AddShortTextStep step = new AddShortTextStep(null);
57 | assertNull(step.getText());
58 |
59 | String text = UUID.randomUUID().toString();
60 | step = new AddShortTextStep(text);
61 | assertEquals(text, step.getText());
62 | }
63 |
64 | @Test
65 | void color() {
66 | AddShortTextStep step = new AddShortTextStep(null);
67 | assertNull(step.getColor());
68 |
69 | step.setColor("red");
70 | assertEquals("red", step.getColor());
71 | }
72 |
73 | @Test
74 | void background() {
75 | AddShortTextStep step = new AddShortTextStep(null);
76 | assertNull(step.getBackground());
77 |
78 | step.setBackground("red");
79 | assertEquals("red", step.getBackground());
80 | }
81 |
82 | @Test
83 | void border() {
84 | AddShortTextStep step = new AddShortTextStep(null);
85 | assertNull(step.getBorder());
86 |
87 | step.setBorder(1);
88 | assertEquals(1, step.getBorder());
89 | }
90 |
91 | @Test
92 | void borderColor() {
93 | AddShortTextStep step = new AddShortTextStep(null);
94 | assertNull(step.getBorderColor());
95 |
96 | step.setBorderColor("red");
97 | assertEquals("red", step.getBorderColor());
98 | }
99 |
100 | @Test
101 | void link() {
102 | AddShortTextStep step = new AddShortTextStep(null);
103 | assertNull(step.getLink());
104 |
105 | step.setLink("https://jenkins.io");
106 | assertEquals("https://jenkins.io", step.getLink());
107 | }
108 |
109 | @Test
110 | void deprecated() {
111 | AddShortTextStep step = new AddShortTextStep(null);
112 | assertTrue(step.getDescriptor().isAdvanced());
113 | }
114 |
115 | @Test
116 | void addShortText() throws Exception {
117 | String text = UUID.randomUUID().toString();
118 | String color = UUID.randomUUID().toString();
119 | String background = UUID.randomUUID().toString();
120 | int border = new Random().nextInt();
121 | String borderColor = UUID.randomUUID().toString();
122 | String link = "http://" + UUID.randomUUID();
123 |
124 | WorkflowJob p = r.createProject(WorkflowJob.class);
125 | p.setDefinition(new CpsFlowDefinition(
126 | "addShortText(text:\"" + text + "\", color:\"" + color + "\", background:\"" + background
127 | + "\", border:" + border + ", borderColor:\"" + borderColor + "\", link:\"" + link + "\")",
128 | true));
129 | WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
130 |
131 | List badgeActions = b.getBadgeActions();
132 | assertEquals(1, badgeActions.size());
133 |
134 | BadgeAction action = (BadgeAction) badgeActions.get(0);
135 | assertEquals(text, action.getText());
136 | assertNull(action.getIcon());
137 | assertEquals(link, action.getLink());
138 | }
139 |
140 | @Test
141 | void jenkinsColorStyle() throws Exception {
142 | String text = UUID.randomUUID().toString();
143 | String color = "jenkins-!-color-red";
144 | int border = 1;
145 |
146 | WorkflowJob p = r.createProject(WorkflowJob.class);
147 | p.setDefinition(new CpsFlowDefinition(
148 | "addShortText(text:\"" + text + "\", color:\"" + color + "\", border:\"" + border + "\")", true));
149 | WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
150 |
151 | List badgeActions = b.getBadgeActions();
152 | assertEquals(1, badgeActions.size());
153 |
154 | BadgeAction action = (BadgeAction) badgeActions.get(0);
155 | assertEquals(text, action.getText());
156 | assertEquals("border: 1px solid ;color: var(---red);", action.getStyle());
157 | }
158 |
159 | @Test
160 | void jenkinsWarningStyle() throws Exception {
161 | String text = UUID.randomUUID().toString();
162 | String color = "jenkins-!-warning-color";
163 | int border = 1;
164 |
165 | WorkflowJob p = r.createProject(WorkflowJob.class);
166 | p.setDefinition(new CpsFlowDefinition(
167 | "addShortText(text:\"" + text + "\", color:\"" + color + "\", border:\"" + border + "\")", true));
168 | WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
169 |
170 | List badgeActions = b.getBadgeActions();
171 | assertEquals(1, badgeActions.size());
172 |
173 | BadgeAction action = (BadgeAction) badgeActions.get(0);
174 | assertEquals(text, action.getText());
175 | assertEquals("border: 1px solid ;color: var(--warning-color);", action.getStyle());
176 | }
177 |
178 | @Test
179 | void addShortText_minimal() throws Exception {
180 | String text = UUID.randomUUID().toString();
181 |
182 | WorkflowJob p = r.createProject(WorkflowJob.class);
183 | p.setDefinition(new CpsFlowDefinition("addShortText(text:\"" + text + "\")", true));
184 | WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
185 |
186 | List badgeActions = b.getBadgeActions();
187 | assertEquals(1, badgeActions.size());
188 |
189 | BadgeAction action = (BadgeAction) badgeActions.get(0);
190 | assertEquals(text, action.getText());
191 | assertNull(action.getIcon());
192 | assertNull(action.getLink());
193 | }
194 | }
195 |
--------------------------------------------------------------------------------
/src/test/java/com/jenkinsci/plugins/badge/dsl/StepClassHierarchyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2025, Badge Plugin Authors
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.jenkinsci.plugins.badge.dsl;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertTrue;
27 |
28 | import org.jenkinsci.plugins.workflow.steps.Step;
29 | import org.junit.jupiter.api.Nested;
30 | import org.junit.jupiter.api.Test;
31 |
32 | class StepClassHierarchyTest {
33 |
34 | @Nested
35 | class Badge {
36 |
37 | @Test
38 | void abstractAddBadgeStep() {
39 | assertTrue(Step.class.isAssignableFrom(AbstractAddBadgeStep.class));
40 | }
41 |
42 | @Test
43 | void abstractRemoveBadgesStep() {
44 | assertTrue(Step.class.isAssignableFrom(AbstractRemoveBadgesStep.class));
45 | }
46 |
47 | @Test
48 | void addBadgeStep() {
49 | assertTrue(Step.class.isAssignableFrom(AddBadgeStep.class));
50 | assertTrue(AbstractAddBadgeStep.class.isAssignableFrom(AddBadgeStep.class));
51 | }
52 |
53 | @Test
54 | void addErrorBadgeStep() {
55 | assertTrue(Step.class.isAssignableFrom(AddErrorBadgeStep.class));
56 | assertTrue(AbstractAddBadgeStep.class.isAssignableFrom(AddErrorBadgeStep.class));
57 | assertTrue(AddBadgeStep.class.isAssignableFrom(AddErrorBadgeStep.class));
58 | }
59 |
60 | @Test
61 | void addInfoBadgeStep() {
62 | assertTrue(Step.class.isAssignableFrom(AddInfoBadgeStep.class));
63 | assertTrue(AbstractAddBadgeStep.class.isAssignableFrom(AddInfoBadgeStep.class));
64 | assertTrue(AddBadgeStep.class.isAssignableFrom(AddInfoBadgeStep.class));
65 | }
66 |
67 | @Test
68 | void addWarningBadgeStep() {
69 | assertTrue(Step.class.isAssignableFrom(AddWarningBadgeStep.class));
70 | assertTrue(AbstractAddBadgeStep.class.isAssignableFrom(AddWarningBadgeStep.class));
71 | assertTrue(AddBadgeStep.class.isAssignableFrom(AddWarningBadgeStep.class));
72 | }
73 |
74 | @Test
75 | void removeBadgesStep() {
76 | assertTrue(Step.class.isAssignableFrom(RemoveBadgesStep.class));
77 | assertTrue(AbstractRemoveBadgesStep.class.isAssignableFrom(RemoveBadgesStep.class));
78 | }
79 | }
80 |
81 | @Nested
82 | class Summary {
83 |
84 | @Test
85 | void addSummaryStep() {
86 | assertTrue(Step.class.isAssignableFrom(AddSummaryStep.class));
87 | assertTrue(AbstractAddBadgeStep.class.isAssignableFrom(AddSummaryStep.class));
88 | assertTrue(AddBadgeStep.class.isAssignableFrom(AddSummaryStep.class));
89 | }
90 |
91 | @Test
92 | void removeSummariesStep() {
93 | assertTrue(Step.class.isAssignableFrom(RemoveSummariesStep.class));
94 | assertTrue(AbstractRemoveBadgesStep.class.isAssignableFrom(RemoveSummariesStep.class));
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/test/resources/legacy-configuration/badge-action-borderColor-null.xml:
--------------------------------------------------------------------------------
1 |
2 | color
3 | background
4 | border
5 |
--------------------------------------------------------------------------------
/src/test/resources/legacy-configuration/badge-action-jenkins-color.xml:
--------------------------------------------------------------------------------
1 |
2 | jenkins-!-color-value
3 |
--------------------------------------------------------------------------------
/src/test/resources/legacy-configuration/badge-action-jenkins.xml:
--------------------------------------------------------------------------------
1 |
2 | jenkins-!-value-color
3 |
--------------------------------------------------------------------------------
/src/test/resources/legacy-configuration/badge-action-null.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/test/resources/legacy-configuration/badge-action.xml:
--------------------------------------------------------------------------------
1 |
2 | iconPath
3 | color
4 | background
5 | border
6 | borderColor
7 |
--------------------------------------------------------------------------------
/src/test/resources/legacy-configuration/summary-action-null.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/test/resources/legacy-configuration/summary-action.xml:
--------------------------------------------------------------------------------
1 |
2 | summaryText
3 |
--------------------------------------------------------------------------------