mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Refactor XML handling (#3385)
* Refactor XML handling for things * integrate config.xml and improve naming Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
@@ -60,4 +60,5 @@ Fragment-Host: org.openhab.core.config.core
|
||||
io.methvin.directory-watcher;version='[0.17.1,0.17.2)',\
|
||||
com.sun.jna;version='[5.12.1,5.12.2)',\
|
||||
org.apache.felix.configadmin;version='[1.9.24,1.9.25)',\
|
||||
org.osgi.service.cm;version='[1.6.0,1.6.1)'
|
||||
org.osgi.service.cm;version='[1.6.0,1.6.1)',\
|
||||
xstream;version='[1.4.19,1.4.20)'
|
||||
|
||||
+4
-3
@@ -71,10 +71,11 @@ public class ConfigOptionRegistryOSGiTest extends JavaOSGiTest {
|
||||
|
||||
@Test
|
||||
public void assertConfigDescriptionRegistryMergesOptions() {
|
||||
assertThat("Registery is empty to start", configDescriptionRegistry.getConfigDescriptions(), hasSize(0));
|
||||
int preAddSize = configDescriptionRegistry.getConfigDescriptions().size();
|
||||
|
||||
configDescriptionRegistry.addConfigDescriptionProvider(configDescriptionProviderMock);
|
||||
assertThat("Config description added ok", configDescriptionRegistry.getConfigDescriptions(), hasSize(1));
|
||||
assertThat("Config description added ok", configDescriptionRegistry.getConfigDescriptions(),
|
||||
hasSize(preAddSize + 1));
|
||||
|
||||
configDescriptionRegistry.addConfigOptionProvider(configOptionsProviderMock);
|
||||
|
||||
@@ -91,6 +92,6 @@ public class ConfigOptionRegistryOSGiTest extends JavaOSGiTest {
|
||||
|
||||
configDescriptionRegistry.removeConfigDescriptionProvider(configDescriptionProviderMock);
|
||||
assertThat("Description registery is empty to finish", configDescriptionRegistry.getConfigDescriptions(),
|
||||
hasSize(0));
|
||||
hasSize(preAddSize));
|
||||
}
|
||||
}
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.core.config.core.xml;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.config.core.ConfigDescriptionRegistry;
|
||||
import org.openhab.core.test.BundleCloseable;
|
||||
import org.openhab.core.test.SyntheticBundleInstaller;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* @author Christoph Weitkamp - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BindingInstaller {
|
||||
|
||||
private final Consumer<Runnable> waitForAssert;
|
||||
private final ConfigDescriptionRegistry configDescriptionRegistry;
|
||||
private final BundleContext bc;
|
||||
|
||||
public BindingInstaller(Consumer<Runnable> waitForAssert, ConfigDescriptionRegistry configDescriptionRegistry,
|
||||
BundleContext bc) {
|
||||
this.waitForAssert = waitForAssert;
|
||||
this.configDescriptionRegistry = configDescriptionRegistry;
|
||||
this.bc = bc;
|
||||
}
|
||||
|
||||
public void exec(final String bundleName, final Runnable func) throws Exception {
|
||||
// Save the number of currently installed bundles.
|
||||
final int initialNumberOfConfigDescriptions = configDescriptionRegistry.getConfigDescriptions().size();
|
||||
|
||||
// install test bundle
|
||||
try (BundleCloseable bundle = new BundleCloseable(SyntheticBundleInstaller.install(bc, bundleName))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
// Wait for correctly installed bundle.
|
||||
waitForAssert.accept(() -> assertThat(configDescriptionRegistry.getConfigDescriptions().size(),
|
||||
is(initialNumberOfConfigDescriptions + 1)));
|
||||
|
||||
func.run();
|
||||
}
|
||||
|
||||
// Wait for correctly uninstalled bundle.
|
||||
waitForAssert.accept(() -> assertThat(configDescriptionRegistry.getConfigDescriptions().size(),
|
||||
is(initialNumberOfConfigDescriptions)));
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.core.config.core.xml;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.core.config.core.ConfigDescription;
|
||||
import org.openhab.core.config.core.ConfigDescriptionParameter;
|
||||
import org.openhab.core.config.core.ConfigDescriptionParameterGroup;
|
||||
import org.openhab.core.config.core.ConfigDescriptionProvider;
|
||||
import org.openhab.core.test.BundleCloseable;
|
||||
import org.openhab.core.test.SyntheticBundleInstaller;
|
||||
import org.openhab.core.test.java.JavaOSGiTest;
|
||||
|
||||
/**
|
||||
* The ConfigDescriptionI18nTest is a test for loading of configuration description from XML documents.
|
||||
*
|
||||
* @author Alex Tugarev - Initial contribution; Extended tests for options and filters
|
||||
* @author Wouter Born - Migrate tests from Groovy to Java
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ConfigDescriptionI18nTest extends JavaOSGiTest {
|
||||
|
||||
private static final String TEST_BUNDLE_NAME = "acmeweather.bundle";
|
||||
|
||||
private @NonNullByDefault({}) ConfigDescriptionProvider configDescriptionProvider;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
configDescriptionProvider = getService(ConfigDescriptionProvider.class,
|
||||
serviceReference -> "core.xml.config".equals(serviceReference.getProperty("openhab.scope")));
|
||||
assertThat(configDescriptionProvider, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertConfigDescriptionsAreLocalized() throws Exception {
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
waitForAssert(() -> {
|
||||
Collection<ConfigDescription> configDescriptions = configDescriptionProvider
|
||||
.getConfigDescriptions(Locale.GERMAN);
|
||||
|
||||
ConfigDescription config = findDescription(configDescriptions, "config:Dummy");
|
||||
assertThat(config, is(notNullValue()));
|
||||
|
||||
Objects.requireNonNull(config);
|
||||
|
||||
String expected = "location.label = Ort\n" + //
|
||||
"location.description = Ort der Wetterinformation.\n" + //
|
||||
"unit.label = Einheit\n" + //
|
||||
"unit.description = Spezifiziert die Einheit der Daten. Valide Werte sind 'us' und 'metric'\n" + //
|
||||
"refresh.label = Aktualisierungsintervall\n" + //
|
||||
"refresh.description = Spezifiziert das Aktualisierungsintervall in Sekunden\n" + //
|
||||
"question.pattern = Wie ist das Wetter in [\\w]*?\n" + //
|
||||
"question.options = München, Köln\n" + //
|
||||
"group.label = Group 1 German Label\n" + //
|
||||
"group.description = Group 1 German Description";
|
||||
|
||||
assertEquals(expected, asString(config));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static String asString(ConfigDescription description) {
|
||||
ConfigDescriptionParameter location = findParameter(description, "location");
|
||||
ConfigDescriptionParameter unit = findParameter(description, "unit");
|
||||
ConfigDescriptionParameter refresh = findParameter(description, "refresh");
|
||||
ConfigDescriptionParameter question = findParameter(description, "question");
|
||||
ConfigDescriptionParameterGroup group = findParameterGroup(description, "group1");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(String.format("location.label = %s\n", location.getLabel()));
|
||||
sb.append(String.format("location.description = %s\n", location.getDescription()));
|
||||
sb.append(String.format("unit.label = %s\n", unit.getLabel()));
|
||||
sb.append(String.format("unit.description = %s\n", unit.getDescription()));
|
||||
sb.append(String.format("refresh.label = %s\n", refresh.getLabel()));
|
||||
sb.append(String.format("refresh.description = %s\n", refresh.getDescription()));
|
||||
sb.append(String.format("question.pattern = %s\n", question.getPattern()));
|
||||
sb.append(String.format("question.options = %s\n",
|
||||
question.getOptions().stream().map(o -> o.getLabel()).collect(Collectors.joining(", "))));
|
||||
sb.append(String.format("group.label = %s\n", group.getLabel()));
|
||||
sb.append(String.format("group.description = %s", group.getDescription()));
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static @Nullable ConfigDescription findDescription(Collection<ConfigDescription> descriptions, String uri) {
|
||||
return findDescription(descriptions, URI.create(uri));
|
||||
}
|
||||
|
||||
private static @Nullable ConfigDescription findDescription(Collection<ConfigDescription> descriptions, URI uri) {
|
||||
return descriptions.stream().filter(d -> uri.equals(d.getUID())).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
private static ConfigDescriptionParameter findParameter(ConfigDescription description, String parameterName) {
|
||||
return description.getParameters().stream().filter(p -> parameterName.equals(p.getName())).findFirst().get();
|
||||
}
|
||||
|
||||
private static ConfigDescriptionParameterGroup findParameterGroup(ConfigDescription description,
|
||||
String parameterGroupName) {
|
||||
return description.getParameterGroups().stream().filter(g -> parameterGroupName.equals(g.getName())).findFirst()
|
||||
.get();
|
||||
}
|
||||
}
|
||||
+279
@@ -0,0 +1,279 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.core.config.core.xml;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.core.config.core.ConfigDescription;
|
||||
import org.openhab.core.config.core.ConfigDescriptionParameter;
|
||||
import org.openhab.core.config.core.ConfigDescriptionParameter.Type;
|
||||
import org.openhab.core.config.core.ConfigDescriptionParameterGroup;
|
||||
import org.openhab.core.config.core.ConfigDescriptionRegistry;
|
||||
import org.openhab.core.test.BundleCloseable;
|
||||
import org.openhab.core.test.SyntheticBundleInstaller;
|
||||
import org.openhab.core.test.java.JavaOSGiTest;
|
||||
|
||||
/**
|
||||
* The ConfigDescriptionsTest is a test for loading of configuration description from XML documents.
|
||||
*
|
||||
* @author Alex Tugarev - Initial contribution; Extended tests for options and filters
|
||||
* @author Thomas Höfer - Added unit
|
||||
* @author Wouter Born - Migrate tests from Groovy to Java
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ConfigDescriptionsTest extends JavaOSGiTest {
|
||||
|
||||
private static final String TEST_BUNDLE_NAME = "ConfigDescriptionsTest.bundle";
|
||||
private static final String FRAGMENT_TEST_HOST_NAME = "ConfigDescriptionsFragmentTest.host";
|
||||
private static final String FRAGMENT_TEST_FRAGMENT_NAME = "ConfigDescriptionsFragmentTest.fragment";
|
||||
|
||||
private @NonNullByDefault({}) ConfigDescriptionRegistry configDescriptionRegistry;
|
||||
private @NonNullByDefault({}) BindingInstaller bindingInstaller;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
|
||||
assertThat(configDescriptionRegistry, is(notNullValue()));
|
||||
bindingInstaller = new BindingInstaller(this::waitForAssert, configDescriptionRegistry, bundleContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatConfigDescriptionsAreLoadedProperly() throws Exception {
|
||||
bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
|
||||
Collection<ConfigDescription> englishConfigDescriptions = configDescriptionRegistry
|
||||
.getConfigDescriptions(Locale.ENGLISH);
|
||||
|
||||
ConfigDescription englishDescription = Objects
|
||||
.requireNonNull(findDescription(englishConfigDescriptions, "config:dummyConfig"));
|
||||
|
||||
List<ConfigDescriptionParameter> parameters = englishDescription.getParameters();
|
||||
assertThat(parameters.size(), is(14));
|
||||
|
||||
ConfigDescriptionParameter ipParameter = findParameter(englishDescription, "ip");
|
||||
assertThat(ipParameter, is(notNullValue()));
|
||||
assertThat(ipParameter.getType(), is(Type.TEXT));
|
||||
assertThat(ipParameter.getGroupName(), is(nullValue()));
|
||||
assertThat(ipParameter.getContext(), is("network-address"));
|
||||
assertThat(ipParameter.getLabel(), is("Network Address"));
|
||||
assertThat(ipParameter.getDescription(), is("Network address of the hue bridge."));
|
||||
assertThat(ipParameter.getPattern(), is("[0-9]{3}.[0-9]{3}.[0-9]{3}.[0-9]{3}"));
|
||||
assertThat(ipParameter.isRequired(), is(true));
|
||||
assertThat(ipParameter.isMultiple(), is(false));
|
||||
assertThat(ipParameter.isReadOnly(), is(true));
|
||||
assertThat(ipParameter.getUnit(), is(nullValue()));
|
||||
assertThat(ipParameter.getUnitLabel(), is(nullValue()));
|
||||
|
||||
ConfigDescriptionParameter usernameParameter = findParameter(englishDescription, "username");
|
||||
assertThat(usernameParameter, is(notNullValue()));
|
||||
assertThat(usernameParameter.getType(), is(Type.TEXT));
|
||||
assertThat(usernameParameter.getGroupName(), is("user"));
|
||||
assertThat(usernameParameter.getContext(), is("password"));
|
||||
assertThat(usernameParameter.getLabel(), is("Username"));
|
||||
assertThat(usernameParameter.isRequired(), is(false));
|
||||
assertThat(usernameParameter.isMultiple(), is(false));
|
||||
assertThat(usernameParameter.isReadOnly(), is(false));
|
||||
assertThat(usernameParameter.getDescription(),
|
||||
is("Name of a registered hue bridge user, that allows to access the API."));
|
||||
|
||||
ConfigDescriptionParameter userPassParameter = findParameter(englishDescription, "user-pass");
|
||||
assertThat(userPassParameter, is(notNullValue()));
|
||||
assertThat(userPassParameter.getType(), is(Type.TEXT));
|
||||
assertThat(userPassParameter.getMinimum(), is(BigDecimal.valueOf(8)));
|
||||
assertThat(userPassParameter.getMaximum(), is(BigDecimal.valueOf(16)));
|
||||
assertThat(userPassParameter.isRequired(), is(true));
|
||||
assertThat(userPassParameter.isVerifyable(), is(true));
|
||||
assertThat(userPassParameter.isMultiple(), is(false));
|
||||
assertThat(userPassParameter.isReadOnly(), is(false));
|
||||
assertThat(userPassParameter.getContext(), is("password"));
|
||||
assertThat(userPassParameter.getLabel(), is("Password"));
|
||||
|
||||
ConfigDescriptionParameter colorItemParameter = findParameter(englishDescription, "color-alarming-light");
|
||||
assertThat(colorItemParameter, is(notNullValue()));
|
||||
assertThat(colorItemParameter.getType(), is(Type.TEXT));
|
||||
assertThat(colorItemParameter.isRequired(), is(false));
|
||||
assertThat(colorItemParameter.isReadOnly(), is(false));
|
||||
assertThat(colorItemParameter.getContext(), is("item"));
|
||||
assertThat(colorItemParameter.getFilterCriteria(), is(notNullValue()));
|
||||
assertThat(
|
||||
colorItemParameter.getFilterCriteria().stream().map(c -> c.toString())
|
||||
.collect(Collectors.joining(", ")),
|
||||
is("FilterCriteria [name=\"tags\", value=\"alarm, light\"], FilterCriteria [name=\"type\", value=\"color\"], FilterCriteria [name=\"binding-id\", value=\"hue\"]"));
|
||||
|
||||
ConfigDescriptionParameter listParameter1 = findParameter(englishDescription, "list1");
|
||||
assertThat(listParameter1, is(notNullValue()));
|
||||
assertThat(listParameter1.getType(), is(Type.TEXT));
|
||||
assertThat(listParameter1.isRequired(), is(false));
|
||||
assertThat(listParameter1.isMultiple(), is(true));
|
||||
assertThat(listParameter1.isReadOnly(), is(false));
|
||||
assertThat(listParameter1.getMinimum(), is(BigDecimal.valueOf(2)));
|
||||
assertThat(listParameter1.getMaximum(), is(BigDecimal.valueOf(3)));
|
||||
assertThat(listParameter1.getOptions(), is(notNullValue()));
|
||||
assertThat(listParameter1.isAdvanced(), is(false));
|
||||
assertThat(listParameter1.isVerifyable(), is(false));
|
||||
assertThat(listParameter1.getLimitToOptions(), is(true));
|
||||
assertThat(listParameter1.getMultipleLimit(), is(nullValue()));
|
||||
assertThat(listParameter1.getOptions().stream().map(o -> o.toString()).collect(joining(", ")), is(
|
||||
"ParameterOption [value=\"key1\", label=\"label1\"], ParameterOption [value=\"key2\", label=\"label2\"]"));
|
||||
|
||||
ConfigDescriptionParameter listParameter2 = findParameter(englishDescription, "list2");
|
||||
assertThat(listParameter2, is(notNullValue()));
|
||||
assertThat(listParameter2.getType(), is(Type.TEXT));
|
||||
assertThat(listParameter2.isRequired(), is(false));
|
||||
assertThat(listParameter2.isMultiple(), is(true));
|
||||
assertThat(listParameter2.isReadOnly(), is(false));
|
||||
assertThat(listParameter2.getOptions(), is(notNullValue()));
|
||||
assertThat(listParameter2.isAdvanced(), is(true));
|
||||
assertThat(listParameter2.getLimitToOptions(), is(false));
|
||||
assertThat(listParameter2.getMultipleLimit(), is(4));
|
||||
|
||||
ConfigDescriptionParameter unitParameter = findParameter(englishDescription, "unit");
|
||||
assertThat(unitParameter, is(notNullValue()));
|
||||
assertThat(unitParameter.getUnit(), is("m"));
|
||||
assertThat(unitParameter.getUnitLabel(), is(nullValue()));
|
||||
|
||||
ConfigDescriptionParameter unitLabelParameter = findParameter(englishDescription, "unit-label");
|
||||
assertThat(unitLabelParameter, is(notNullValue()));
|
||||
assertThat(unitLabelParameter.getUnit(), is(nullValue()));
|
||||
assertThat(unitLabelParameter.getUnitLabel(), is("Runs"));
|
||||
|
||||
ConfigDescriptionParameter unitOhmParameter = findParameter(englishDescription, "unit-ohm");
|
||||
assertThat(unitOhmParameter, is(notNullValue()));
|
||||
assertThat(unitOhmParameter.getUnit(), is("Ω"));
|
||||
assertThat(unitOhmParameter.getUnitLabel(), is(nullValue()));
|
||||
|
||||
ConfigDescriptionParameter unitAccelerationParameter = findParameter(englishDescription,
|
||||
"unit-acceleration");
|
||||
assertThat(unitAccelerationParameter, is(notNullValue()));
|
||||
assertThat(unitAccelerationParameter.getUnit(), is("m/s2"));
|
||||
assertThat(unitAccelerationParameter.getUnitLabel(), is("m/s\u00B2"));
|
||||
|
||||
ConfigDescriptionParameter unitCelcius = findParameter(englishDescription, "unit-celcius");
|
||||
assertThat(unitCelcius, is(notNullValue()));
|
||||
assertThat(unitCelcius.getUnit(), is("Cel"));
|
||||
assertThat(unitCelcius.getUnitLabel(), is("°C"));
|
||||
|
||||
ConfigDescriptionParameter unitSeconds = findParameter(englishDescription, "unit-seconds");
|
||||
assertThat(unitSeconds, is(notNullValue()));
|
||||
assertThat(unitSeconds.getUnit(), is("s"));
|
||||
assertThat(unitSeconds.getUnitLabel(), is("seconds"));
|
||||
|
||||
ConfigDescriptionParameter unitMovements = findParameter(englishDescription, "unit-movements");
|
||||
assertThat(unitMovements, is(notNullValue()));
|
||||
assertThat(unitMovements.getUnit(), is(nullValue()));
|
||||
assertThat(unitMovements.getUnitLabel(), is("Movements"));
|
||||
|
||||
ConfigDescriptionParameter unitKph = findParameter(englishDescription, "unit-kph");
|
||||
assertThat(unitKph, is(notNullValue()));
|
||||
assertThat(unitKph.getUnit(), is("kph"));
|
||||
assertThat(unitKph.getUnitLabel(), is("km/h"));
|
||||
|
||||
assertThat(englishDescription.getParameterGroups().size(), is(2));
|
||||
|
||||
ConfigDescriptionParameterGroup group1 = findParameterGroup(englishDescription, "group1");
|
||||
assertThat(group1, is(notNullValue()));
|
||||
assertThat(group1.getLabel(), is("Group 1"));
|
||||
assertThat(group1.getDescription(), is("Description Group 1"));
|
||||
assertThat(group1.isAdvanced(), is(false));
|
||||
assertThat(group1.getContext(), is("Context-Group1"));
|
||||
|
||||
ConfigDescriptionParameterGroup group2 = findParameterGroup(englishDescription, "group2");
|
||||
assertThat(group2, is(notNullValue()));
|
||||
assertThat(group2.getLabel(), is("Group 2"));
|
||||
assertThat(group2.getDescription(), is("Description Group 2"));
|
||||
assertThat(group2.isAdvanced(), is(true));
|
||||
assertThat(group2.getContext(), is("Context-Group2"));
|
||||
|
||||
ConfigDescription germanDescription = Objects.requireNonNull(findDescription(
|
||||
configDescriptionRegistry.getConfigDescriptions(Locale.GERMAN), "config:dummyConfig"));
|
||||
|
||||
unitSeconds = findParameter(germanDescription, "unit-seconds");
|
||||
assertThat(unitSeconds, is(notNullValue()));
|
||||
assertThat(unitSeconds.getUnit(), is("s"));
|
||||
assertThat(unitSeconds.getUnitLabel(), is("Sekunden"));
|
||||
|
||||
unitMovements = findParameter(germanDescription, "unit-movements");
|
||||
assertThat(unitMovements, is(notNullValue()));
|
||||
assertThat(unitMovements.getUnit(), is(nullValue()));
|
||||
assertThat(unitMovements.getUnitLabel(), is("Bewegungen"));
|
||||
|
||||
unitKph = findParameter(germanDescription, "unit-kph");
|
||||
assertThat(unitKph, is(notNullValue()));
|
||||
assertThat(unitKph.getUnit(), is("kph"));
|
||||
assertThat(unitKph.getUnitLabel(), is("km/h"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatConfigDescriptionsOfFragmentHostAreLoadedProperly() throws Exception {
|
||||
bindingInstaller.exec(FRAGMENT_TEST_FRAGMENT_NAME, () -> {
|
||||
try {
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, FRAGMENT_TEST_HOST_NAME))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
Collection<ConfigDescription> configDescriptions = configDescriptionRegistry
|
||||
.getConfigDescriptions();
|
||||
|
||||
ConfigDescription description = Objects
|
||||
.requireNonNull(findDescription(configDescriptions, "config:fragmentConfig"));
|
||||
|
||||
List<ConfigDescriptionParameter> parameters = description.getParameters();
|
||||
assertThat(parameters.size(), is(1));
|
||||
|
||||
ConfigDescriptionParameter usernameParameter = findParameter(description, "testParam");
|
||||
assertThat(usernameParameter, is(notNullValue()));
|
||||
assertThat(usernameParameter.getType(), is(Type.TEXT));
|
||||
assertThat(usernameParameter.getLabel(), is("Test"));
|
||||
assertThat(usernameParameter.isRequired(), is(false));
|
||||
assertThat(usernameParameter.isMultiple(), is(false));
|
||||
assertThat(usernameParameter.isReadOnly(), is(false));
|
||||
assertThat(usernameParameter.getDescription(), is("Test Parameter."));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// do nothing: handle exception
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static @Nullable ConfigDescription findDescription(Collection<ConfigDescription> descriptions, String uri) {
|
||||
return findDescription(descriptions, URI.create(uri));
|
||||
}
|
||||
|
||||
private static ConfigDescription findDescription(Collection<ConfigDescription> descriptions, URI uri) {
|
||||
return descriptions.stream().filter(d -> uri.equals(d.getUID())).findFirst().get();
|
||||
}
|
||||
|
||||
private static ConfigDescriptionParameter findParameter(ConfigDescription description, String parameterName) {
|
||||
return description.getParameters().stream().filter(p -> parameterName.equals(p.getName())).findFirst().get();
|
||||
}
|
||||
|
||||
private static ConfigDescriptionParameterGroup findParameterGroup(ConfigDescription description,
|
||||
String parameterGroupName) {
|
||||
return description.getParameterGroups().stream().filter(g -> parameterGroupName.equals(g.getName())).findFirst()
|
||||
.get();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config-description:config-descriptions
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:config-description="https://openhab.org/schemas/config-description/v1.0.0"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0 https://openhab.org/schemas/config-description-1.0.0.xsd">
|
||||
|
||||
<!-- test dummy -->
|
||||
<config-description uri="config:fragmentConfig">
|
||||
|
||||
<parameter name="testParam" type="text">
|
||||
<label>Test</label>
|
||||
<description>Test Parameter.</description>
|
||||
</parameter>
|
||||
|
||||
|
||||
</config-description>
|
||||
|
||||
</config-description:config-descriptions>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<thing:thing-descriptions bindingId="hue" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
|
||||
|
||||
<thing-type id="MyThingType">
|
||||
<label>My Thing Type</label>
|
||||
<description>My Thing Type</description>
|
||||
|
||||
<config-description>
|
||||
<parameter name="myID" type="text">
|
||||
<label>My ID</label>
|
||||
<description>My ID.</description>
|
||||
</parameter>
|
||||
</config-description>
|
||||
</thing-type>
|
||||
</thing:thing-descriptions>
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config-description:config-descriptions
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:config-description="https://openhab.org/schemas/config-description/v1.0.0"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0 https://openhab.org/schemas/config-description-1.0.0.xsd">
|
||||
|
||||
<!-- test dummy -->
|
||||
<config-description uri="config:dummyConfig">
|
||||
<parameter-group name="group1">
|
||||
<context>Context-Group1</context>
|
||||
<label>Group 1</label>
|
||||
<description>Description Group 1</description>
|
||||
<advanced>false</advanced>
|
||||
</parameter-group>
|
||||
|
||||
<parameter-group name="group2">
|
||||
<context>Context-Group2</context>
|
||||
<label>Group 2</label>
|
||||
<description>Description Group 2</description>
|
||||
<advanced>true</advanced>
|
||||
</parameter-group>
|
||||
|
||||
<parameter name="ip" type="text" pattern="[0-9]{3}.[0-9]{3}.[0-9]{3}.[0-9]{3}" required="true"
|
||||
readOnly="true">
|
||||
<multipleLimit>4</multipleLimit>
|
||||
<context>network-address</context>
|
||||
<label>Network Address</label>
|
||||
<description>Network address of the hue bridge.</description>
|
||||
<required>true</required><!-- deprecated -->
|
||||
<limitToOptions>true</limitToOptions>
|
||||
</parameter>
|
||||
|
||||
<parameter name="username" type="text" groupName="user">
|
||||
<context>password</context>
|
||||
<label>Username</label>
|
||||
<description>Name of a registered hue bridge user, that allows to access the API.
|
||||
</description>
|
||||
</parameter>
|
||||
|
||||
<!-- password with min 8, max 16 characters -->
|
||||
<parameter name="user-pass" type="text" groupName="user" min="8" max="16" required="true">
|
||||
<context>password</context>
|
||||
<label>Password</label>
|
||||
<required>true</required><!-- deprecated -->
|
||||
<verify>true</verify>
|
||||
</parameter>
|
||||
|
||||
<!-- a static selection list allowing multiple selections with min 2 max 3 items -->
|
||||
<parameter name="list1" type="text" multiple="true" min="2" max="3">
|
||||
<options>
|
||||
<option value="key1">label1</option>
|
||||
<option value="key2">label2</option>
|
||||
</options>
|
||||
</parameter>
|
||||
|
||||
<parameter name="list2" type="text" multiple="true" min="2" max="3">
|
||||
<options>
|
||||
<option value="key1">label1</option>
|
||||
<option value="key2">label2</option>
|
||||
</options>
|
||||
<advanced>true</advanced>
|
||||
<multipleLimit>4</multipleLimit>
|
||||
<limitToOptions>false</limitToOptions>
|
||||
</parameter>
|
||||
|
||||
<!-- a selection list of color items that have the tags "alarm" and "light" -->
|
||||
<parameter name="color-alarming-light" type="text" multiple="true">
|
||||
<context>item</context>
|
||||
<filter>
|
||||
<criteria name="tags">alarm, light</criteria>
|
||||
<criteria name="type">color</criteria>
|
||||
<criteria name="binding-id">hue</criteria>
|
||||
</filter>
|
||||
</parameter>
|
||||
|
||||
<parameter name="unit" type="integer" unit="m"/>
|
||||
|
||||
<parameter name="unit-label" type="decimal">
|
||||
<unitLabel>Runs</unitLabel>
|
||||
</parameter>
|
||||
|
||||
<parameter name="unit-ohm" type="decimal" unit="Ω"/>
|
||||
|
||||
<parameter name="unit-acceleration" type="decimal" unit="m/s2"/>
|
||||
|
||||
<parameter name="unit-celcius" type="decimal" unit="Cel"/>
|
||||
|
||||
<parameter name="unit-seconds" type="decimal" unit="s"/>
|
||||
|
||||
<parameter name="unit-kph" type="decimal" unit="kph"/>
|
||||
|
||||
<parameter name="unit-movements" type="decimal">
|
||||
<unitLabel>@text/thing-type.config.dummyConfig.unit-movement.unitLabel</unitLabel>
|
||||
</parameter>
|
||||
|
||||
</config-description>
|
||||
|
||||
</config-description:config-descriptions>
|
||||
+1
@@ -0,0 +1 @@
|
||||
thing-type.config.dummyConfig.unit-movement.unitLabel=Movements
|
||||
+1
@@ -0,0 +1 @@
|
||||
thing-type.config.dummyConfig.unit-movement.unitLabel=Bewegungen
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config-description:config-descriptions
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:config-description="https://openhab.org/schemas/config-description/v1.0.0"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0 https://openhab.org/schemas/config-description-1.0.0.xsd">
|
||||
|
||||
<!-- test dummy -->
|
||||
<config-description uri="config:Dummy">
|
||||
<parameter-group name="group1">
|
||||
<context>Context-Group1</context>
|
||||
<label>Group 1</label>
|
||||
<description>Description Group 1</description>
|
||||
<advanced>false</advanced>
|
||||
</parameter-group>
|
||||
|
||||
<parameter name="location" type="text" required="true">
|
||||
<label>Location</label>
|
||||
<description>Location for the weather information. Syntax is WOEID, see https://en.wikipedia.org/wiki/WOEID.</description>
|
||||
</parameter>
|
||||
<parameter name="unit" type="text">
|
||||
<label>Unit</label>
|
||||
<description>Specifies the unit of the data. Valid values are "us" or "metric".</description>
|
||||
<default>metric</default>
|
||||
</parameter>
|
||||
<parameter name="refresh" type="integer">
|
||||
<label>Refresh interval</label>
|
||||
<description>Specifies the refresh interval in seconds.</description>
|
||||
<default>60</default>
|
||||
</parameter>
|
||||
<parameter name="question" type="text" pattern="How is the weather in [\\w]*?">
|
||||
<options>
|
||||
<option value="676757">Munich</option>
|
||||
<option value="667931">Cologne</option>
|
||||
</options>
|
||||
</parameter>
|
||||
</config-description>
|
||||
|
||||
</config-description:config-descriptions>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
config.config.Dummy.location.label = Ort
|
||||
config.config.Dummy.location.description = Ort der Wetterinformation.
|
||||
config.config.Dummy.question.pattern = Wie ist das Wetter in [\\w]*?
|
||||
config.config.Dummy.question.option.676757 = München
|
||||
config.config.Dummy.question.option.667931 = Köln
|
||||
config.config.Dummy.unit.label = Einheit
|
||||
config.config.Dummy.unit.description = Spezifiziert die Einheit der Daten. Valide Werte sind 'us' und 'metric'
|
||||
config.config.Dummy.refresh.label = Aktualisierungsintervall
|
||||
config.config.Dummy.refresh.description = Spezifiziert das Aktualisierungsintervall in Sekunden
|
||||
|
||||
config.config.Dummy.group.group1.label = Group 1 German Label
|
||||
config.config.Dummy.group.group1.description = Group 1 German Description
|
||||
Reference in New Issue
Block a user