Search in sources :

Example 1 with ModuleTypeRegistry

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");
}
Also used : ItemProvider(org.openhab.core.items.ItemProvider) EventSubscriber(org.openhab.core.events.EventSubscriber) EventPublisher(org.openhab.core.events.EventPublisher) ModuleTypeRegistry(org.openhab.core.automation.type.ModuleTypeRegistry) RuleEngineImpl(org.openhab.core.automation.internal.RuleEngineImpl) RuleRegistry(org.openhab.core.automation.RuleRegistry) ManagedRuleProvider(org.openhab.core.automation.ManagedRuleProvider) ItemRegistry(org.openhab.core.items.ItemRegistry) VolatileStorageService(org.openhab.core.test.storage.VolatileStorageService) StorageService(org.openhab.core.storage.StorageService) SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) ProviderChangeListener(org.openhab.core.common.registry.ProviderChangeListener) RuleManager(org.openhab.core.automation.RuleManager) RuleStatusInfoEvent(org.openhab.core.automation.events.RuleStatusInfoEvent) ItemCommandEvent(org.openhab.core.items.events.ItemCommandEvent) Event(org.openhab.core.events.Event) ReadyMarker(org.openhab.core.service.ReadyMarker) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ModuleTypeRegistry

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);
}
Also used : ModuleTypeRegistry(org.openhab.core.automation.type.ModuleTypeRegistry) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 3 with ModuleTypeRegistry

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()));
}
Also used : Condition(org.openhab.core.automation.Condition) Locale(java.util.Locale) TriggerType(org.openhab.core.automation.type.TriggerType) Action(org.openhab.core.automation.Action) ActionType(org.openhab.core.automation.type.ActionType) ModuleTypeRegistry(org.openhab.core.automation.type.ModuleTypeRegistry) RuleTemplate(org.openhab.core.automation.template.RuleTemplate) ModuleType(org.openhab.core.automation.type.ModuleType) Trigger(org.openhab.core.automation.Trigger) RuleTemplateProvider(org.openhab.core.automation.template.RuleTemplateProvider) ProviderChangeListener(org.openhab.core.common.registry.ProviderChangeListener) ModuleTypeProvider(org.openhab.core.automation.type.ModuleTypeProvider) Collection(java.util.Collection) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Nullable(org.eclipse.jdt.annotation.Nullable) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 4 with ModuleTypeRegistry

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));
    });
}
Also used : ModuleTypeRegistry(org.openhab.core.automation.type.ModuleTypeRegistry) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 5 with ModuleTypeRegistry

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");
}
Also used : ItemProvider(org.openhab.core.items.ItemProvider) EventPublisher(org.openhab.core.events.EventPublisher) ModuleTypeRegistry(org.openhab.core.automation.type.ModuleTypeRegistry) RuleEngineImpl(org.openhab.core.automation.internal.RuleEngineImpl) RuleRegistry(org.openhab.core.automation.RuleRegistry) ManagedRuleProvider(org.openhab.core.automation.ManagedRuleProvider) ItemRegistry(org.openhab.core.items.ItemRegistry) StorageService(org.openhab.core.storage.StorageService) SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) TemplateRegistry(org.openhab.core.automation.template.TemplateRegistry) ProviderChangeListener(org.openhab.core.common.registry.ProviderChangeListener) RuleManager(org.openhab.core.automation.RuleManager) ReadyMarker(org.openhab.core.service.ReadyMarker) SwitchItem(org.openhab.core.library.items.SwitchItem) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ModuleTypeRegistry (org.openhab.core.automation.type.ModuleTypeRegistry)8 Test (org.junit.jupiter.api.Test)6 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)4 ProviderChangeListener (org.openhab.core.common.registry.ProviderChangeListener)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ManagedRuleProvider (org.openhab.core.automation.ManagedRuleProvider)2 RuleManager (org.openhab.core.automation.RuleManager)2 RuleRegistry (org.openhab.core.automation.RuleRegistry)2 RuleEngineImpl (org.openhab.core.automation.internal.RuleEngineImpl)2 EventPublisher (org.openhab.core.events.EventPublisher)2 Item (org.openhab.core.items.Item)2 ItemProvider (org.openhab.core.items.ItemProvider)2 ItemRegistry (org.openhab.core.items.ItemRegistry)2 SwitchItem (org.openhab.core.library.items.SwitchItem)2 ReadyMarker (org.openhab.core.service.ReadyMarker)2 StorageService (org.openhab.core.storage.StorageService)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 Nullable (org.eclipse.jdt.annotation.Nullable)1