Skip to content

Commit e069f65

Browse files
authored
Merge pull request #26 from rundeck-plugins/fix/null-value
RUN-3422: fix: do not set null attribute value
2 parents 2b0bcd2 + 5fb95a5 commit e069f65

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

src/main/java/org/rundeck/plugins/nodes/icon/IconNodeEnhancer.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import java.io.IOException;
1010
import java.io.InputStream;
11-
import java.util.*;
11+
import java.util.List;
12+
import java.util.Properties;
1213

1314
@Plugin(service = "NodeEnhancer", name = IconNodeEnhancer.PROVIDER)
1415
@PluginDescription(title = "Icon",
@@ -110,8 +111,12 @@ public void updateNode(
110111
&& !attributeValue.equals(node.getAttributes().get(attributeName))) {
111112
return;
112113
}
113-
node.addAttribute("ui:icon:name", iconName);
114-
if (iconColor != null && !"".equals(iconColor)) {
114+
if (null != iconName && !iconName.isBlank()) {
115+
if (iconName.startsWith("glyphicon-") || iconName.startsWith("fa-") || iconName.startsWith("fab-")) {
116+
node.addAttribute("ui:icon:name", iconName);
117+
}
118+
}
119+
if (iconColor != null && !iconColor.isBlank()) {
115120
node.addAttribute("ui:icon:color", iconColor);
116121
}
117122
if (iconBadges != null && iconBadges.size() > 0) {
@@ -124,7 +129,9 @@ public void updateNode(
124129
sb.append(iconBadge);
125130
}
126131
}
127-
node.addAttribute("ui:badges", sb.toString());
132+
if (sb.length() > 0) {
133+
node.addAttribute("ui:badges", sb.toString());
134+
}
128135
}
129136
}
130137

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.rundeck.plugins.nodes.icon
2+
3+
import com.dtolabs.rundeck.plugins.nodes.IModifiableNodeEntry
4+
import spock.lang.Specification
5+
6+
class IconNodeEnhancerSpec extends Specification {
7+
8+
def "test icon enhancement"() {
9+
given:
10+
def node = Mock(IModifiableNodeEntry) {
11+
getAttributes() >> ['key': 'value']
12+
}
13+
def iconEnhancer = new IconNodeEnhancer()
14+
iconEnhancer.attributeName = attributeName
15+
iconEnhancer.attributeValue = attributeValue
16+
iconEnhancer.iconName = iconName
17+
iconEnhancer.iconColor = iconColor
18+
iconEnhancer.iconBadges = iconBadges
19+
when:
20+
iconEnhancer.updateNode('project', node)
21+
22+
then:
23+
(expectName ? 1 : 0) * node.addAttribute('ui:icon:name', expectName)
24+
(expectColor ? 1 : 0) * node.addAttribute('ui:icon:color', expectColor)
25+
(expectBadges ? 1 : 0) * node.addAttribute('ui:badges', expectBadges)
26+
0 * node.addAttribute(_, null)
27+
28+
where:
29+
attributeName | attributeValue | iconName | iconColor | iconBadges | expectName | expectColor | expectBadges
30+
'key' | 'value' | null | null | [] | null | null | null
31+
'wrongkey' | 'value' | 'fa-iconName' | 'iconColor' | ['fa-badge1', 'fab-badge2'] | null | null | null
32+
'key' | 'value' | null | null | ['fa-badge1', 'fab-badge2'] | null | null | 'fa-badge1,fab-badge2'
33+
'key' | 'value' | null | 'iconColor' | [] | null | 'iconColor' | null
34+
'key' | 'value' | 'fa-test' | null | [] | 'fa-test' | null | null
35+
'key' | 'value' | 'fab-test' | null | [] | 'fab-test' | null | null
36+
'key' | 'value' | 'glyphicon-test' | null | [] | 'glyphicon-test' | null | null
37+
'key' | 'value' | 'other' | null | [] | null | null | null
38+
'key' | 'value' | 'fa-test' | 'iconColor' | ['fa-badge1', 'fab-badge2'] | 'fa-test' | 'iconColor' | 'fa-badge1,fab-badge2'
39+
'key' | 'value' | 'fa-test' | 'iconColor' | ['wrong', 'fab-badge2'] | 'fa-test' | 'iconColor' | 'fab-badge2'
40+
'key' | 'value' | 'fa-test' | 'iconColor' | ['glyphicon-x'] | 'fa-test' | 'iconColor' | 'glyphicon-x'
41+
}
42+
}

0 commit comments

Comments
 (0)