Search in sources :

Example 1 with VolatileStorageService

use of org.openhab.core.test.storage.VolatileStorageService 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 2 with VolatileStorageService

use of org.openhab.core.test.storage.VolatileStorageService 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 3 with VolatileStorageService

use of org.openhab.core.test.storage.VolatileStorageService in project openhab-core by openhab.

the class SayCommandTest method testSayCommand.

@ParameterizedTest
@MethodSource("data")
public void testSayCommand(boolean shouldItemsBePassed, boolean shouldItemsBeRegistered, boolean shouldMultipleItemsBeRegistered, @Nullable TTSService defaultTTSService, boolean ttsServiceMockShouldBeRegistered, boolean shouldStreamBeExpected) throws IOException {
    String[] methodParameters = new String[2];
    methodParameters[0] = SUBCMD_SAY;
    if (defaultTTSService != null) {
        ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class);
        Dictionary<String, Object> audioConfig = new Hashtable<>();
        audioConfig.put("defaultSink", sink.getId());
        Configuration configuration = configAdmin.getConfiguration("org.openhab.audio", null);
        configuration.update(audioConfig);
        Dictionary<String, Object> voiceConfig = new Hashtable<>();
        voiceConfig.put(CONFIG_DEFAULT_TTS, defaultTTSService);
        configuration = configAdmin.getConfiguration(VoiceManagerImpl.CONFIGURATION_PID);
        configuration.update(voiceConfig);
    }
    TTSService ttsService = SayCommandTest.ttsService;
    if (ttsServiceMockShouldBeRegistered && ttsService != null) {
        registerService(ttsService);
    }
    if (shouldItemsBePassed) {
        VolatileStorageService volatileStorageService = new VolatileStorageService();
        registerService(volatileStorageService);
        ManagedThingProvider managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
        assertNotNull(managedThingProvider);
        ItemRegistry itemRegistry = getService(ItemRegistry.class);
        assertNotNull(itemRegistry);
        Item item = new StringItem("itemName");
        if (shouldItemsBeRegistered) {
            itemRegistry.add(item);
        }
        methodParameters[1] = "%" + item.getName() + "%";
        if (shouldMultipleItemsBeRegistered) {
            Item item1 = new StringItem("itemName1");
            itemRegistry.add(item1);
            Item item2 = new StringItem("itemName2");
            itemRegistry.add(item2);
            Item item3 = new StringItem("itemName3");
            itemRegistry.add(item3);
            methodParameters[1] = "%itemName.%";
        }
    } else {
        methodParameters[1] = "hello";
    }
    extensionService.execute(methodParameters, console);
    assertThat(sink.isStreamProcessed(), is(shouldStreamBeExpected));
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) TTSService(org.openhab.core.voice.TTSService) ItemRegistry(org.openhab.core.items.ItemRegistry) StringItem(org.openhab.core.library.items.StringItem) Item(org.openhab.core.items.Item) StringItem(org.openhab.core.library.items.StringItem) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) VolatileStorageService(org.openhab.core.test.storage.VolatileStorageService) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with VolatileStorageService

use of org.openhab.core.test.storage.VolatileStorageService in project openhab-core by openhab.

the class ItemRegistryImplTest method beforeEach.

@BeforeEach
public void beforeEach() {
    GenericItem cameraItem1 = new SwitchItem(CAMERA_ITEM_NAME1);
    GenericItem cameraItem2 = new SwitchItem(CAMERA_ITEM_NAME2);
    GenericItem cameraItem3 = new NumberItem(CAMERA_ITEM_NAME3);
    GenericItem cameraItem4 = new NumberItem(CAMERA_ITEM_NAME4);
    cameraItem1.addTag(CAMERA_TAG);
    cameraItem2.addTag(CAMERA_TAG);
    cameraItem2.addTag(SENSOR_TAG);
    cameraItem3.addTag(CAMERA_TAG);
    cameraItem4.addTag(CAMERA_TAG_UPPERCASE);
    // setup ManageItemProvider with necessary dependencies:
    itemProvider = new ManagedItemProvider(new VolatileStorageService(), new ItemBuilderFactoryImpl(new CoreItemFactory()));
    itemProvider.add(new SwitchItem(ITEM_NAME));
    itemProvider.add(cameraItem1);
    itemProvider.add(cameraItem2);
    itemProvider.add(cameraItem3);
    itemProvider.add(cameraItem4);
    // setup ItemRegistryImpl with necessary dependencies:
    itemRegistry = new ItemRegistryImpl(mock(MetadataRegistry.class)) {

        {
            addProvider(itemProvider);
            setManagedProvider(itemProvider);
            setEventPublisher(ItemRegistryImplTest.this.eventPublisherMock);
            setStateDescriptionService(mock(StateDescriptionService.class));
            setUnitProvider(mock(UnitProvider.class));
            setItemStateConverter(mock(ItemStateConverter.class));
        }
    };
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) CoreItemFactory(org.openhab.core.library.CoreItemFactory) VolatileStorageService(org.openhab.core.test.storage.VolatileStorageService) ItemBuilderFactoryImpl(org.openhab.core.internal.items.ItemBuilderFactoryImpl) ItemRegistryImpl(org.openhab.core.internal.items.ItemRegistryImpl) SwitchItem(org.openhab.core.library.items.SwitchItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with VolatileStorageService

use of org.openhab.core.test.storage.VolatileStorageService in project openhab-addons by openhab.

the class FeedHandlerTest method setUp.

@BeforeEach
public void setUp() {
    volatileStorageService = new VolatileStorageService();
    registerService(volatileStorageService);
    managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
    assertThat(managedThingProvider, is(notNullValue()));
    thingRegistry = getService(ThingRegistry.class);
    assertThat(thingRegistry, is(notNullValue()));
    registerFeedTestServlet();
}
Also used : ThingProvider(org.openhab.core.thing.ThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) VolatileStorageService(org.openhab.core.test.storage.VolatileStorageService) ThingRegistry(org.openhab.core.thing.ThingRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

VolatileStorageService (org.openhab.core.test.storage.VolatileStorageService)6 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 ThingRegistry (org.openhab.core.thing.ThingRegistry)4 ItemRegistry (org.openhab.core.items.ItemRegistry)3 ThingProvider (org.openhab.core.thing.ThingProvider)3 Locale (java.util.Locale)2 ChannelTypeProvider (org.openhab.core.thing.type.ChannelTypeProvider)2 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)2 Hashtable (java.util.Hashtable)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 UpnpService (org.jupnp.UpnpService)1 MockUpnpService (org.jupnp.mock.MockUpnpService)1 SysteminfoHandlerFactory (org.openhab.binding.systeminfo.internal.SysteminfoHandlerFactory)1 SysteminfoInterface (org.openhab.binding.systeminfo.internal.model.SysteminfoInterface)1 WemoHttpCallFactory (org.openhab.binding.wemo.internal.WemoHttpCallFactory)1 WemoHttpCall (org.openhab.binding.wemo.internal.http.WemoHttpCall)1 ItemBuilderFactoryImpl (org.openhab.core.internal.items.ItemBuilderFactoryImpl)1 ItemRegistryImpl (org.openhab.core.internal.items.ItemRegistryImpl)1