Enable Config XML Tests (#971)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2019-08-17 22:27:53 +02:00 committed by Kai Kreuzer
parent 2198eea37f
commit 11b1334ca7
15 changed files with 188 additions and 121 deletions

View File

@ -6,6 +6,13 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
@ -21,12 +28,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -5,13 +5,15 @@ Fragment-Host: org.openhab.core.config.xml
-runrequires: bnd.identity;id='org.openhab.core.config.xml.tests'
# We would like to use the "volatile" storage only
-runblacklist: \
bnd.identity;id='org.openhab.core.storage.json',\
bnd.identity;id='org.openhab.core.storage.mapdb'
#
# done
#
-runbundles: \
ch.qos.logback.classic;version='[1.2.0,1.2.1)',\
ch.qos.logback.core;version='[1.2.0,1.2.1)',\
com.google.gson;version='[2.7.0,2.7.1)',\
javax.measure.unit-api;version='[1.0.0,1.0.1)',\
org.apache.commons.io;version='[2.2.0,2.2.1)',\
org.apache.commons.lang;version='[2.6.0,2.6.1)',\
@ -25,9 +27,6 @@ Fragment-Host: org.openhab.core.config.xml
org.eclipse.jetty.servlet;version='[9.4.11,9.4.12)',\
org.eclipse.jetty.util;version='[9.4.11,9.4.12)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
slf4j.api;version='[1.7.21,1.7.22)',\
tec.uom.lib.uom-lib-common;version='[1.0.2,1.0.3)',\
tec.uom.se;version='[1.0.8,1.0.9)',\
osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\
osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\
org.openhab.core;version='[2.5.0,2.5.1)',\
@ -35,4 +34,14 @@ Fragment-Host: org.openhab.core.config.xml
org.apache.servicemix.bundles.xstream;version='[1.4.7,1.4.8)',\
org.openhab.core.config.xml;version='[2.5.0,2.5.1)',\
org.openhab.core.config.xml.tests;version='[2.5.0,2.5.1)',\
org.openhab.core.test;version='[2.5.0,2.5.1)'
org.openhab.core.test;version='[2.5.0,2.5.1)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
com.google.gson;version='[2.8.2,2.8.3)',\
org.apache.servicemix.specs.activation-api-1.1;version='[2.9.0,2.9.1)',\
org.apache.servicemix.specs.jaxb-api-2.2;version='[2.9.0,2.9.1)',\
org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
tec.uom.se;version='[1.0.10,1.0.11)',\
org.apache.servicemix.bundles.jaxb-impl;version='[2.2.11,2.2.12)'

View File

@ -10,6 +10,6 @@
<artifactId>org.openhab.core.config.xml.tests</artifactId>
<name>openHAB Core :: Integration Tests :: Config XML Tests</name>
<name>openHAB Core :: Integration Tests :: Configuration XML Tests</name>
</project>

View File

@ -0,0 +1,61 @@
/**
* Copyright (c) 2010-2019 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.eclipse.smarthome.config.xml.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import java.util.function.Consumer;
import org.eclipse.smarthome.config.core.ConfigDescriptionRegistry;
import org.eclipse.smarthome.test.BundleCloseable;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.osgi.framework.BundleContext;
/**
* @author Christoph Weitkamp - Initial contribution
*/
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)));
}
}

View File

