use of org.openhab.core.thing.type.ThingType in project openhab-core by openhab.
the class ThingFactoryTest method createSimpleThing.
@Test
public void createSimpleThing() {
ThingType thingType = ThingTypeBuilder.instance("bindingId", "thingTypeId", "label").build();
Configuration configuration = new Configuration();
Thing thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), configuration);
assertThat(thing.getUID().toString(), is(equalTo("bindingId:thingTypeId:thingId")));
assertThat(thing.getThingTypeUID().toString(), is(equalTo("bindingId:thingTypeId")));
assertThat(thing.getConfiguration(), is(not(nullValue())));
assertThat(thing.getProperties(), is(not(nullValue())));
}
use of org.openhab.core.thing.type.ThingType in project openhab-core by openhab.
the class ThingFactoryTest method createThingWithDefaultValues.
@Test
public void createThingWithDefaultValues() throws Exception {
ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("myThingType", "myThing"), "label").withDescription("description").withChannelDefinitions(getChannelDefinitions()).withConfigDescriptionURI(new URI("scheme", "thingType", null)).build();
Configuration configuration = new Configuration();
ConfigDescriptionRegistry configDescriptionRegistry = mock(ConfigDescriptionRegistry.class);
when(configDescriptionRegistry.getConfigDescription(any(URI.class))).thenAnswer(new Answer<ConfigDescription>() {
@Override
@Nullable
public ConfigDescription answer(InvocationOnMock invocation) throws Throwable {
URI uri = (URI) invocation.getArgument(0);
return ConfigDescriptionBuilder.create(uri).withParameter(ConfigDescriptionParameterBuilder.create("testProperty", ConfigDescriptionParameter.Type.TEXT).withContext("context").withDefault("default").withDescription("description").withLimitToOptions(true).build()).build();
}
});
Thing thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), configuration, null, configDescriptionRegistry);
assertThat(thing.getConfiguration(), is(not(nullValue())));
assertThat(thing.getConfiguration().get("testProperty"), is(not(nullValue())));
assertThat(thing.getConfiguration().get("testProperty"), is(equalTo("default")));
assertThat(thing.getChannels().size(), is(equalTo(2)));
assertThat(thing.getChannels().get(0).getConfiguration().get("testProperty"), is(equalTo("default")));
assertThat(thing.getChannels().get(1).getConfiguration().get("testProperty"), is(equalTo("default")));
assertThat(thing.getProperties().size(), is(0));
}
use of org.openhab.core.thing.type.ThingType in project openhab-core by openhab.
the class BindingBaseClassesOSGiTest method registerThingTypeProvider.
private void registerThingTypeProvider() {
ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID(BINDING_ID, THING_TYPE_ID), "label").withConfigDescriptionURI(BINDING_CONFIG_URI).build();
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(ArgumentMatchers.any(ThingTypeUID.class), ArgumentMatchers.nullable(Locale.class))).thenReturn(thingType);
registerService(thingTypeProvider);
ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
when(thingTypeRegistry.getThingType(ArgumentMatchers.any(ThingTypeUID.class))).thenReturn(thingType);
registerService(thingTypeRegistry);
}
use of org.openhab.core.thing.type.ThingType in project openhab-core by openhab.
the class BindingBaseClassesOSGiTest method registerThingTypeAndConfigDescription.
private void registerThingTypeAndConfigDescription() {
ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID(BINDING_ID, THING_TYPE_ID), "label").withConfigDescriptionURI(BINDING_CONFIG_URI).build();
ConfigDescription configDescription = ConfigDescriptionBuilder.create(BINDING_CONFIG_URI).withParameter(ConfigDescriptionParameterBuilder.create("parameter", ConfigDescriptionParameter.Type.TEXT).withRequired(true).build()).build();
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(ArgumentMatchers.any(ThingTypeUID.class), ArgumentMatchers.any(Locale.class))).thenReturn(thingType);
registerService(thingTypeProvider);
ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
when(thingTypeRegistry.getThingType(ArgumentMatchers.any(ThingTypeUID.class))).thenReturn(thingType);
registerService(thingTypeRegistry);
ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
when(configDescriptionProvider.getConfigDescription(ArgumentMatchers.any(URI.class), ArgumentMatchers.nullable(Locale.class))).thenReturn(configDescription);
registerService(configDescriptionProvider);
}
use of org.openhab.core.thing.type.ThingType in project openhab-core by openhab.
the class ThingManagerOSGiJavaTest method registerThingTypeProvider.
private void registerThingTypeProvider() throws Exception {
ThingType thingType = ThingTypeBuilder.instance(THING_TYPE_UID, "label").withConfigDescriptionURI(configDescriptionThing).withChannelDefinitions(List.of(new ChannelDefinitionBuilder(CHANNEL_ID, CHANNEL_TYPE_UID).build())).build();
ThingTypeProvider mockThingTypeProvider = mock(ThingTypeProvider.class);
when(mockThingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(thingType);
registerService(mockThingTypeProvider);
}
Aggregations