Search in sources :

Example 6 with ManagedItemChannelLinkProvider

use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-addons by openhab.

the class WWNThingHandlerOSGiTest method setUp.

@BeforeEach
public void setUp() throws ItemNotFoundException {
    registerService(volatileStorageService);
    managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
    assertThat("Could not get ManagedThingProvider", managedThingProvider, is(notNullValue()));
    thingTypeRegistry = getService(ThingTypeRegistry.class);
    assertThat("Could not get ThingTypeRegistry", thingTypeRegistry, is(notNullValue()));
    channelTypeRegistry = getService(ChannelTypeRegistry.class);
    assertThat("Could not get ChannelTypeRegistry", channelTypeRegistry, is(notNullValue()));
    channelGroupTypeRegistry = getService(ChannelGroupTypeRegistry.class);
    assertThat("Could not get ChannelGroupTypeRegistry", channelGroupTypeRegistry, is(notNullValue()));
    eventPublisher = getService(EventPublisher.class);
    assertThat("Could not get EventPublisher", eventPublisher, is(notNullValue()));
    itemFactory = getService(ItemFactory.class);
    assertThat("Could not get ItemFactory", itemFactory, is(notNullValue()));
    itemRegistry = getService(ItemRegistry.class);
    assertThat("Could not get ItemRegistry", itemRegistry, is(notNullValue()));
    managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertThat("Could not get ManagedItemChannelLinkProvider", managedItemChannelLinkProvider, is(notNullValue()));
    clientBuilder = getService(ClientBuilder.class);
    assertThat("Could not get ClientBuilder", clientBuilder, is(notNullValue()));
    eventSourceFactory = getService(SseEventSourceFactory.class);
    assertThat("Could not get SseEventSourceFactory", eventSourceFactory, is(notNullValue()));
    ComponentContext componentContext = mock(ComponentContext.class);
    when(componentContext.getBundleContext()).thenReturn(bundleContext);
    nestTestHandlerFactory = new WWNTestHandlerFactory(clientBuilder, eventSourceFactory);
    nestTestHandlerFactory.activate(componentContext, Map.of(WWNTestHandlerFactory.REDIRECT_URL_CONFIG_PROPERTY, REDIRECT_URL));
    registerService(nestTestHandlerFactory);
    nestTestHandlerFactory = getService(ThingHandlerFactory.class, WWNTestHandlerFactory.class);
    assertThat("Could not get NestTestHandlerFactory", nestTestHandlerFactory, is(notNullValue()));
    bridge = buildBridge();
    thing = buildThing(bridge);
    bridgeHandler = addThing(bridge, WWNTestAccountHandler.class);
    thingHandler = addThing(thing, thingClass);
    createAndLinkItems();
    assertThatAllItemStatesAreNull();
}
Also used : ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) EventPublisher(org.openhab.core.events.EventPublisher) ComponentContext(org.osgi.service.component.ComponentContext) WWNTestAccountHandler(org.openhab.binding.nest.internal.wwn.test.WWNTestAccountHandler) ItemRegistry(org.openhab.core.items.ItemRegistry) ThingHandlerFactory(org.openhab.core.thing.binding.ThingHandlerFactory) WWNTestHandlerFactory(org.openhab.binding.nest.internal.wwn.test.WWNTestHandlerFactory) ThingProvider(org.openhab.core.thing.ThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ChannelGroupTypeRegistry(org.openhab.core.thing.type.ChannelGroupTypeRegistry) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) ItemFactory(org.openhab.core.items.ItemFactory) SseEventSourceFactory(org.osgi.service.jaxrs.client.SseEventSourceFactory) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ClientBuilder(javax.ws.rs.client.ClientBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with ManagedItemChannelLinkProvider

use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider 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)

Example 8 with ManagedItemChannelLinkProvider

use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-addons by openhab.

the class NtpOSGiTest method initialize.

