Search in sources :

Example 6 with ItemProvider

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

the class RunRuleModuleTest 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("switch1"), new SwitchItem("switch2"), new SwitchItem("switch3"), new SwitchItem("ruleTrigger"));
        }
    });
    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 7 with ItemProvider

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

the class ScriptRuleOSGiTest 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("MyTrigger"), new SwitchItem("ScriptItem"));
        }

        @Override
        public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
        }
    };
    registerService(itemProvider);
    registerService(volatileStorageService);
    EventSubscriber eventSubscriber = new EventSubscriber() {

        @Override
        public void receive(Event event) {
            receivedEvent = (ItemCommandEvent) event;
            logger.info("received event from item {}, command {}", receivedEvent.getItemName(), receivedEvent.getItemCommand());
        }

        @Override
        public Set<String> getSubscribedEventTypes() {
            return Set.of(ItemCommandEvent.TYPE);
        }

        @Override
        @Nullable
        public EventFilter getEventFilter() {
            return null;
        }
    };
    registerService(eventSubscriber);
}
Also used : ItemProvider(org.openhab.core.items.ItemProvider) SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) EventSubscriber(org.openhab.core.events.EventSubscriber) ProviderChangeListener(org.openhab.core.common.registry.ProviderChangeListener) ItemCommandEvent(org.openhab.core.items.events.ItemCommandEvent) Event(org.openhab.core.events.Event) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with ItemProvider

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

the class BasicConditionHandlerTest method beforeBase.

/**
 * This executes before every test and before the
 *
 * @Before-annotated methods in sub-classes.
 */
@BeforeEach
public void beforeBase() {
    ItemProvider itemProvider = new ItemProvider() {

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

        @Override
        public Collection<Item> getAll() {
            List<Item> items = new ArrayList<>();
            items.add(new SwitchItem("TriggeredItem"));
            items.add(new SwitchItem("SwitchedItem"));
            return items;
        }

        @Override
        public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
        }
    };
    registerService(itemProvider);
    registerService(volatileStorageService);
    waitForAssert(() -> {
        ruleRegistry = getService(RuleRegistry.class);
        assertThat(ruleRegistry, is(notNullValue()));
    }, 3000, 100);
    waitForAssert(() -> {
        ruleEngine = getService(RuleManager.class);
        assertThat(ruleEngine, is(notNullValue()));
    }, 3000, 100);
    // 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) RuleRegistry(org.openhab.core.automation.RuleRegistry) ProviderChangeListener(org.openhab.core.common.registry.ProviderChangeListener) ArrayList(java.util.ArrayList) RuleManager(org.openhab.core.automation.RuleManager) ReadyMarker(org.openhab.core.service.ReadyMarker) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with ItemProvider

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

the class RuntimeRuleTest method before.

@BeforeEach
public void before() {
    ItemProvider itemProvider = new TestItemProvider(Set.of(new SwitchItem("myLampItem")));
    registerService(itemProvider);
    registerService(volatileStorageService);
    waitForAssert(() -> {
        ruleRegistry = getService(RuleRegistry.class);
        assertThat("RuleRegistry service not found", ruleRegistry, is(notNullValue()));
    }, 3000, 100);
    waitForAssert(() -> {
        ruleEngine = getService(RuleManager.class);
        assertThat("RuleManager service not found", ruleEngine, is(notNullValue()));
    }, 3000, 100);
    // 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) RuleEngineImpl(org.openhab.core.automation.internal.RuleEngineImpl) RuleRegistry(org.openhab.core.automation.RuleRegistry) RuleManager(org.openhab.core.automation.RuleManager) ReadyMarker(org.openhab.core.service.ReadyMarker) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with ItemProvider

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

the class AbstractModbusOSGiTest method setUpAbstractModbusOSGiTest.

/**
 * Before each test, configure mocked services
 */
@BeforeEach
public void setUpAbstractModbusOSGiTest() {
    logger.debug("setUpAbstractModbusOSGiTest BEGIN");
    registerVolatileStorageService();
    registerService(mockedModbusManager);
    registerService(stateSubscriber);
    swapModbusManagerToMocked();
    thingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
    assertThat("Could not get ManagedThingProvider", thingProvider, is(notNullValue()));
    itemProvider = getService(ItemProvider.class, ManagedItemProvider.class);
    assertThat("Could not get ManagedItemProvider", itemProvider, is(notNullValue()));
    itemChannelLinkProvider = getService(ItemChannelLinkProvider.class, ManagedItemChannelLinkProvider.class);
    assertThat("Could not get ManagedItemChannelLinkProvider", itemChannelLinkProvider, is(notNullValue()));
    itemRegistry = getService(ItemRegistry.class);
    assertThat("Could not get ItemRegistry", itemRegistry, is(notNullValue()));
    coreItemFactory = new CoreItemFactory();
    // Clean slate for all tests
    reset(mockedModbusManager);
    stateSubscriber.stateUpdates.clear();
    logger.debug("setUpAbstractModbusOSGiTest END");
}
Also used : ManagedItemProvider(org.openhab.core.items.ManagedItemProvider) ItemProvider(org.openhab.core.items.ItemProvider) ManagedItemProvider(org.openhab.core.items.ManagedItemProvider) CoreItemFactory(org.openhab.core.library.CoreItemFactory) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ThingProvider(org.openhab.core.thing.ThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ItemRegistry(org.openhab.core.items.ItemRegistry) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ItemChannelLinkProvider(org.openhab.core.thing.link.ItemChannelLinkProvider) 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