Search in sources :

Example 1 with ThingManager

use of org.eclipse.smarthome.core.thing.ThingManager in project smarthome by eclipse.

the class ThingManagerOSGiTest method thingManagerAllowsChangesToUnmanagedThings.

@Test
@SuppressWarnings({ "null", "unchecked" })
public void thingManagerAllowsChangesToUnmanagedThings() throws Exception {
    ThingManager thingManager = (ThingManager) getService(ThingTypeMigrationService.class);
    assertThat(thingManager, is(notNullValue()));
    ThingProvider customThingProvider = mock(ThingProvider.class);
    when(customThingProvider.getAll()).thenReturn(Collections.singletonList(thing));
    registerService(customThingProvider);
    ThingRegistry thingRegistry = getService(ThingRegistry.class);
    RegistryChangeListener<Thing> registryChangeListener = mock(RegistryChangeListener.class);
    try {
        thingRegistry.addRegistryChangeListener(registryChangeListener);
        Field field = thingManager.getClass().getDeclaredField("thingHandlerCallback");
        field.setAccessible(true);
        ThingHandlerCallback callback = (ThingHandlerCallback) field.get(thingManager);
        callback.thingUpdated(thing);
        verify(registryChangeListener, times(1)).updated(any(Thing.class), any(Thing.class));
    } finally {
        thingRegistry.removeRegistryChangeListener(registryChangeListener);
    }
}
Also used : Field(java.lang.reflect.Field) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ThingProvider(org.eclipse.smarthome.core.thing.ThingProvider) ThingTypeMigrationService(org.eclipse.smarthome.core.thing.ThingTypeMigrationService) ThingHandlerCallback(org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback) ThingManager(org.eclipse.smarthome.core.thing.ThingManager) Thing(org.eclipse.smarthome.core.thing.Thing) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 2 with ThingManager

use of org.eclipse.smarthome.core.thing.ThingManager in project smarthome by eclipse.

the class ThingManagerOSGiJavaTest method setUp.

@Before
public void setUp() throws Exception {
    CONFIG_DESCRIPTION_THING = new URI("test:test");
    CONFIG_DESCRIPTION_CHANNEL = new URI("test:channel");
    THING = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(// 
    Collections.singletonList(ChannelBuilder.create(CHANNEL_UID, "Switch").withLabel("Test Label").withDescription("Test Description").withType(CHANNEL_TYPE_UID).withDefaultTags(Collections.singleton("Test Tag")).build())).build();
    registerVolatileStorageService();
    configureAutoLinking(false);
    managedThingProvider = getService(ManagedThingProvider.class);
    itemRegistry = getService(ItemRegistry.class);
    assertNotNull(itemRegistry);
    thingRegistry = getService(ThingRegistry.class);
    assertNotNull(thingRegistry);
    StorageService storageService;
    storageService = getService(StorageService.class);
    assertNotNull(storageService);
    storage = storageService.getStorage("thing_status_storage");
    itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
    assertNotNull(itemChannelLinkRegistry);
    readyService = getService(ReadyService.class);
    assertNotNull(readyService);
    thingManager = getService(ThingManager.class);
    assertNotNull(thingManager);
    waitForAssert(() -> {
        try {
            assertThat(bundleContext.getServiceReferences(ReadyMarker.class, "(esh.xmlThingTypes=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
        } catch (InvalidSyntaxException e) {
            throw new RuntimeException(e);
        }
    });
    waitForAssert(() -> {
        try {
            assertThat(bundleContext.getServiceReferences(ChannelItemProvider.class, null), is(notNullValue()));
        } catch (InvalidSyntaxException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ReadyService(org.eclipse.smarthome.core.service.ReadyService) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ThingManager(org.eclipse.smarthome.core.thing.ThingManager) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) URI(java.net.URI) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) StorageService(org.eclipse.smarthome.core.storage.StorageService) Before(org.junit.Before)

Aggregations

ManagedThingProvider (org.eclipse.smarthome.core.thing.ManagedThingProvider)2 ThingManager (org.eclipse.smarthome.core.thing.ThingManager)2 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)2 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)1 ReadyMarker (org.eclipse.smarthome.core.service.ReadyMarker)1 ReadyService (org.eclipse.smarthome.core.service.ReadyService)1 StorageService (org.eclipse.smarthome.core.storage.StorageService)1 Thing (org.eclipse.smarthome.core.thing.Thing)1 ThingProvider (org.eclipse.smarthome.core.thing.ThingProvider)1 ThingTypeMigrationService (org.eclipse.smarthome.core.thing.ThingTypeMigrationService)1 ThingHandlerCallback (org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback)1 ItemChannelLinkRegistry (org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry)1 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)1 Before (org.junit.Before)1 Test (org.junit.Test)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1