Search in sources :

Example 1 with ItemProvider

use of org.openhab.core.items.ItemProvider in project openhab-core by openhab.

the class ScriptEngineOSGiTest method setup.

@BeforeEach
public void setup() {
    registerVolatileStorageService();
    EventPublisher eventPublisher = event -> {
    };
    registerService(eventPublisher);
    itemRegistry = getService(ItemRegistry.class);
    assertNotNull(itemRegistry);
    itemProvider = new ItemProvider() {

        @Override
        public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
        }

        @Override
        public Collection<Item> getAll() {
            return List.of(new SwitchItem(ITEM_NAME), createNumberItem(NUMBER_ITEM_TEMPERATURE, Temperature.class), createNumberItem(NUMBER_ITEM_LENGTH, Length.class), new NumberItem(NUMBER_ITEM_DECIMAL));
        }

        @Override
        public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
        }
    };
    registerService(itemProvider);
    ScriptServiceUtil scriptServiceUtil = getService(ScriptServiceUtil.class);
    assertNotNull(scriptServiceUtil);
    scriptEngine = ScriptServiceUtil.getScriptEngine();
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) SIUnits(org.openhab.core.library.unit.SIUnits) BeforeEach(org.junit.jupiter.api.BeforeEach) ScriptServiceUtil(org.openhab.core.model.script.ScriptServiceUtil) SwitchItem(org.openhab.core.library.items.SwitchItem) OnOffType(org.openhab.core.library.types.OnOffType) Temperature(javax.measure.quantity.Temperature) Length(javax.measure.quantity.Length) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DecimalType(org.openhab.core.library.types.DecimalType) EventPublisher(org.openhab.core.events.EventPublisher) NumberItem(org.openhab.core.library.items.NumberItem) Units(org.openhab.core.library.unit.Units) QuantityType(org.openhab.core.library.types.QuantityType) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ItemProvider(org.openhab.core.items.ItemProvider) Collection(java.util.Collection) State(org.openhab.core.types.State) MetricPrefix(org.openhab.core.library.unit.MetricPrefix) Item(org.openhab.core.items.Item) Test(org.junit.jupiter.api.Test) ItemRegistry(org.openhab.core.items.ItemRegistry) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest) Assertions(org.junit.jupiter.api.Assertions) ProviderChangeListener(org.openhab.core.common.registry.ProviderChangeListener) ItemProvider(org.openhab.core.items.ItemProvider) NumberItem(org.openhab.core.library.items.NumberItem) SwitchItem(org.openhab.core.library.items.SwitchItem) NumberItem(org.openhab.core.library.items.NumberItem) Item(org.openhab.core.items.Item) EventPublisher(org.openhab.core.events.EventPublisher) ScriptServiceUtil(org.openhab.core.model.script.ScriptServiceUtil) Collection(java.util.Collection) ItemRegistry(org.openhab.core.items.ItemRegistry) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ItemProvider

use of org.openhab.core.items.ItemProvider 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 3 with ItemProvider

use of org.openhab.core.items.ItemProvider in project openhab-core by openhab.

the class RuntimeRuleTest method before.

@BeforeEach
public void before() {
    registerService(new ItemProvider() {

        @Override
        public void addProviderChangeListener(final ProviderChangeListener<Item> listener) {
        }

        @Override
        public void removeProviderChangeListener(final ProviderChangeListener<Item> listener) {
        }

        @Override
        public Collection<Item> getAll() {
            return List.of(new SwitchItem("myMotionItem"), new SwitchItem("myPresenceItem"), new SwitchItem("myLampItem"), new SwitchItem("myMotionItem2"), new SwitchItem("myPresenceItem2"), new SwitchItem("myLampItem2"), new SwitchItem("myMotionItem3"), new SwitchItem("myPresenceItem3"), new SwitchItem("myLampItem3"), new SwitchItem("myMotionItem4"), new SwitchItem("myPresenceItem4"), new SwitchItem("myLampItem4"));
        }
    });
    registerService(volatileStorageService);
    // start rule engine
    RuleEngineImpl ruleEngine = requireNonNull((RuleEngineImpl) getService(RuleManager.class));
    ruleEngine.onReadyMarkerAdded(new ReadyMarker("", ""));
    waitForAssert(() -> assertTrue(ruleEngine.isStarted()));
}
Also used : ItemProvider(org.openhab.core.items.ItemProvider) SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) RuleEngineImpl(org.openhab.core.automation.internal.RuleEngineImpl) Collection(java.util.Collection) ReadyMarker(org.openhab.core.service.ReadyMarker) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ItemProvider

use of org.openhab.core.items.ItemProvider in project openhab-core by openhab.

the class RuleEventTest method before.

@BeforeEach
public void before() {
    ItemProvider itemProvider = new ItemProvider() {

        @Override
        public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
        }

        @Override
        public Collection<Item> getAll() {
            return List.of(new SwitchItem("myMotionItem"), new SwitchItem("myPresenceItem"), new SwitchItem("myLampItem"), new SwitchItem("myMotionItem2"), new SwitchItem("myPresenceItem2"), new SwitchItem("myLampItem2"));
        }

        @Override
        public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
        }
    };
    registerService(itemProvider);
    registerVolatileStorageService();
    // start rule engine
    RuleEngineImpl ruleEngine = requireNonNull((RuleEngineImpl) getService(RuleManager.class));
    ruleEngine.onReadyMarkerAdded(new ReadyMarker("", ""));
    waitForAssert(() -> assertTrue(ruleEngine.isStarted()));
}
Also used : ItemProvider(org.openhab.core.items.ItemProvider) SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) RuleEngineImpl(org.openhab.core.automation.internal.RuleEngineImpl) ProviderChangeListener(org.openhab.core.common.registry.ProviderChangeListener) ReadyMarker(org.openhab.core.service.ReadyMarker) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ItemProvider

use of org.openhab.core.items.ItemProvider 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

BeforeEach (org.junit.jupiter.api.BeforeEach)10 ItemProvider (org.openhab.core.items.ItemProvider)10 SwitchItem (org.openhab.core.library.items.SwitchItem)9 Item (org.openhab.core.items.Item)8 RuleEngineImpl (org.openhab.core.automation.internal.RuleEngineImpl)7 ReadyMarker (org.openhab.core.service.ReadyMarker)7 ProviderChangeListener (org.openhab.core.common.registry.ProviderChangeListener)6 RuleManager (org.openhab.core.automation.RuleManager)4 RuleRegistry (org.openhab.core.automation.RuleRegistry)4 ItemRegistry (org.openhab.core.items.ItemRegistry)4 Collection (java.util.Collection)3 EventPublisher (org.openhab.core.events.EventPublisher)3 ManagedRuleProvider (org.openhab.core.automation.ManagedRuleProvider)2 ModuleTypeRegistry (org.openhab.core.automation.type.ModuleTypeRegistry)2 Event (org.openhab.core.events.Event)2 EventSubscriber (org.openhab.core.events.EventSubscriber)2 ItemCommandEvent (org.openhab.core.items.events.ItemCommandEvent)2 StorageService (org.openhab.core.storage.StorageService)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1