Search in sources :

Example 1 with ConfigDescriptionProvider

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);
}
Also used : BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) Command(org.eclipse.smarthome.core.types.Command) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) ConfigDescriptionProvider(org.eclipse.smarthome.config.core.ConfigDescriptionProvider) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)1 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)1 ConfigDescriptionProvider (org.eclipse.smarthome.config.core.ConfigDescriptionProvider)1 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)1 BaseThingHandler (org.eclipse.smarthome.core.thing.binding.BaseThingHandler)1 Command (org.eclipse.smarthome.core.types.Command)1 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)1 Test (org.junit.Test)1