private void initialize(Configuration configuration, String channelID, String acceptedItemType, Configuration channelConfiguration) {
    configuration.put(NtpBindingConstants.PROPERTY_NTP_SERVER_PORT, TEST_PORT);
    ThingUID ntpUid = new ThingUID(NtpBindingConstants.THING_TYPE_NTP, TEST_THING_ID);
    ChannelUID channelUID = new ChannelUID(ntpUid, channelID);
    Channel channel = ChannelBuilder.create(channelUID, acceptedItemType).withType(channelTypeUID).withConfiguration(channelConfiguration).withLabel("label").withKind(ChannelKind.STATE).build();
    ntpThing = ThingBuilder.create(NtpBindingConstants.THING_TYPE_NTP, ntpUid).withConfiguration(configuration).withChannel(channel).build();
    managedThingProvider.add(ntpThing);
    // Wait for the NTP thing to be added to the ManagedThingProvider.
    ntpHandler = waitForAssert(() -> {
        final ThingHandler thingHandler = ntpThing.getHandler();
        assertThat(thingHandler, is(instanceOf(NtpHandler.class)));
        return (NtpHandler) thingHandler;
    }, DFL_TIMEOUT * 3, DFL_SLEEP_TIME);
    if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_STRING)) {
        testItem = new StringItem(TEST_ITEM_NAME);
    } else if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_DATE_TIME)) {
        testItem = new DateTimeItem(TEST_ITEM_NAME);
    }
    itemRegistry.add(testItem);
    // Wait for the item , linked to the NTP thing to be added to the
    // ManagedThingProvider.
    final ManagedItemChannelLinkProvider itemChannelLinkProvider = waitForAssert(() -> {
        final ManagedItemChannelLinkProvider tmp = getService(ManagedItemChannelLinkProvider.class);
        assertNotNull(tmp);
        return tmp;
    });
    itemChannelLinkProvider.add(new ItemChannelLink(TEST_ITEM_NAME, channelUID));
}
Also used : ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ChannelUID(org.openhab.core.thing.ChannelUID) ThingUID(org.openhab.core.thing.ThingUID) Channel(org.openhab.core.thing.Channel) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ThingHandler(org.openhab.core.thing.binding.ThingHandler) NtpHandler(org.openhab.binding.ntp.internal.handler.NtpHandler) DateTimeItem(org.openhab.core.library.items.DateTimeItem) StringItem(org.openhab.core.library.items.StringItem)

Example 9 with ManagedItemChannelLinkProvider

use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-core by openhab.

the class ThingManagerOSGiJavaTest method testThatIsLinkedReturnsTrue.

@Test
public void testThatIsLinkedReturnsTrue() throws Exception {
    AtomicReference<ThingHandlerCallback> thc = initializeThingHandlerCallback();
    ManagedItemChannelLinkProvider managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertNotNull(managedItemChannelLinkProvider);
    managedItemChannelLinkProvider.add(new ItemChannelLink("item", CHANNEL_UID));
    assertTrue(thc.get().isChannelLinked(CHANNEL_UID));
}
Also used : ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ThingHandlerCallback(org.openhab.core.thing.binding.ThingHandlerCallback) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Aggregations

ManagedItemChannelLinkProvider (org.openhab.core.thing.link.ManagedItemChannelLinkProvider)9 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ItemChannelLink (org.openhab.core.thing.link.ItemChannelLink)5 ItemRegistry (org.openhab.core.items.ItemRegistry)4 StringItem (org.openhab.core.library.items.StringItem)4 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)4 EventPublisher (org.openhab.core.events.EventPublisher)2 ManagedItemProvider (org.openhab.core.items.ManagedItemProvider)2 ChannelUID (org.openhab.core.thing.ChannelUID)2 ThingProvider (org.openhab.core.thing.ThingProvider)2 ItemChannelLinkRegistry (org.openhab.core.thing.link.ItemChannelLinkRegistry)2 ChannelTypeProvider (org.openhab.core.thing.type.ChannelTypeProvider)2 ThingTypeRegistry (org.openhab.core.thing.type.ThingTypeRegistry)2 ComponentContext (org.osgi.service.component.ComponentContext)2 Locale (java.util.Locale)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 Test (org.junit.jupiter.api.Test)1 WWNTestAccountHandler (org.openhab.binding.nest.internal.wwn.test.WWNTestAccountHandler)1 WWNTestHandlerFactory (org.openhab.binding.nest.internal.wwn.test.WWNTestHandlerFactory)1 NtpHandler (org.openhab.binding.ntp.internal.handler.NtpHandler)1