diff --git a/itests/org.openhab.core.binding.xml.tests/itest.bndrun b/itests/org.openhab.core.binding.xml.tests/itest.bndrun index cd8ab2986..9bc0cd7f3 100644 --- a/itests/org.openhab.core.binding.xml.tests/itest.bndrun +++ b/itests/org.openhab.core.binding.xml.tests/itest.bndrun @@ -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)' diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInfoI18nTest.java b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInfoI18nTest.java index 1f022ec34..d16c7c67c 100644 --- a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInfoI18nTest.java +++ b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInfoI18nTest.java @@ -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 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 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 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 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")); - } + }); } } diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInfoTest.java b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInfoTest.java index f84a449af..2689d13b0 100644 --- a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInfoTest.java +++ b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInfoTest.java @@ -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 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 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 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 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\"]")); - } + }); } } diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInstaller.java b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInstaller.java new file mode 100644 index 000000000..e94c77e71 --- /dev/null +++ b/itests/org.openhab.core.binding.xml.tests/src/main/java/org/eclipse/smarthome/core/binding/xml/test/BindingInstaller.java @@ -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 waitForAssert; + private final BindingInfoRegistry bindingInfoRegistry; + private final BundleContext bc; + + public BindingInstaller(Consumer 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))); + + } + +} diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTest.bundle/src/main/resources/ESH-INF/binding/binding.xml b/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTest.bundle/ESH-INF/binding/binding.xml similarity index 100% rename from itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTest.bundle/src/main/resources/ESH-INF/binding/binding.xml rename to itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTest.bundle/ESH-INF/binding/binding.xml diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTest.bundle/src/main/resources/ESH-INF/thing/thing-types.xml b/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTest.bundle/ESH-INF/thing/thing-types.xml similarity index 100% rename from itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTest.bundle/src/main/resources/ESH-INF/thing/thing-types.xml rename to itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTest.bundle/ESH-INF/thing/thing-types.xml diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTestNoAuthor.bundle/src/main/resources/ESH-INF/binding/binding.xml b/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTestNoAuthor.bundle/ESH-INF/binding/binding.xml similarity index 100% rename from itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTestNoAuthor.bundle/src/main/resources/ESH-INF/binding/binding.xml rename to itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTestNoAuthor.bundle/ESH-INF/binding/binding.xml diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTestNoAuthor.bundle/src/main/resources/ESH-INF/thing/thing-types.xml b/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTestNoAuthor.bundle/ESH-INF/thing/thing-types.xml similarity index 100% rename from itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTestNoAuthor.bundle/src/main/resources/ESH-INF/thing/thing-types.xml rename to itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/BundleInfoTestNoAuthor.bundle/ESH-INF/thing/thing-types.xml diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/src/main/resources/ESH-INF/binding/binding.xml b/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/ESH-INF/binding/binding.xml similarity index 100% rename from itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/src/main/resources/ESH-INF/binding/binding.xml rename to itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/ESH-INF/binding/binding.xml diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/src/main/resources/ESH-INF/i18n/yahooweather_de.properties b/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/ESH-INF/i18n/yahooweather_de.properties similarity index 100% rename from itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/src/main/resources/ESH-INF/i18n/yahooweather_de.properties rename to itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/ESH-INF/i18n/yahooweather_de.properties diff --git a/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/src/main/resources/ESH-INF/i18n/yahooweather_nl.properties b/itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/ESH-INF/i18n/yahooweather_nl.properties similarity index 100% rename from itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/src/main/resources/ESH-INF/i18n/yahooweather_nl.properties rename to itests/org.openhab.core.binding.xml.tests/src/main/resources/test-bundle-pool/yahooweather.bundle/ESH-INF/i18n/yahooweather_nl.properties diff --git a/itests/pom.xml b/itests/pom.xml index 0805f3578..5db4faab6 100644 --- a/itests/pom.xml +++ b/itests/pom.xml @@ -26,7 +26,7 @@ - + org.openhab.core.binding.xml.tests org.openhab.core.compat1x.tests org.openhab.core.config.core.tests org.openhab.core.config.discovery.mdns.tests