@ -24,14 +24,12 @@ import org.eclipse.smarthome.config.core.ConfigDescription;
import org.eclipse.smarthome.config.core.ConfigDescriptionParameter;
import org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup;
import org.eclipse.smarthome.config.core.ConfigDescriptionRegistry;
import org.eclipse.smarthome.test.BundleCloseable;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.Before;
import org.junit.Test;
/**
* The ConfigDescriptionsTest is a test for loading of configuration description from XML documents.
* 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
@ -41,43 +39,37 @@ public class ConfigDescriptionI18nTest extends JavaOSGiTest {
private static final String TEST_BUNDLE_NAME = "yahooweather.bundle";
private ConfigDescriptionRegistry configDescriptionRegistry;
private BindingInstaller bindingInstaller;
@Before
public void setUp() {
configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
assertThat(configDescriptionRegistry, is(notNullValue()));
bindingInstaller = new BindingInstaller(this::waitForAssert, configDescriptionRegistry, bundleContext);
}
@Test
public void assertConfigDescriptionsAreLocalized() throws Exception {
int initialNumberOfConfigDescriptions = configDescriptionRegistry.getConfigDescriptions().size();
// install test bundle
try (BundleCloseable bundle = new BundleCloseable(
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
assertThat(bundle, is(notNullValue()));
bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
Collection<ConfigDescription> configDescriptions = configDescriptionRegistry
.getConfigDescriptions(Locale.GERMAN);
assertThat(configDescriptions.size(), is(initialNumberOfConfigDescriptions + 1));
ConfigDescription config = new LinkedList<>(configDescriptions).getFirst();
assertThat(config, is(notNullValue()));
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";
"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) {

View File

@ -18,6 +18,7 @@ import static org.junit.Assert.assertThat;
import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@ -48,28 +49,22 @@ public class ConfigDescriptionsTest extends JavaOSGiTest {
private static final String FRAGMENT_TEST_FRAGMENT_NAME = "ConfigDescriptionsFragmentTest.fragment";
private ConfigDescriptionRegistry configDescriptionRegistry;
private BindingInstaller bindingInstaller;
@Before
public void setUp() {
configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
assertThat(configDescriptionRegistry, is(notNullValue()));
bindingInstaller = new BindingInstaller(this::waitForAssert, configDescriptionRegistry, bundleContext);
}
@Test
public void assertThatConfigDescriptionsAreLoadedProperly() throws Exception {
int initialNumberOfConfigDescriptions = configDescriptionRegistry.getConfigDescriptions().size();
// install test bundle
try (BundleCloseable bundle = new BundleCloseable(
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
assertThat(bundle, is(notNullValue()));
bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
Collection<ConfigDescription> englishConfigDescriptions = configDescriptionRegistry
.getConfigDescriptions(Locale.ENGLISH);
assertThat(englishConfigDescriptions.size(), is(initialNumberOfConfigDescriptions + 1));
ConfigDescription englishDescription = findDescription(englishConfigDescriptions,
new URI("config:dummyConfig"));
ConfigDescription englishDescription = findDescription(englishConfigDescriptions, "config:dummyConfig");
assertThat(englishDescription, is(notNullValue()));
List<ConfigDescriptionParameter> parameters = englishDescription.getParameters();
@ -210,7 +205,8 @@ public class ConfigDescriptionsTest extends JavaOSGiTest {
assertThat(group2.getContext(), is("Context-Group2"));
ConfigDescription germanDescription = findDescription(
configDescriptionRegistry.getConfigDescriptions(Locale.GERMAN), new URI("config:dummyConfig"));
configDescriptionRegistry.getConfigDescriptions(Locale.GERMAN), "config:dummyConfig");
assertThat(germanDescription, is(notNullValue()));
unitSeconds = findParameter(germanDescription, "unit-seconds");
assertThat(unitSeconds, is(notNullValue()));
@ -226,38 +222,46 @@ public class ConfigDescriptionsTest extends JavaOSGiTest {
assertThat(unitKph, is(notNullValue()));
assertThat(unitKph.getUnit(), is("kph"));
assertThat(unitKph.getUnitLabel(), is("km/h"));
}
});
}
@Test
public void assertThatConfigDescriptionsOfFragmentHostAreLoadedProperly() throws Exception {
int initialNumberOfConfigDescriptions = configDescriptionRegistry.getConfigDescriptions().size();
bindingInstaller.exec(FRAGMENT_TEST_FRAGMENT_NAME, () -> {
try {
try (BundleCloseable bundle = new BundleCloseable(
SyntheticBundleInstaller.install(bundleContext, FRAGMENT_TEST_HOST_NAME))) {
assertThat(bundle, is(notNullValue()));
// install test bundle
try (BundleCloseable fragment = new BundleCloseable(
SyntheticBundleInstaller.installFragment(bundleContext, FRAGMENT_TEST_FRAGMENT_NAME))) {
try (BundleCloseable bundle = new BundleCloseable(
SyntheticBundleInstaller.install(bundleContext, FRAGMENT_TEST_HOST_NAME))) {
assertThat(bundle, is(notNullValue()));
Collection<ConfigDescription> configDescriptions = configDescriptionRegistry
.getConfigDescriptions();
Collection<ConfigDescription> configDescriptions = configDescriptionRegistry.getConfigDescriptions();
assertThat(configDescriptions.size(), is(initialNumberOfConfigDescriptions + 1));
ConfigDescription description = findDescription(configDescriptions, "config:fragmentConfig");
assertThat(description, is(notNullValue()));
ConfigDescription description = findDescription(configDescriptions, new URI("config:fragmentConfig"));
assertThat(description, is(notNullValue()));
List<ConfigDescriptionParameter> parameters = description.getParameters();
assertThat(parameters.size(), is(1));
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."));
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 ConfigDescription findDescription(Collection<ConfigDescription> descriptions, String uri) {
try {
return findDescription(descriptions, new URI(uri));
} catch (URISyntaxException e) {
return null;
}
}

View File

@ -19,9 +19,10 @@
<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>
<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>
@ -43,54 +44,54 @@
<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 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-label" type="decimal">
<unitLabel>Runs</unitLabel>
</parameter>
<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>
<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>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<config-description:config-descriptions
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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 ../../../../../../../../org.eclipse.smarthome.config.xml/org.eclipse.smarthome.config-description.xsd ">
xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0 https://openhab.org/schemas/config-description/v1.0.0">
<!-- test dummy -->
<config-description uri="config:Dummy">

View File

@ -32,7 +32,7 @@
<module>org.openhab.core.config.discovery.tests</module>
<!-- <module>org.openhab.core.config.discovery.usbserial.tests</module> -->
<!-- <module>org.openhab.core.config.dispatch.tests</module> -->
<!-- <module>org.openhab.core.config.xml.tests</module> -->
<module>org.openhab.core.config.xml.tests</module>
<module>org.openhab.core.io.http.tests</module>
<module>org.openhab.core.io.net.tests</module>
<!-- <module>org.openhab.core.io.rest.tests</module> -->