use of org.eclipse.smarthome.automation.events.RuleStatusInfoEvent in project smarthome by eclipse.
the class RuntimeRuleTest method ruleTriggeredByCompositeTrigger.
@Test
public void ruleTriggeredByCompositeTrigger() throws ItemNotFoundException, InterruptedException {
// //Test the creation of a rule out of
final Configuration triggerConfig = new Configuration(Stream.of(new SimpleEntry<>("itemName", "myMotionItem3")).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())));
final Configuration actionConfig = new Configuration(Stream.of(new SimpleEntry<>("itemName", "myLampItem3"), new SimpleEntry<>("command", "ON")).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())));
final Rule rule = new Rule("myRule21" + new Random().nextInt() + "_COMPOSITE");
rule.setTriggers(Arrays.asList(new Trigger[] { new Trigger("ItemStateChangeTrigger3", "core.ItemStateChangeTrigger", triggerConfig) }));
rule.setActions(Arrays.asList(new Action[] { new Action("ItemPostCommandAction3", "core.ItemCommandAction", actionConfig, null) }));
rule.setName("RuleByJAVA_API_WithCompositeTrigger");
logger.info("Rule created: {}", rule.getUID());
final RuleRegistry ruleRegistry = getService(RuleRegistry.class);
ruleRegistry.add(rule);
// Test rule
waitForAssert(() -> {
Assert.assertEquals(RuleStatus.IDLE, ruleRegistry.getStatusInfo(rule.getUID()).getStatus());
});
final Queue<Event> events = new LinkedList<>();
registerService(new EventSubscriber() {
@Override
public void receive(final Event event) {
logger.info("RuleEvent: {}", event.getTopic());
events.add(event);
}
@Override
public Set<String> getSubscribedEventTypes() {
return Collections.singleton(RuleStatusInfoEvent.TYPE);
}
@Override
public EventFilter getEventFilter() {
return null;
}
});
final EventPublisher eventPublisher = getService(EventPublisher.class);
eventPublisher.post(ItemEventFactory.createStateEvent("myPresenceItem3", OnOffType.ON));
eventPublisher.post(ItemEventFactory.createStateEvent("myMotionItem3", OnOffType.ON));
waitForAssert(() -> {
assertFalse(events.isEmpty());
RuleStatusInfoEvent event = (RuleStatusInfoEvent) events.remove();
assertEquals(RuleStatus.RUNNING, event.getStatusInfo().getStatus());
});
waitForAssert(() -> {
assertFalse(events.isEmpty());
RuleStatusInfoEvent event = (RuleStatusInfoEvent) events.remove();
assertEquals(RuleStatus.IDLE, event.getStatusInfo().getStatus());
});
}
Aggregations