Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ VariableDeclaration:

Rule:
'rule' name=(STRING|ID) ('uid' '=' uid=(STRING|ID))? ('[' tags+=(ID|STRING) (',' tags+=(ID|STRING))* ']')?
'when' eventtrigger+=EventTrigger ('or' eventtrigger+=EventTrigger)*
('when' eventtrigger+=EventTrigger ('or' eventtrigger+=EventTrigger)*)?
('but' 'only' 'if' conditions+=Condition ('and' conditions+=Condition)*)?
'then' script=XExpressionInClosure
'end'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public void testSimpleRules() {
" logInfo('Test', 'Test')\n" + //
"end\n\n";

modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
modelRepository.addOrRefreshModel(TESTMODEL_NAME,
new ByteArrayInputStream(model.getBytes(StandardCharsets.UTF_8)));
Collection<Rule> actualRules = dslRuleProvider.getAll();

assertThat(actualRules.size(), is(2));
Expand All @@ -131,7 +132,9 @@ public void testSimpleRules() {
assertThat(firstRule.getTags(), hasItem("Test"));
assertThat(firstRule.getTags(), hasItem("my test"));
assertThat(firstRule.getConditions(), hasSize(0));
assertThat(firstRule.getTriggers(), hasSize(1));
assertThat(firstRule.getTriggers().getFirst().getTypeUID(), is(SystemTriggerHandler.STARTLEVEL_MODULE_TYPE_ID));
assertThat(firstRule.getActions(), hasSize(1));
assertThat(firstRule.getActions().getFirst().getTypeUID(), is(ScriptActionHandler.TYPE_ID));
assertThat(firstRule.getActions().getFirst().getConfiguration()
.get(AbstractScriptModuleHandler.CONFIG_SCRIPT_TYPE), is(DSLScriptEngine.MIMETYPE_OPENHAB_DSL_RULE));
Expand All @@ -141,15 +144,46 @@ public void testSimpleRules() {
assertThat(secondRule.getUID(), is("dslruletest-2"));
assertThat(secondRule.getName(), is("Rule Number Two"));
assertThat(secondRule.getTags(), hasSize(0));
assertThat(secondRule.getTriggers(), hasSize(1));
assertThat(secondRule.getTriggers().getFirst().getTypeUID(), is(ItemStateTriggerHandler.CHANGE_MODULE_TYPE_ID));
assertThat(secondRule.getTriggers().getFirst().getConfiguration().get(ItemStateTriggerHandler.CFG_ITEMNAME),
is("X"));
assertThat(secondRule.getConditions(), hasSize(0));
assertThat(secondRule.getActions(), hasSize(1));
assertThat(secondRule.getActions().getFirst().getTypeUID(), is(ScriptActionHandler.TYPE_ID));
assertThat(secondRule.getActions().getFirst().getConfiguration()
.get(AbstractScriptModuleHandler.CONFIG_SCRIPT_TYPE), is(DSLScriptEngine.MIMETYPE_OPENHAB_DSL_RULE));
}

@Test
public void testNoTrigger() {
Collection<Rule> rules = dslRuleProvider.getAll();
assertThat(rules.size(), is(0));

String model = "rule RuleNoTrigger\n" + //
"then\n" + //
" logInfo('Test', 'Test')\n" + //
"end\n\n";

modelRepository.addOrRefreshModel(TESTMODEL_NAME,
new ByteArrayInputStream(model.getBytes(StandardCharsets.UTF_8)));
Collection<Rule> actualRules = dslRuleProvider.getAll();

assertThat(actualRules.size(), is(1));

Rule rule = actualRules.iterator().next();

assertThat(rule.getUID(), is("dslruletest-1"));
assertThat(rule.getName(), is("RuleNoTrigger"));
assertThat(rule.getTags(), hasSize(0));
assertThat(rule.getConditions(), hasSize(0));
assertThat(rule.getTriggers(), hasSize(0));
assertThat(rule.getActions(), hasSize(1));
assertThat(rule.getActions().getFirst().getTypeUID(), is(ScriptActionHandler.TYPE_ID));
assertThat(rule.getActions().getFirst().getConfiguration().get(AbstractScriptModuleHandler.CONFIG_SCRIPT_TYPE),
is(DSLScriptEngine.MIMETYPE_OPENHAB_DSL_RULE));
}

@Test
public void testAllTriggers() {
Collection<Rule> rules = dslRuleProvider.getAll();
Expand Down Expand Up @@ -378,7 +412,8 @@ public void testVars() {
" logInfo('Test', 'Test')\n" + //
"end\n\n";

modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
modelRepository.addOrRefreshModel(TESTMODEL_NAME,
new ByteArrayInputStream(model.getBytes(StandardCharsets.UTF_8)));
Collection<Rule> actualRules = dslRuleProvider.getAll();

assertThat(actualRules.size(), is(1));
Expand Down
Loading