Search in sources :

Example 1 with VolatileStorageService

use of org.eclipse.smarthome.test.storage.VolatileStorageService in project smarthome by eclipse.

the class NtpOSGiTest method setUp.

@Before
public void setUp() {
    VolatileStorageService volatileStorageService = new VolatileStorageService();
    registerService(volatileStorageService);
    managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
    assertNotNull(managedThingProvider);
    thingRegistry = getService(ThingRegistry.class);
    assertNotNull(thingRegistry);
    itemRegistry = getService(ItemRegistry.class);
    assertNotNull(itemRegistry);
    channelTypeUID = new ChannelTypeUID(NtpBindingConstants.BINDING_ID + ":channelType");
    channelTypeProvider = mock(ChannelTypeProvider.class);
    when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), any(Locale.class))).thenReturn(new ChannelType(channelTypeUID, false, "Switch", ChannelKind.STATE, "label", null, null, null, null, null, null));
    registerService(channelTypeProvider);
}
Also used : Locale(java.util.Locale) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ThingProvider(org.eclipse.smarthome.core.thing.ThingProvider) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) Before(org.junit.Before)

Example 2 with VolatileStorageService

use of org.eclipse.smarthome.test.storage.VolatileStorageService in project smarthome by eclipse.

the class AutomaticInboxProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    when(thing.getConfiguration()).thenReturn(CONFIG);
    when(thing.getThingTypeUID()).thenReturn(THING_TYPE_UID);
    when(thing.getProperties()).thenReturn(THING_PROPERTIES);
    when(thing.getStatus()).thenReturn(ThingStatus.ONLINE);
    when(thing.getUID()).thenReturn(THING_UID);
    when(thing2.getConfiguration()).thenReturn(CONFIG);
    when(thing2.getThingTypeUID()).thenReturn(THING_TYPE_UID);
    when(thing2.getProperties()).thenReturn(THING_PROPERTIES);
    when(thing2.getStatus()).thenReturn(ThingStatus.ONLINE);
    when(thing2.getUID()).thenReturn(THING_UID2);
    when(thing3.getConfiguration()).thenReturn(CONFIG);
    when(thing3.getThingTypeUID()).thenReturn(THING_TYPE_UID3);
    when(thing3.getProperties()).thenReturn(OTHER_THING_PROPERTIES);
    when(thing3.getStatus()).thenReturn(ThingStatus.ONLINE);
    when(thing3.getUID()).thenReturn(THING_UID3);
    when(thingRegistry.stream()).thenReturn(Stream.empty());
    when(thingTypeRegistry.getThingType(THING_TYPE_UID)).thenReturn(THING_TYPE);
    when(thingTypeRegistry.getThingType(THING_TYPE_UID2)).thenReturn(THING_TYPE2);
    when(thingTypeRegistry.getThingType(THING_TYPE_UID3)).thenReturn(THING_TYPE3);
    when(thingHandlerFactory.supportsThingType(eq(THING_TYPE_UID))).thenReturn(true);
    when(thingHandlerFactory.createThing(eq(THING_TYPE_UID), any(Configuration.class), eq(THING_UID), any(ThingUID.class))).then(invocation -> ThingBuilder.create(THING_TYPE_UID, "test").withConfiguration((Configuration) invocation.getArguments()[1]).build());
    inbox = new PersistentInbox();
    inbox.setThingRegistry(thingRegistry);
    inbox.setStorageService(new VolatileStorageService());
    inbox.setManagedThingProvider(thingProvider);
    inbox.setConfigDescriptionRegistry(configDescriptionRegistry);
    inbox.setThingTypeRegistry(thingTypeRegistry);
    inbox.addThingHandlerFactory(thingHandlerFactory);
    inboxAutoIgnore = new AutomaticInboxProcessor();
    inboxAutoIgnore.setThingRegistry(thingRegistry);
    inboxAutoIgnore.setThingTypeRegistry(thingTypeRegistry);
    inboxAutoIgnore.setInbox(inbox);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) Before(org.junit.Before)

Example 3 with VolatileStorageService

use of org.eclipse.smarthome.test.storage.VolatileStorageService in project smarthome by eclipse.

the class SayCommandTest method testSayCommand.

@Test
public void testSayCommand() throws IOException {
    String[] methodParameters = new String[2];
    methodParameters[0] = SUBCMD_SAY;
    if (defaultTTSService != null) {
        Dictionary<String, Object> config = new Hashtable<String, Object>();
        config.put(CONFIG_DEFAULT_TTS, defaultTTSService);
        ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class);
        String pid = "org.eclipse.smarthome.voice";
        Configuration configuration = configAdmin.getConfiguration(pid);
        configuration.update(config);
    }
    if (TTSServiceMockShouldBeRegistered) {
        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 : Item(org.eclipse.smarthome.core.items.Item) StringItem(org.eclipse.smarthome.core.library.items.StringItem) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) StringItem(org.eclipse.smarthome.core.library.items.StringItem) Test(org.junit.Test)

Aggregations

VolatileStorageService (org.eclipse.smarthome.test.storage.VolatileStorageService)3 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)2 ManagedThingProvider (org.eclipse.smarthome.core.thing.ManagedThingProvider)2 Before (org.junit.Before)2 Hashtable (java.util.Hashtable)1 Locale (java.util.Locale)1 Configuration (org.eclipse.smarthome.config.core.Configuration)1 Item (org.eclipse.smarthome.core.items.Item)1 StringItem (org.eclipse.smarthome.core.library.items.StringItem)1 ThingProvider (org.eclipse.smarthome.core.thing.ThingProvider)1 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)1 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)1 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)1 ChannelTypeProvider (org.eclipse.smarthome.core.thing.type.ChannelTypeProvider)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1 Test (org.junit.Test)1 Configuration (org.osgi.service.cm.Configuration)1 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)1