use of org.eclipse.smarthome.config.core.ConfigDescriptionProvider in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method testInitializeOnlyIfInitializable.
@Test
public void testInitializeOnlyIfInitializable() throws Exception {
registerThingTypeProvider();
registerChannelTypeProvider();
registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
}
});
ConfigDescriptionProvider mockConfigDescriptionProvider = mock(ConfigDescriptionProvider.class);
List<ConfigDescriptionParameter> parameters = //
Collections.singletonList(//
ConfigDescriptionParameterBuilder.create(CONFIG_PARAM_NAME, Type.TEXT).withRequired(true).build());
registerService(mockConfigDescriptionProvider, ConfigDescriptionProvider.class.getName());
// verify a missing mandatory thing config prevents it from getting initialized
when(mockConfigDescriptionProvider.getConfigDescription(eq(CONFIG_DESCRIPTION_THING), any())).thenReturn(new ConfigDescription(CONFIG_DESCRIPTION_THING, parameters));
assertThingStatus(Collections.emptyMap(), Collections.emptyMap(), ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_CONFIGURATION_PENDING);
// verify a missing mandatory channel config prevents it from getting initialized
when(mockConfigDescriptionProvider.getConfigDescription(eq(CONFIG_DESCRIPTION_CHANNEL), any())).thenReturn(new ConfigDescription(CONFIG_DESCRIPTION_CHANNEL, parameters));
assertThingStatus(Collections.singletonMap(CONFIG_PARAM_NAME, "value"), Collections.emptyMap(), ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_CONFIGURATION_PENDING);
// verify a satisfied config does not prevent it from getting initialized anymore
assertThingStatus(Collections.singletonMap(CONFIG_PARAM_NAME, "value"), Collections.singletonMap(CONFIG_PARAM_NAME, "value"), ThingStatus.ONLINE, ThingStatusDetail.NONE);
}
Aggregations