use of org.openhab.core.thing.ThingProvider in project openhab-core by openhab.
the class ThingRegistryOSGiTest method assertThatThingRegistryDelegatesConfigUpdateToThingHandler.
@Test
public void assertThatThingRegistryDelegatesConfigUpdateToThingHandler() {
ThingUID thingUID = new ThingUID("binding:type:thing");
Thing thing = ThingBuilder.create(THING_TYPE_UID, thingUID).build();
ThingHandler thingHandler = new BaseThingHandler(thing) {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
}
@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) {
changedParameters = configurationParameters;
}
@Override
public void initialize() {
updateStatus(ThingStatus.ONLINE);
}
};
thing.setHandler(thingHandler);
ThingProvider thingProvider = new ThingProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Thing> listener) {
}
@Override
public Collection<Thing> getAll() {
return Set.of(thing);
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<Thing> listener) {
}
};
registerService(thingProvider);
ThingRegistry thingRegistry = getService(ThingRegistry.class);
Map<String, Object> parameters = Map.ofEntries(entry("param1", "value1"), entry("param2", 1));
thingRegistry.updateConfiguration(thingUID, parameters);
assertThat(changedParameters.entrySet(), is(equalTo(parameters.entrySet())));
}
use of org.openhab.core.thing.ThingProvider in project openhab-addons by openhab.
the class AbstractModbusOSGiTest method setUpAbstractModbusOSGiTest.
/**
* Before each test, configure mocked services
*/
@BeforeEach
public void setUpAbstractModbusOSGiTest() {
logger.debug("setUpAbstractModbusOSGiTest BEGIN");
registerVolatileStorageService();
registerService(mockedModbusManager);
registerService(stateSubscriber);
swapModbusManagerToMocked();
thingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertThat("Could not get ManagedThingProvider", thingProvider, is(notNullValue()));
itemProvider = getService(ItemProvider.class, ManagedItemProvider.class);
assertThat("Could not get ManagedItemProvider", itemProvider, is(notNullValue()));
itemChannelLinkProvider = getService(ItemChannelLinkProvider.class, ManagedItemChannelLinkProvider.class);
assertThat("Could not get ManagedItemChannelLinkProvider", itemChannelLinkProvider, is(notNullValue()));
itemRegistry = getService(ItemRegistry.class);
assertThat("Could not get ItemRegistry", itemRegistry, is(notNullValue()));
coreItemFactory = new CoreItemFactory();
// Clean slate for all tests
reset(mockedModbusManager);
stateSubscriber.stateUpdates.clear();
logger.debug("setUpAbstractModbusOSGiTest END");
}
use of org.openhab.core.thing.ThingProvider in project openhab-core by openhab.
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(List.of(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);
}
}
Aggregations