Browse Source
Merge pull request #8425 from YevhenBondarenko/fix/log-node
fexed NPE in log node
pull/8428/head
Andrew Shvayka
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
21 additions and
6 deletions
-
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbLogNode.java
-
rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/action/TbLogNodeTest.java
|
|
|
@ -92,12 +92,14 @@ public class TbLogNode implements TbNode { |
|
|
|
boolean isStandard(TbLogNodeConfiguration conf) { |
|
|
|
Objects.requireNonNull(conf, "node config is null"); |
|
|
|
final TbLogNodeConfiguration defaultConfig = new TbLogNodeConfiguration().defaultConfiguration(); |
|
|
|
switch (conf.getScriptLang()) { |
|
|
|
case JS: return defaultConfig.getJsScript().equals(conf.getJsScript()); |
|
|
|
case TBEL: return defaultConfig.getTbelScript().equals(conf.getTbelScript()); |
|
|
|
default: |
|
|
|
log.warn("No rule to define isStandard script for script language [{}], assuming that is non-standard", conf.getScriptLang()); |
|
|
|
return false; |
|
|
|
|
|
|
|
if (conf.getScriptLang() == null || conf.getScriptLang().equals(ScriptLanguage.JS)) { |
|
|
|
return defaultConfig.getJsScript().equals(conf.getJsScript()); |
|
|
|
} else if (conf.getScriptLang().equals(ScriptLanguage.TBEL)) { |
|
|
|
return defaultConfig.getTbelScript().equals(conf.getTbelScript()); |
|
|
|
} else { |
|
|
|
log.warn("No rule to define isStandard script for script language [{}], assuming that is non-standard", conf.getScriptLang()); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -110,6 +110,19 @@ public class TbLogNodeTest { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void backwardCompatibility_whenScriptLangIsNull() throws TbNodeException { |
|
|
|
TbLogNodeConfiguration config = new TbLogNodeConfiguration().defaultConfiguration(); |
|
|
|
TbLogNode node = spy(new TbLogNode()); |
|
|
|
TbNodeConfiguration tbNodeConfiguration = new TbNodeConfiguration(JacksonUtil.valueToTree(config)); |
|
|
|
TbContext ctx = mock(TbContext.class); |
|
|
|
node.init(ctx, tbNodeConfiguration); |
|
|
|
|
|
|
|
assertThat(node.isStandard(config)).as("Script is standard for language JS").isTrue(); |
|
|
|
verify(node, never()).createScriptEngine(any(), any()); |
|
|
|
verify(ctx, never()).createScriptEngine(any(), anyString()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void givenScriptEngineEnum_whenNewAdded_thenFailed() { |
|
|
|
assertThat(ScriptLanguage.values().length).as("only two ScriptLanguage supported").isEqualTo(2); |
|
|
|
|