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();
}
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");
}
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));
}
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));
}
Aggregations