use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-addons by openhab.
the class SysteminfoOSGiTest method intializeItem.
private void intializeItem(ChannelUID channelUID, String itemName, String acceptedItemType) {
if (acceptedItemType.equals("Number")) {
testItem = new NumberItem(itemName);
} else if (acceptedItemType.equals("String")) {
testItem = new StringItem(itemName);
}
itemRegistry.add(testItem);
ManagedItemChannelLinkProvider itemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
assertThat(itemChannelLinkProvider, is(notNullValue()));
itemChannelLinkProvider.add(new ItemChannelLink(itemName, channelUID));
}
use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-core by openhab.
the class ItemChannelLinkResourceOSGiTest method beforeEach.
@BeforeEach
public void beforeEach() {
registerVolatileStorageService();
itemChannelLinkResource = getService(RESTResource.class, ItemChannelLinkResource.class);
assertNotNull(itemChannelLinkResource);
itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
assertNotNull(itemChannelLinkRegistry);
managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
assertNotNull(managedItemChannelLinkProvider);
link1 = new ItemChannelLink(ITEM_NAME1, new ChannelUID(CHANNEL_UID1));
link2 = new ItemChannelLink(ITEM_NAME2, new ChannelUID(CHANNEL_UID2));
link3 = new ItemChannelLink(ITEM_NAME3, new ChannelUID(THING_TYPE_UID + ":" + UID + ":3"));
when(itemChannelLinkProviderMock.getAll()).thenReturn(List.of(link1, link2, link3));
registerService(itemChannelLinkProviderMock);
waitForAssert(() -> {
assertThat(itemChannelLinkRegistry.getAll(), hasSize(3));
});
when(uriBuilderMock.build(any())).thenReturn(URI.create(""));
when(uriInfoMock.getAbsolutePathBuilder()).thenReturn(uriBuilderMock);
when(uriInfoMock.getPath()).thenReturn("");
when(httpHeadersMock.getHeaderString(anyString())).thenReturn(null);
}
use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-core by openhab.
the class ChangeThingTypeOSGiTest method setup.
@BeforeEach
public void setup() throws URISyntaxException {
registerVolatileStorageService();
managedThingProvider = getService(ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
assertThat(configDescriptionRegistry, is(notNullValue()));
managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
assertThat(managedItemChannelLinkProvider, is(notNullValue()));
managedItemProvider = getService(ManagedItemProvider.class);
assertThat(managedItemProvider, is(notNullValue()));
ComponentContext componentContext = mock(ComponentContext.class);
when(componentContext.getBundleContext()).thenReturn(bundleContext);
thingHandlerFactory = new SampleThingHandlerFactory();
thingHandlerFactory.activate(componentContext);
registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
Map<String, String> thingTypeGenericProperties = Map.ofEntries(entry(PROPERTY_ON_GENERIC_THING_TYPE, GENERIC_VALUE), entry(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, GENERIC_VALUE));
Map<String, String> thingTypeSpecificProperties = Map.ofEntries(entry(PROPERTY_ON_SPECIFIC_THING_TYPE, SPECIFIC_VALUE), entry(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, SPECIFIC_VALUE));
thingTypeGeneric = registerThingTypeAndConfigDescription(THING_TYPE_GENERIC_UID, thingTypeGenericProperties);
thingTypeSpecific = registerThingTypeAndConfigDescription(THING_TYPE_SPECIFIC_UID, thingTypeSpecificProperties);
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
registerService(thingTypeProvider);
ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
when(thingTypeRegistry.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
registerService(thingTypeRegistry);
ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
when(configDescriptionProvider.getConfigDescription(any(), any())).thenAnswer(invocation -> configDescriptions.get(invocation.getArgument(0)));
registerService(configDescriptionProvider);
ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelTypes(any())).thenReturn(channelTypes.values());
when(channelTypeProvider.getChannelType(any(), any())).thenAnswer(invocation -> channelTypes.get(invocation.getArgument(0)));
registerService(channelTypeProvider);
ChannelGroupTypeProvider channelGroupTypeProvider = mock(ChannelGroupTypeProvider.class);
when(channelGroupTypeProvider.getChannelGroupTypes(any())).thenReturn(channelGroupTypes.values());
when(channelGroupTypeProvider.getChannelGroupType(any(), any())).thenAnswer(invocation -> channelGroupTypes.get(invocation.getArgument(0)));
registerService(channelGroupTypeProvider);
managedItemProvider.add(new StringItem(ITEM_GENERIC));
managedItemProvider.add(new StringItem(ITEM_SPECIFIC));
managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_GENERIC);
managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_SPECIFIC);
}
use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-core by openhab.
the class ThingManagerOSGiTest method setUp.
@BeforeEach
@SuppressWarnings("null")
public void setUp() {
thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(ChannelBuilder.create(CHANNEL_UID, CoreItemFactory.SWITCH).withKind(ChannelKind.STATE).withType(CHANNEL_TYPE_UID).build()).build();
registerVolatileStorageService();
configurationAdmin = getService(ConfigurationAdmin.class);
assertNotNull(configurationAdmin);
channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), nullable(Locale.class))).thenReturn(ChannelTypeBuilder.state(CHANNEL_TYPE_UID, "label", CoreItemFactory.SWITCH).build());
registerService(channelTypeProvider);
managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
managedThingProvider = getService(ManagedThingProvider.class);
eventPublisher = getService(EventPublisher.class);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
assertNotNull(itemChannelLinkRegistry);
readyService = getService(ReadyService.class);
assertNotNull(readyService);
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ReadyMarker.class, "(" + ThingManagerImpl.XML_THING_TYPE + "=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
} catch (InvalidSyntaxException e) {
fail("Failed to get service reference: " + e.getMessage());
}
});
Bundle bundle = mock(Bundle.class);
when(bundle.getSymbolicName()).thenReturn("org.openhab.core.thing");
BundleResolver bundleResolver = mock(BundleResolver.class);
when(bundleResolver.resolveBundle(any())).thenReturn(bundle);
ThingManagerImpl thingManager = (ThingManagerImpl) getService(ThingTypeMigrationService.class);
thingManager.setBundleResolver(bundleResolver);
}
use of org.openhab.core.thing.link.ManagedItemChannelLinkProvider in project openhab-addons by openhab.
the class FeedHandlerTest method initializeItem.
private void initializeItem(ChannelUID channelUID) {
// Create new item
ItemRegistry itemRegistry = getService(ItemRegistry.class);
assertThat(itemRegistry, is(notNullValue()));
StringItem newItem = new StringItem(ITEM_NAME);
// Add item state change listener
StateChangeListener updateListener = new StateChangeListener() {
@Override
public void stateChanged(Item item, State oldState, State newState) {
}
@Override
public void stateUpdated(Item item, State state) {
currentItemState = (StringType) state;
}
};
newItem.addStateChangeListener(updateListener);
itemRegistry.add(newItem);
// Add item channel link
ManagedItemChannelLinkProvider itemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
assertThat(itemChannelLinkProvider, is(notNullValue()));
itemChannelLinkProvider.add(new ItemChannelLink(ITEM_NAME, channelUID));
}
Aggregations