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