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