use of org.openhab.core.automation.type.ModuleTypeRegistry in project openhab-core by openhab.
the class AutomationIntegrationJsonTest method before.
@BeforeEach
public void before() {
logger.info("@Before.begin");
getService(ItemRegistry.class);
ItemProvider itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
}
@Override
public Collection<Item> getAll() {
return Set.of(new SwitchItem("myMotionItem"), new SwitchItem("myPresenceItem"), new SwitchItem("myLampItem"), new SwitchItem("myMotionItem2"), new SwitchItem("myPresenceItem2"), new SwitchItem("myLampItem2"), new SwitchItem("myMotionItem11"), new SwitchItem("myLampItem11"), new SwitchItem("myMotionItem3"), new SwitchItem("templ_MotionItem"), new SwitchItem("templ_LampItem"));
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
}
};
registerService(itemProvider);
registerVolatileStorageService();
EventSubscriber ruleEventHandler = new EventSubscriber() {
@Override
public Set<String> getSubscribedEventTypes() {
return Set.of(RuleStatusInfoEvent.TYPE);
}
@Override
@Nullable
public EventFilter getEventFilter() {
return null;
}
@Override
public void receive(Event e) {
logger.info("RuleEvent: {} --> {}", e.getTopic(), e.getPayload());
if (e.getPayload().contains("RUNNING")) {
ruleEvent = e;
}
}
};
registerService(ruleEventHandler);
StorageService storageService = getService(StorageService.class);
managedRuleProvider = getService(ManagedRuleProvider.class);
eventPublisher = getService(EventPublisher.class);
itemRegistry = getService(ItemRegistry.class);
ruleRegistry = getService(RuleRegistry.class);
ruleManager = getService(RuleManager.class);
moduleTypeRegistry = getService(ModuleTypeRegistry.class);
waitForAssert(() -> {
assertThat(storageService, is(notNullValue()));
// sometimes assert fails because EventPublisher service is null
assertThat(eventPublisher, is(notNullValue()));
assertThat(itemRegistry, is(notNullValue()));
assertThat(ruleRegistry, is(notNullValue()));
assertThat(ruleManager, is(notNullValue()));
assertThat(managedRuleProvider, is(notNullValue()));
assertThat(moduleTypeRegistry, is(notNullValue()));
}, 9000, 1000);
// start rule engine
RuleEngineImpl ruleEngine = (RuleEngineImpl) ruleManager;
ruleEngine.onReadyMarkerAdded(new ReadyMarker("", ""));
waitForAssert(() -> assertTrue(ruleEngine.isStarted()));
logger.info("@Before.finish");
}
use of org.openhab.core.automation.type.ModuleTypeRegistry in project openhab-core by openhab.
the class RuntimeRuleTest method checkIfTimerTriggerModuleTypeIsRegistered.
@Test
public void checkIfTimerTriggerModuleTypeIsRegistered() {
ModuleTypeRegistry mtr = getService(ModuleTypeRegistry.class);
waitForAssert(() -> {
assertThat(mtr.get(GenericCronTriggerHandler.MODULE_TYPE_ID), is(notNullValue()));
}, 3000, 100);
}
use of org.openhab.core.automation.type.ModuleTypeRegistry in project openhab-core by openhab.
the class AutomationIntegrationTest method testModuleTypeProviderAndTemplateProvider.
@Test
public void testModuleTypeProviderAndTemplateProvider() {
logger.info("test ModuleTypeProvider and TemplateProvider");
TemplateRegistry<RuleTemplate> templateRegistry = getService(TemplateRegistry.class);
ModuleTypeRegistry moduleTypeRegistry = getService(ModuleTypeRegistry.class);
String templateUID = "testTemplate1";
Set<String> tags = Stream.of("test", "testTag").collect(toSet());
List<Trigger> templateTriggers = Collections.emptyList();
List<Condition> templateConditions = Collections.emptyList();
List<Action> templateActions = Collections.emptyList();
List<ConfigDescriptionParameter> templateConfigDescriptionParameters = List.of(ConfigDescriptionParameterBuilder.create("param", ConfigDescriptionParameter.Type.TEXT).build());
RuleTemplate template = new RuleTemplate(templateUID, "Test template Label", "Test template description", tags, templateTriggers, templateConditions, templateActions, templateConfigDescriptionParameters, Visibility.VISIBLE);
String triggerTypeUID = "testTrigger1";
TriggerType triggerType = new TriggerType(triggerTypeUID, templateConfigDescriptionParameters, null);
String actionTypeUID = "testAction1";
ActionType actionType = new ActionType(actionTypeUID, templateConfigDescriptionParameters, null);
RuleTemplateProvider templateProvider = new RuleTemplateProvider() {
@Override
@Nullable
public RuleTemplate getTemplate(String UID, @Nullable Locale locale) {
if (UID.equals(templateUID)) {
return template;
} else {
return null;
}
}
@Override
public Collection<RuleTemplate> getTemplates(@Nullable Locale locale) {
return Set.of(template);
}
@Override
public void addProviderChangeListener(ProviderChangeListener<RuleTemplate> listener) {
}
@Override
public Collection<RuleTemplate> getAll() {
return Set.of(template);
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<RuleTemplate> listener) {
}
};
ModuleTypeProvider moduleTypeProvider = new ModuleTypeProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<ModuleType> listener) {
}
@Override
public Collection<ModuleType> getAll() {
return Stream.of(triggerType, actionType).collect(toSet());
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<ModuleType> listener) {
}
@Override
@Nullable
public <T extends ModuleType> T getModuleType(String UID, @Nullable Locale locale) {
if (UID.equals(triggerTypeUID)) {
return (T) triggerType;
} else if (UID.equals(actionTypeUID)) {
return (T) actionType;
} else {
return null;
}
}
@Override
public <T extends ModuleType> Collection<T> getModuleTypes(@Nullable Locale locale) {
return (Collection<T>) Stream.of(triggerType, actionType).collect(toSet());
}
};
registerService(templateProvider);
assertThat(templateRegistry.get(templateUID), is(notNullValue()));
unregisterService(templateProvider);
assertThat(templateRegistry.get(templateUID), is(nullValue()));
registerService(moduleTypeProvider);
assertThat(moduleTypeRegistry.get(actionTypeUID), is(notNullValue()));
assertThat(moduleTypeRegistry.get(triggerTypeUID), is(notNullValue()));
unregisterService(moduleTypeProvider);
assertThat(moduleTypeRegistry.get(actionTypeUID), is(nullValue()));
assertThat(moduleTypeRegistry.get(triggerTypeUID), is(nullValue()));
}
use of org.openhab.core.automation.type.ModuleTypeRegistry in project openhab-core by openhab.
the class RuntimeRuleTest method modeTypesRegistration.
@Test
public void modeTypesRegistration() {
final ModuleTypeRegistry mtr = getService(ModuleTypeRegistry.class);
waitForAssert(() -> {
assertNotNull(mtr.get("core.GenericEventTrigger"));
assertNotNull(mtr.get("core.GenericEventCondition"));
assertNotNull(mtr.get("core.ItemStateChangeTrigger"));
assertNotNull(mtr.get("core.ItemStateUpdateTrigger"));
assertNotNull(mtr.get(CompareConditionHandler.MODULE_TYPE));
});
}
use of org.openhab.core.automation.type.ModuleTypeRegistry in project openhab-core by openhab.
the class AutomationIntegrationTest method before.
@BeforeEach
public void before() {
logger.info("@Before.begin");
getService(ItemRegistry.class);
ItemProvider itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
}
@Override
public Collection<Item> getAll() {
Set<Item> items = new HashSet<>();
items.add(new SwitchItem("myMotionItem"));
items.add(new SwitchItem("myPresenceItem"));
items.add(new SwitchItem("myLampItem"));
items.add(new SwitchItem("myMotionItem2"));
items.add(new SwitchItem("myPresenceItem2"));
items.add(new SwitchItem("myLampItem2"));
items.add(new SwitchItem("myMotionItem3"));
items.add(new SwitchItem("templ_MotionItem"));
items.add(new SwitchItem("templ_LampItem"));
items.add(new SwitchItem("myMotionItem3"));
items.add(new SwitchItem("myPresenceItem3"));
items.add(new SwitchItem("myLampItem3"));
items.add(new SwitchItem("myMotionItem4"));
items.add(new SwitchItem("myPresenceItem4"));
items.add(new SwitchItem("myLampItem4"));
items.add(new SwitchItem("myMotionItem5"));
items.add(new SwitchItem("myPresenceItem5"));
items.add(new SwitchItem("myLampItem5"));
items.add(new SwitchItem("xtempl_MotionItem"));
items.add(new SwitchItem("xtempl_LampItem"));
return items;
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
}
};
registerService(itemProvider);
registerVolatileStorageService();
StorageService storageService = getService(StorageService.class);
eventPublisher = getService(EventPublisher.class);
itemRegistry = getService(ItemRegistry.class);
ruleRegistry = getService(RuleRegistry.class);
ruleEngine = getService(RuleManager.class);
managedRuleProvider = getService(ManagedRuleProvider.class);
moduleTypeRegistry = getService(ModuleTypeRegistry.class);
templateRegistry = getService(TemplateRegistry.class);
waitForAssert(() -> {
assertThat(eventPublisher, is(notNullValue()));
assertThat(storageService, is(notNullValue()));
assertThat(itemRegistry, is(notNullValue()));
assertThat(ruleRegistry, is(notNullValue()));
assertThat(ruleEngine, is(notNullValue()));
assertThat(moduleTypeRegistry, is(notNullValue()));
assertThat(templateRegistry, is(notNullValue()));
assertThat(managedRuleProvider, is(notNullValue()));
}, 9000, 1000);
// start rule engine
((RuleEngineImpl) ruleEngine).onReadyMarkerAdded(new ReadyMarker("", ""));
waitForAssert(() -> {
assertThat(((RuleEngineImpl) ruleEngine).isStarted(), is(true));
}, 5000, 1000);
logger.info("@Before.finish");
}
Aggregations