use of org.openhab.core.config.core.ConfigDescriptionProvider in project openhab-core by openhab.
the class InboxOSGiTest method assertThatApproveAddsPropertiesOfDiscoveryResultWhichAreConfigDescriptionParametersAsThingConfigurationPropertiesAndPropertiesWhichAreNoConfigDescriptionParametersAsThingProperties.
@Test
@SuppressWarnings("null")
public void assertThatApproveAddsPropertiesOfDiscoveryResultWhichAreConfigDescriptionParametersAsThingConfigurationPropertiesAndPropertiesWhichAreNoConfigDescriptionParametersAsThingProperties() {
final List<Object> services = new LinkedList<>();
inbox.add(testDiscoveryResult);
final ThingTypeProvider thingTypeProvider = new ThingTypeProvider() {
@Override
public Collection<ThingType> getThingTypes(@Nullable Locale locale) {
return Set.of(testThingType);
}
@Override
@Nullable
public ThingType getThingType(ThingTypeUID thingTypeUID, @Nullable Locale locale) {
return thingTypeUID.equals(testThingType.getUID()) ? testThingType : null;
}
};
services.add(registerService(thingTypeProvider));
final ThingTypeRegistry thingTypeRegistry = getService(ThingTypeRegistry.class);
assertNotNull(thingTypeRegistry);
waitForAssert(() -> assertNotNull(thingTypeRegistry.getThingType(testThingType.getUID())));
final ConfigDescriptionProvider configDescriptionProvider = new ConfigDescriptionProvider() {
@Override
public Collection<ConfigDescription> getConfigDescriptions(@Nullable Locale locale) {
return Set.of(testConfigDescription);
}
@Override
@Nullable
public ConfigDescription getConfigDescription(URI uri, @Nullable Locale locale) {
return uri.equals(testConfigDescription.getUID()) ? testConfigDescription : null;
}
};
services.add(registerService(configDescriptionProvider));
final ConfigDescriptionRegistry configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
assertNotNull(configDescriptionRegistry);
waitForAssert(() -> assertNotNull(configDescriptionRegistry.getConfigDescription(testConfigDescription.getUID())));
Thing approvedThing = inbox.approve(testThing.getUID(), testThingLabel, null);
Thing addedThing = registry.get(testThing.getUID());
assertTrue(approvedThing.equals(addedThing));
assertFalse(addedThing == null);
for (String key : keysInConfigDescription) {
Object thingConfItem = addedThing.getConfiguration().get(key);
Object descResultParam = discoveryResultProperties.get(key);
if (descResultParam instanceof Number) {
descResultParam = new BigDecimal(descResultParam.toString());
}
assertFalse(thingConfItem == null);
assertFalse(descResultParam == null);
assertTrue(thingConfItem.equals(descResultParam));
}
for (String key : keysNotInConfigDescription) {
String thingProperty = addedThing.getProperties().get(key);
String descResultParam = String.valueOf(discoveryResultProperties.get(key));
assertFalse(thingProperty == null);
assertFalse(descResultParam == null);
assertTrue(thingProperty.equals(descResultParam));
}
services.forEach(obj -> unregisterService(obj));
}
use of org.openhab.core.config.core.ConfigDescriptionProvider in project openhab-core by openhab.
the class ChangeThingTypeOSGiTest method setup.
@BeforeEach
public void setup() throws URISyntaxException {
registerVolatileStorageService();
managedThingProvider = getService(ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
assertThat(configDescriptionRegistry, is(notNullValue()));
managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
assertThat(managedItemChannelLinkProvider, is(notNullValue()));
managedItemProvider = getService(ManagedItemProvider.class);
assertThat(managedItemProvider, is(notNullValue()));
ComponentContext componentContext = mock(ComponentContext.class);
when(componentContext.getBundleContext()).thenReturn(bundleContext);
thingHandlerFactory = new SampleThingHandlerFactory();
thingHandlerFactory.activate(componentContext);
registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
Map<String, String> thingTypeGenericProperties = Map.ofEntries(entry(PROPERTY_ON_GENERIC_THING_TYPE, GENERIC_VALUE), entry(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, GENERIC_VALUE));
Map<String, String> thingTypeSpecificProperties = Map.ofEntries(entry(PROPERTY_ON_SPECIFIC_THING_TYPE, SPECIFIC_VALUE), entry(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, SPECIFIC_VALUE));
thingTypeGeneric = registerThingTypeAndConfigDescription(THING_TYPE_GENERIC_UID, thingTypeGenericProperties);
thingTypeSpecific = registerThingTypeAndConfigDescription(THING_TYPE_SPECIFIC_UID, thingTypeSpecificProperties);
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
registerService(thingTypeProvider);
ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
when(thingTypeRegistry.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
registerService(thingTypeRegistry);
ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
when(configDescriptionProvider.getConfigDescription(any(), any())).thenAnswer(invocation -> configDescriptions.get(invocation.getArgument(0)));
registerService(configDescriptionProvider);
ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelTypes(any())).thenReturn(channelTypes.values());
when(channelTypeProvider.getChannelType(any(), any())).thenAnswer(invocation -> channelTypes.get(invocation.getArgument(0)));
registerService(channelTypeProvider);
ChannelGroupTypeProvider channelGroupTypeProvider = mock(ChannelGroupTypeProvider.class);
when(channelGroupTypeProvider.getChannelGroupTypes(any())).thenReturn(channelGroupTypes.values());
when(channelGroupTypeProvider.getChannelGroupType(any(), any())).thenAnswer(invocation -> channelGroupTypes.get(invocation.getArgument(0)));
registerService(channelGroupTypeProvider);
managedItemProvider.add(new StringItem(ITEM_GENERIC));
managedItemProvider.add(new StringItem(ITEM_SPECIFIC));
managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_GENERIC);
managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_SPECIFIC);
}
use of org.openhab.core.config.core.ConfigDescriptionProvider 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.config.core.ConfigDescriptionProvider in project openhab-core by openhab.
the class ThingManagerOSGiTest method registerConfigDescriptionProvider.
private void registerConfigDescriptionProvider(boolean withRequiredParameter) {
ConfigDescription configDescription = ConfigDescriptionBuilder.create(THING_CONFIG_URI).withParameter(ConfigDescriptionParameterBuilder.create("parameter", ConfigDescriptionParameter.Type.TEXT).withRequired(withRequiredParameter).build()).build();
ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
when(configDescriptionProvider.getConfigDescription(any(URI.class), nullable(Locale.class))).thenReturn(configDescription);
registerService(configDescriptionProvider);
}
use of org.openhab.core.config.core.ConfigDescriptionProvider in project openhab-core by openhab.
the class GenericThingProviderTest3 method setUp.
@BeforeEach
public void setUp() throws Exception {
thingRegistry = getService(ThingRegistry.class);
assertThat(thingRegistry, is(notNullValue()));
modelRepository = getService(ModelRepository.class);
assertThat(modelRepository, is(notNullValue()));
modelRepository.removeModel(TESTMODEL_NAME);
ComponentContext componentContextMock = mock(ComponentContext.class);
when(componentContextMock.getBundleContext()).thenReturn(bundleContext);
// create a "dumb" thing handler that acts as if the XML config was not yet loaded
dumbThingHandlerFactory = new DumbThingHandlerFactory(componentContextMock, true);
Collection<Thing> things = thingRegistry.getAll();
assertThat(things.size(), is(0));
String model = //
"dumb:DUMB:boo \"Test Label\" @ \"Test Location\" [" + //
" testConf=\"foo\"" + //
"]" + //
"{" + //
" Switch : manual [ duration = \"5\" ]" + "}";
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
registerService(dumbThingHandlerFactory, ThingHandlerFactory.class.getName());
ConfigDescription configDescription = ConfigDescriptionBuilder.create(new URI("test:test")).withParameters(Stream.of(ConfigDescriptionParameterBuilder.create("testAdditional", ConfigDescriptionParameter.Type.TEXT).withRequired(false).withDefault("hello world").build(), ConfigDescriptionParameterBuilder.create("testConf", ConfigDescriptionParameter.Type.TEXT).withRequired(false).withDefault("bar").build()).collect(toList())).build();
ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
when(configDescriptionProvider.getConfigDescription(any(), nullable(Locale.class))).thenReturn(configDescription);
registerService(configDescriptionProvider);
}
Aggregations