mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
migrate tests for binding.xml (#619)
Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
This commit is contained in:
committed by
Kai Kreuzer
parent
2d92336d72
commit
4be3a0edd1
@@ -9,8 +9,6 @@ Fragment-Host: org.openhab.core.binding.xml
|
||||
# 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)',\
|
||||
@@ -26,16 +24,17 @@ Fragment-Host: org.openhab.core.binding.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)',\
|
||||
org.openhab.core.config.core;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.storage.json;version='[2.5.0,2.5.1)',\
|
||||
org.apache.servicemix.bundles.xstream;version='[1.4.7,1.4.8)',\
|
||||
org.openhab.core.binding.xml;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.binding.xml.tests;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.config.xml;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)',\
|
||||
slf4j.api;version='[1.7.25,1.7.26)'
|
||||
|
||||
+10
-38
@@ -23,8 +23,6 @@ import java.util.Set;
|
||||
import org.eclipse.smarthome.core.binding.BindingInfo;
|
||||
import org.eclipse.smarthome.core.binding.BindingInfoRegistry;
|
||||
import org.eclipse.smarthome.core.i18n.LocaleProvider;
|
||||
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;
|
||||
@@ -36,71 +34,52 @@ public class BindingInfoI18nTest extends JavaOSGiTest {
|
||||
private static final String TEST_BUNDLE_NAME = "yahooweather.bundle";
|
||||
|
||||
private BindingInfoRegistry bindingInfoRegistry;
|
||||
private BindingInstaller bindingInstaller;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
bindingInfoRegistry = getService(BindingInfoRegistry.class);
|
||||
assertThat(bindingInfoRegistry, is(notNullValue()));
|
||||
bindingInstaller = new BindingInstaller(this::waitForAssert, bindingInfoRegistry, bundleContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertBindingInfosWereLocalizedInGerman() throws Exception {
|
||||
int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();
|
||||
|
||||
// install test bundle
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
|
||||
Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(Locale.GERMAN);
|
||||
assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
|
||||
BindingInfo bindingInfo = bindingInfos.iterator().next();
|
||||
|
||||
assertThat(bindingInfo, is(notNullValue()));
|
||||
assertThat(bindingInfo.getName(), is("Yahoo Wetter Binding"));
|
||||
assertThat(bindingInfo.getDescription(), is(
|
||||
"Das Yahoo Wetter Binding stellt verschiedene Wetterdaten wie die Temperatur, die Luftfeuchtigkeit und den Luftdruck für konfigurierbare Orte vom yahoo Wetterdienst bereit"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertBindingInfosWereLocalizedInDutch() throws Exception {
|
||||
int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();
|
||||
|
||||
// install test bundle
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
|
||||
Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(new Locale("nl"));
|
||||
assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
|
||||
BindingInfo bindingInfo = bindingInfos.iterator().next();
|
||||
|
||||
assertThat(bindingInfo, is(notNullValue()));
|
||||
assertThat(bindingInfo.getName(), is("Yahoo Weer Binding"));
|
||||
assertThat(bindingInfo.getDescription(), is(
|
||||
"De Yahoo Weer Binding biedt verschillende meteorologische gegevens zoals temperatuur, vochtigheid en luchtdruk voor configureerbare locaties uit yahoo weerdienst klaar"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertUsingOriginalBindingInfosIfProvidedLocaleIsNotSupported() throws Exception {
|
||||
int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();
|
||||
|
||||
// install test bundle
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
|
||||
Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(Locale.FRENCH);
|
||||
assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
|
||||
BindingInfo bindingInfo = bindingInfos.iterator().next();
|
||||
|
||||
assertThat(bindingInfo, is(notNullValue()));
|
||||
assertThat(bindingInfo.getName(), is("YahooWeather Binding"));
|
||||
assertThat(bindingInfo.getDescription(), is(
|
||||
"The Yahoo Weather Binding requests the Yahoo Weather Service to show the current temperature, humidity and pressure."));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,22 +96,15 @@ public class BindingInfoI18nTest extends JavaOSGiTest {
|
||||
LocaleProvider localeProvider = getService(LocaleProvider.class);
|
||||
waitForAssert(() -> assertThat(localeProvider.getLocale().toString(), is("de")));
|
||||
|
||||
int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();
|
||||
|
||||
// install test bundle
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
|
||||
Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(/* use default locale */ null);
|
||||
assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
|
||||
BindingInfo bindingInfo = bindingInfos.iterator().next();
|
||||
|
||||
assertThat(bindingInfo, is(notNullValue()));
|
||||
assertThat(bindingInfo.getName(), is("Yahoo Wetter Binding"));
|
||||
assertThat(bindingInfo.getDescription(), is(
|
||||
"Das Yahoo Wetter Binding stellt verschiedene Wetterdaten wie die Temperatur, die Luftfeuchtigkeit und den Luftdruck für konfigurierbare Orte vom yahoo Wetterdienst bereit"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-56
@@ -25,8 +25,6 @@ import org.eclipse.smarthome.config.core.ConfigDescriptionParameter;
|
||||
import org.eclipse.smarthome.config.core.ConfigDescriptionRegistry;
|
||||
import org.eclipse.smarthome.core.binding.BindingInfo;
|
||||
import org.eclipse.smarthome.core.binding.BindingInfoRegistry;
|
||||
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;
|
||||
@@ -42,6 +40,7 @@ public class BindingInfoTest extends JavaOSGiTest {
|
||||
|
||||
private BindingInfoRegistry bindingInfoRegistry;
|
||||
private ConfigDescriptionRegistry configDescriptionRegistry;
|
||||
private BindingInstaller bindingInstaller;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -49,19 +48,13 @@ public class BindingInfoTest extends JavaOSGiTest {
|
||||
assertThat(bindingInfoRegistry, is(notNullValue()));
|
||||
configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
|
||||
assertThat(configDescriptionRegistry, is(notNullValue()));
|
||||
bindingInstaller = new BindingInstaller(this::waitForAssert, bindingInfoRegistry, bundleContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatBindingInfoIsReadProperly() throws Exception {
|
||||
int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();
|
||||
|
||||
// install test bundle
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
|
||||
Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos();
|
||||
assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
|
||||
BindingInfo bindingInfo = bindingInfos.iterator().next();
|
||||
assertThat(bindingInfo.getUID(), is("hue"));
|
||||
assertThat(bindingInfo.getConfigDescriptionURI(), is(URI.create("binding:hue")));
|
||||
@@ -69,20 +62,13 @@ public class BindingInfoTest extends JavaOSGiTest {
|
||||
is("The hue Binding integrates the Philips hue system. It allows to control hue lights."));
|
||||
assertThat(bindingInfo.getName(), is("hue Binding"));
|
||||
assertThat(bindingInfo.getAuthor(), is("Deutsche Telekom AG"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatBindingInfoWithoutAuthorIsReadProperly() throws Exception {
|
||||
int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();
|
||||
|
||||
// install test bundle
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME2))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
bindingInstaller.exec(TEST_BUNDLE_NAME2, () -> {
|
||||
Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos();
|
||||
assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
|
||||
BindingInfo bindingInfo = bindingInfos.iterator().next();
|
||||
assertThat(bindingInfo.getUID(), is("hue"));
|
||||
assertThat(bindingInfo.getConfigDescriptionURI(), is(URI.create("binding:hue")));
|
||||
@@ -90,47 +76,13 @@ public class BindingInfoTest extends JavaOSGiTest {
|
||||
is("The hue Binding integrates the Philips hue system. It allows to control hue lights."));
|
||||
assertThat(bindingInfo.getName(), is("hue Binding"));
|
||||
assertThat(bindingInfo.getAuthor(), is((String) null));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatBindingInfoIsRemovedAfterTheBundleWasUninstalled() throws Exception {
|
||||
int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();
|
||||
|
||||
Set<BindingInfo> bindingInfos;
|
||||
BindingInfo bindingInfo;
|
||||
|
||||
// install test bundle
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
bindingInfos = bindingInfoRegistry.getBindingInfos();
|
||||
assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
|
||||
bindingInfo = bindingInfos.iterator().next();
|
||||
}
|
||||
|
||||
bindingInfos = bindingInfoRegistry.getBindingInfos();
|
||||
assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos));
|
||||
|
||||
if (initialNumberOfBindingInfos > 0) {
|
||||
for (BindingInfo bindingInfo_ : bindingInfos) {
|
||||
assertThat(bindingInfo_.getUID(), is(not(bindingInfo.getUID())));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatConfigWithOptionsAndFilterAreProperlyRead() throws Exception {
|
||||
int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();
|
||||
|
||||
// install test bundle
|
||||
try (BundleCloseable bundle = new BundleCloseable(
|
||||
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
|
||||
assertThat(bundle, is(notNullValue()));
|
||||
|
||||
bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
|
||||
Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos();
|
||||
assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
|
||||
BindingInfo bindingInfo = bindingInfos.iterator().next();
|
||||
|
||||
URI configDescriptionURI = bindingInfo.getConfigDescriptionURI();
|
||||
@@ -151,6 +103,6 @@ public class BindingInfoTest extends JavaOSGiTest {
|
||||
lightParameter.getFilterCriteria().stream().map(p -> p.toString())
|
||||
.collect(Collectors.joining(", ")),
|
||||
is("FilterCriteria [name=\"tags\", value=\"alarm, light\"], FilterCriteria [name=\"type\", value=\"color\"], FilterCriteria [name=\"binding-id\", value=\"hue\"]"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (c) 2014,2019 Contributors to the Eclipse Foundation
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*
|
||||
* 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.core.binding.xml.test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.eclipse.smarthome.core.binding.BindingInfoRegistry;
|
||||
import org.eclipse.smarthome.test.BundleCloseable;
|
||||
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* @author Markus Rathgeb - Initial Contribution and API
|
||||
*/
|
||||
public class BindingInstaller {
|
||||
|
||||
private final Consumer<Runnable> waitForAssert;
|
||||
private final BindingInfoRegistry bindingInfoRegistry;
|
||||
private final BundleContext bc;
|
||||
|
||||
public BindingInstaller(Consumer<Runnable> waitForAssert, BindingInfoRegistry bindingInfoRegistry,
|
||||
BundleContext bc) {
|
||||
this.waitForAssert = waitForAssert;
|
||||
this.bindingInfoRegistry = bindingInfoRegistry;
|
||||
this.bc = bc;
|
||||
}
|
||||
|
||||
public void exec(final String bundleName, final Runnable func) throws Exception {
|
||||
// Save the number of currently installed bundles.
|
||||
final int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().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(bindingInfoRegistry.getBindingInfos().size(),
|
||||
is(initialNumberOfBindingInfos + 1)));
|
||||
|
||||
func.run();
|
||||
}
|
||||
|
||||
// Wait for correctly uninstalled bundle.
|
||||
waitForAssert.accept(
|
||||
() -> assertThat(bindingInfoRegistry.getBindingInfos().size(), is(initialNumberOfBindingInfos)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
<!-- <module>org.openhab.core.automation.module.script.defaultscope.tests</module> -->
|
||||
<!-- <module>org.openhab.core.automation.module.script.tests</module> -->
|
||||
<!-- <module>org.openhab.core.automation.integration.tests</module> -->
|
||||
<!-- <module>org.openhab.core.binding.xml.tests</module> -->
|
||||
<module>org.openhab.core.binding.xml.tests</module>
|
||||
<module>org.openhab.core.compat1x.tests</module>
|
||||
<module>org.openhab.core.config.core.tests</module>
|
||||
<module>org.openhab.core.config.discovery.mdns.tests</module>
|
||||
|
||||
Reference in New Issue
Block a user