use of org.openhab.core.thing.ManagedThingProvider in project openhab-addons by openhab.
the class AVMFritzThingHandlerOSGiTest method setUp.
@BeforeEach
public void setUp() {
registerService(volatileStorageService);
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertNotNull(managedThingProvider, "Could not get ManagedThingProvider");
bridge = buildBridge();
assertNotNull(bridge.getConfiguration());
managedThingProvider.add(bridge);
ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
bridgeHandler = new BoxHandler(bridge, httpClient, mock(AVMFritzDynamicCommandDescriptionProvider.class));
assertNotNull(bridgeHandler);
bridgeHandler.setCallback(callback);
assertNull(bridge.getHandler());
bridge.setHandler(bridgeHandler);
assertNotNull(bridge.getHandler());
bridgeHandler.initialize();
}
use of org.openhab.core.thing.ManagedThingProvider in project openhab-addons by openhab.
the class SysteminfoOSGiTest method setUp.
@BeforeEach
public void setUp() {
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
// Preparing the mock with OS properties, that are used in the initialize method of SysteminfoHandler
mockedSystemInfo = mock(SysteminfoInterface.class);
when(mockedSystemInfo.getCpuLogicalCores()).thenReturn(new DecimalType(2));
when(mockedSystemInfo.getCpuPhysicalCores()).thenReturn(new DecimalType(2));
when(mockedSystemInfo.getOsFamily()).thenReturn(new StringType("Mock OS"));
when(mockedSystemInfo.getOsManufacturer()).thenReturn(new StringType("Mock OS Manufacturer"));
when(mockedSystemInfo.getOsVersion()).thenReturn(new StringType("Mock Os Version"));
systeminfoHandlerFactory = getService(ThingHandlerFactory.class, SysteminfoHandlerFactory.class);
SysteminfoInterface oshiSystemInfo = getService(SysteminfoInterface.class);
// the external OSHI library
if (oshiSystemInfo != null) {
systeminfoHandlerFactory.unbindSystemInfo(oshiSystemInfo);
}
systeminfoHandlerFactory.bindSystemInfo(mockedSystemInfo);
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
thingRegistry = getService(ThingRegistry.class);
assertThat(thingRegistry, is(notNullValue()));
itemRegistry = getService(ItemRegistry.class);
assertThat(itemRegistry, is(notNullValue()));
}
use of org.openhab.core.thing.ManagedThingProvider in project openhab-addons by openhab.
the class GenericWemoOSGiTest method setUpServices.
protected void setUpServices() throws IOException {
WemoUtil.serviceAvailableFunction = (host, port) -> true;
// StorageService is required from the ManagedThingProvider
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
// Mock the UPnP Service, that is required from the UPnP IO Service
mockUpnpService = new MockUpnpService(false, true);
mockUpnpService.startup();
registerService(mockUpnpService, UpnpService.class.getName());
managedThingProvider = getService(ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
thingRegistry = getService(ThingRegistry.class);
assertThat(thingRegistry, is(notNullValue()));
// UPnP IO Service is required from the WemoDiscoveryService and WemoHandlerFactory
upnpIOService = getService(UpnpIOService.class);
assertThat(upnpIOService, is(notNullValue()));
mockCaller = Mockito.spy(new WemoHttpCall());
WemoHttpCallFactory wemoHttpCallFactory = () -> mockCaller;
registerService(wemoHttpCallFactory, WemoHttpCallFactory.class.getName());
ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), any(Locale.class))).thenReturn(ChannelTypeBuilder.state(DEFAULT_CHANNEL_TYPE_UID, "label", CoreItemFactory.SWITCH).build());
registerService(channelTypeProvider);
}
use of org.openhab.core.thing.ManagedThingProvider in project openhab-core by openhab.
the class DynamicThingUpdateOSGiTest method setUp.
@BeforeEach
public void setUp() {
registerVolatileStorageService();
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(THING_TYPE);
registerService(thingTypeProvider);
inbox = getService(Inbox.class);
managedThingProvider = getService(ManagedThingProvider.class);
assertEquals(0, inbox.getAll().size());
ThingHandlerFactory thingHandlerFactory = createThingHandlerFactory();
registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
}
use of org.openhab.core.thing.ManagedThingProvider 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);
}
Aggregations