Search in sources :

Example 1 with ManagedThingProvider

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();
}
Also used : ThingProvider(org.openhab.core.thing.ThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ThingHandlerCallback(org.openhab.core.thing.binding.ThingHandlerCallback) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ManagedThingProvider

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()));
}
Also used : ThingProvider(org.openhab.core.thing.ThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) StringType(org.openhab.core.library.types.StringType) SysteminfoInterface(org.openhab.binding.systeminfo.internal.model.SysteminfoInterface) DecimalType(org.openhab.core.library.types.DecimalType) SysteminfoHandlerFactory(org.openhab.binding.systeminfo.internal.SysteminfoHandlerFactory) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) VolatileStorageService(org.openhab.core.test.storage.VolatileStorageService) ItemRegistry(org.openhab.core.items.ItemRegistry) ThingHandlerFactory(org.openhab.core.thing.binding.ThingHandlerFactory) ThingRegistry(org.openhab.core.thing.ThingRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ManagedThingProvider

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);
}
Also used : MockUpnpService(org.jupnp.mock.MockUpnpService) UpnpService(org.jupnp.UpnpService) WemoHttpCallFactory(org.openhab.binding.wemo.internal.WemoHttpCallFactory) Locale(java.util.Locale) MockUpnpService(org.jupnp.mock.MockUpnpService) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) WemoHttpCall(org.openhab.binding.wemo.internal.http.WemoHttpCall) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) VolatileStorageService(org.openhab.core.test.storage.VolatileStorageService) UpnpIOService(org.openhab.core.io.transport.upnp.UpnpIOService) ThingRegistry(org.openhab.core.thing.ThingRegistry)

Example 4 with ManagedThingProvider

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());
}
Also used : ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ThingTypeProvider(org.openhab.core.thing.binding.ThingTypeProvider) ThingHandlerFactory(org.openhab.core.thing.binding.ThingHandlerFactory) BaseThingHandlerFactory(org.openhab.core.thing.binding.BaseThingHandlerFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ManagedThingProvider

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);
}
Also used : ManagedItemProvider(org.openhab.core.items.ManagedItemProvider) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ComponentContext(org.osgi.service.component.ComponentContext) StringItem(org.openhab.core.library.items.StringItem) ChannelGroupTypeProvider(org.openhab.core.thing.type.ChannelGroupTypeProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) ConfigDescriptionRegistry(org.openhab.core.config.core.ConfigDescriptionRegistry) ConfigDescriptionProvider(org.openhab.core.config.core.ConfigDescriptionProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)25 BeforeEach (org.junit.jupiter.api.BeforeEach)13 ThingRegistry (org.openhab.core.thing.ThingRegistry)10 Test (org.junit.jupiter.api.Test)7 Configuration (org.openhab.core.config.core.Configuration)7 ItemRegistry (org.openhab.core.items.ItemRegistry)7 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)7 Thing (org.openhab.core.thing.Thing)7 ThingProvider (org.openhab.core.thing.ThingProvider)7 Item (org.openhab.core.items.Item)5 VolatileStorageService (org.openhab.core.test.storage.VolatileStorageService)5 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)5 ThingUID (org.openhab.core.thing.ThingUID)5 NumberItem (org.openhab.core.library.items.NumberItem)4 StringItem (org.openhab.core.library.items.StringItem)4 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)4 ItemChannelLink (org.openhab.core.thing.link.ItemChannelLink)4 ManagedItemChannelLinkProvider (org.openhab.core.thing.link.ManagedItemChannelLinkProvider)4 ComponentContext (org.osgi.service.component.ComponentContext)4 Locale (java.util.Locale)3