migrate tests for thing.xml

Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
This commit is contained in:
Markus Rathgeb 2019-02-06 14:05:36 +01:00
parent fd95b86b36
commit 223889c6d0
29 changed files with 595 additions and 619 deletions

View File

@ -1,2 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -3,7 +3,9 @@
Bundle-SymbolicName: ${project.artifactId}
Fragment-Host: org.openhab.core.thing.xml
-runrequires: bnd.identity;id='org.openhab.core.thing.xml.tests'
-runrequires: \
bnd.identity;id='org.openhab.core.thing.xml.tests',\
bnd.identity;id='org.openhab.core.binding.xml'
#
# done
@ -39,4 +41,5 @@ Fragment-Host: org.openhab.core.thing.xml
osgi.enroute.junit.wrapper;version='[4.12.0,4.12.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)'
tec.uom.se;version='[1.0.8,1.0.9)',\
org.openhab.core.binding.xml;version='[2.5.0,2.5.1)'

View File

@ -13,9 +13,10 @@
package org.eclipse.smarthome.core.thing.xml.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;
import java.util.Collection;
import java.util.Optional;
import org.eclipse.smarthome.core.thing.binding.ThingTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
@ -24,12 +25,12 @@ import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
import org.eclipse.smarthome.core.thing.type.ThingType;
import org.eclipse.smarthome.test.BundleCloseable;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
/***
*
@ -60,50 +61,57 @@ public class ChannelTypesI18nTest extends JavaOSGiTest {
assertThat(thingTypeProvider, is(notNullValue()));
}
@After
public void tearDown() throws Exception {
SyntheticBundleInstaller.uninstall(bundleContext, TEST_BUNDLE_NAME);
}
@Test
public void channelTypesShouldTranslateCorrectly() throws Exception {
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
try (BundleCloseable bundle = new BundleCloseable(
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
assertThat(bundle, is(notNullValue()));
Collection<ChannelType> channelTypes = channelTypeProvider.getChannelTypes(null);
ChannelType channelType1 = channelTypes.stream()
.filter(c -> c.getUID().toString().equals("somebinding:channel-with-i18n")).findFirst().get();
assertThat(channelType1, is(not(nullValue())));
assertThat(channelType1.getLabel(), is(equalTo("Channel Label")));
assertThat(channelType1.getDescription(), is(equalTo("Channel Description")));
ChannelType channelType1 = waitForAssert(() -> {
final Optional<ChannelType> opt = channelTypeProvider.getChannelTypes(null).stream()
.filter(c -> c.getUID().toString().equals("somebinding:channel-with-i18n")).findFirst();
assertTrue(opt.isPresent());
return opt.get();
});
assertThat(channelType1, is(not(nullValue())));
assertThat(channelType1.getLabel(), is(equalTo("Channel Label")));
assertThat(channelType1.getDescription(), is(equalTo("Channel Description")));
Collection<ChannelGroupType> channelGroupTypes = channelGroupTypeProvider.getChannelGroupTypes(null);
ChannelGroupType channelGroupType = channelGroupTypes.stream()
.filter(c -> c.getUID().toString().equals("somebinding:channelgroup-with-i18n")).findFirst().get();
assertThat(channelGroupType, is(not(nullValue())));
assertThat(channelGroupType.getLabel(), is(equalTo("Channel Group Label")));
assertThat(channelGroupType.getDescription(), is(equalTo("Channel Group Description")));
Collection<ChannelGroupType> channelGroupTypes = channelGroupTypeProvider.getChannelGroupTypes(null);
ChannelGroupType channelGroupType = channelGroupTypes.stream()
.filter(c -> c.getUID().toString().equals("somebinding:channelgroup-with-i18n")).findFirst().get();
assertThat(channelGroupType, is(not(nullValue())));
assertThat(channelGroupType.getLabel(), is(equalTo("Channel Group Label")));
assertThat(channelGroupType.getDescription(), is(equalTo("Channel Group Description")));
}
}
@Test
public void channelDefinitionsShouldBeTranslatedCorrectly() throws Exception {
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
try (BundleCloseable bundle = new BundleCloseable(
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
assertThat(bundle, is(notNullValue()));
ThingType thingType = thingTypeProvider.getThingTypes(null).stream()
.filter(it -> it.getUID().toString().equals("somebinding:something")).findFirst().get();
assertThat(thingType, is(notNullValue()));
assertThat(thingType.getChannelDefinitions().size(), is(2));
ThingType thingType = waitForAssert(() -> {
Optional<ThingType> thingTypeOpt = thingTypeProvider.getThingTypes(null).stream()
.filter(it -> it.getUID().toString().equals("somebinding:something")).findFirst();
Assert.assertTrue(thingTypeOpt.isPresent());
final ThingType thingTypeTmp = thingTypeOpt.get();
// assertThat(thingTypeTmp, is(notNullValue()));
assertThat(thingTypeTmp.getChannelDefinitions().size(), is(2));
return thingTypeTmp;
});
ChannelDefinition channelDefinition1 = thingType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("channelPlain")).findFirst().get();
assertThat(channelDefinition1.getLabel(), is(equalTo("Channel Plain Label")));
assertThat(channelDefinition1.getDescription(), is(equalTo("Channel Plain Description")));
ChannelDefinition channelDefinition1 = thingType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("channelPlain")).findFirst().get();
assertThat(channelDefinition1.getLabel(), is(equalTo("Channel Plain Label")));
assertThat(channelDefinition1.getDescription(), is(equalTo("Channel Plain Description")));
ChannelDefinition channelDefinition2 = thingType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("channelInplace")).findFirst().get();
assertThat(channelDefinition2.getLabel(), is(equalTo("Channel Inplace Label")));
assertThat(channelDefinition2.getDescription(), is(equalTo("Channel Inplace Description")));
ChannelDefinition channelDefinition2 = thingType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("channelInplace")).findFirst().get();
assertThat(channelDefinition2.getLabel(), is(equalTo("Channel Inplace Label")));
assertThat(channelDefinition2.getDescription(), is(equalTo("Channel Inplace Description")));
}
}
}

View File

@ -21,12 +21,11 @@ import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
import org.eclipse.smarthome.test.BundleCloseable;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
/***
*
@ -52,42 +51,43 @@ public class ChannelTypesTest extends JavaOSGiTest {
assertThat(channelGroupTypeProvider, is(notNullValue()));
}
@After
public void tearDown() throws Exception {
SyntheticBundleInstaller.uninstall(bundleContext, TEST_BUNDLE_NAME);
}
@Test
public void ChannelTypesShouldBeLoaded() throws Exception {
int initialNumberOfChannelTypes = channelTypeProvider.getChannelTypes(null).size();
int initialNumberOfChannelGroupTypes = channelGroupTypeProvider.getChannelGroupTypes(null).size();
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
try (BundleCloseable bundle = new BundleCloseable(
SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME))) {
assertThat(bundle, is(notNullValue()));
Collection<ChannelType> channelTypes = channelTypeProvider.getChannelTypes(null);
assertThat(channelTypes.size(), is(initialNumberOfChannelTypes + 2));
Collection<ChannelType> channelTypes = waitForAssert(() -> {
Collection<ChannelType> channelTypesTmp = channelTypeProvider.getChannelTypes(null);
assertThat(channelTypesTmp.size(), is(initialNumberOfChannelTypes + 2));
return channelTypesTmp;
});
ChannelType channelType1 = channelTypes.stream()
.filter(it -> it.getUID().toString().equals("somebinding:channel1")).findFirst().get();
assertThat(channelType1, is(not(nullValue())));
ChannelType channelType1 = channelTypes.stream()
.filter(it -> it.getUID().toString().equals("somebinding:channel1")).findFirst().get();
assertThat(channelType1, is(not(nullValue())));
ChannelType channelType2 = channelTypes.stream()
.filter(it -> it.getUID().toString().equals("somebinding:channel-without-reference")).findFirst().get();
assertThat(channelType2, is(not(nullValue())));
ChannelType channelType2 = channelTypes.stream()
.filter(it -> it.getUID().toString().equals("somebinding:channel-without-reference")).findFirst()
.get();
assertThat(channelType2, is(not(nullValue())));
Collection<ChannelGroupType> channelGroupTypes = channelGroupTypeProvider.getChannelGroupTypes(null);
assertThat(channelGroupTypes.size(), is(initialNumberOfChannelGroupTypes + 1));
Collection<ChannelGroupType> channelGroupTypes = channelGroupTypeProvider.getChannelGroupTypes(null);
assertThat(channelGroupTypes.size(), is(initialNumberOfChannelGroupTypes + 1));
ChannelGroupType channelGroupType = channelGroupTypes.stream()
.filter(it -> it.getUID().toString().equals("somebinding:channelgroup")).findFirst().get();
assertThat(channelGroupType, is(not(nullValue())));
assertThat(channelGroupType.getCategory(), is("Temperature"));
ChannelGroupType channelGroupType = channelGroupTypes.stream()
.filter(it -> it.getUID().toString().equals("somebinding:channelgroup")).findFirst().get();
assertThat(channelGroupType, is(not(nullValue())));
assertThat(channelGroupType.getCategory(), is("Temperature"));
}
SyntheticBundleInstaller.uninstall(bundleContext, TEST_BUNDLE_NAME);
assertThat(channelTypeProvider.getChannelTypes(null).size(), is(initialNumberOfChannelTypes));
assertThat(channelGroupTypeProvider.getChannelGroupTypes(null).size(), is(initialNumberOfChannelGroupTypes));
waitForAssert(
() -> assertThat(channelTypeProvider.getChannelTypes(null).size(), is(initialNumberOfChannelTypes)));
waitForAssert(() -> assertThat(channelGroupTypeProvider.getChannelGroupTypes(null).size(),
is(initialNumberOfChannelGroupTypes)));
}
}

View File

@ -23,142 +23,114 @@ import org.eclipse.smarthome.config.core.ConfigDescriptionParameter;
import org.eclipse.smarthome.config.core.ConfigDescriptionParameter.Type;
import org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup;
import org.eclipse.smarthome.config.core.ConfigDescriptionRegistry;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.eclipse.smarthome.core.thing.xml.test.LoadedTestBundle.StuffAddition;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
public class ConfigDescriptionsTest extends JavaOSGiTest {
private static final String TEST_BUNDLE_NAME = "ConfigDescriptionsTest.bundle";
private LoadedTestBundle loadedTestBundle() throws Exception {
return new LoadedTestBundle("ConfigDescriptionsTest.bundle", bundleContext, this::getService,
new StuffAddition().configDescriptions(3));
}
private ConfigDescriptionRegistry configDescriptionRegistry;
@Before
public void setUp() {
public void before() {
configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
assertThat(configDescriptionRegistry, is(notNullValue()));
}
@After
public void tearDown() throws Exception {
SyntheticBundleInstaller.uninstall(bundleContext, TEST_BUNDLE_NAME);
}
@Test
public void syntheticBundleShouldLoadFromTestResource() throws Exception {
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
// uninstall test bundle
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
try (final AutoCloseable unused = loadedTestBundle()) {
}
}
@Test
public void ConfigDescriptionsShouldLoadProperly() throws Exception {
int initialNumberOfConfigDescriptions = configDescriptionRegistry.getConfigDescriptions().size();
try (final AutoCloseable unused = loadedTestBundle()) {
URI bridgeURI = new URI("thing-type:hue:bridge");
ConfigDescription bridgeConfigDescription = configDescriptionRegistry.getConfigDescriptions().stream()
.filter(it -> it.getUID().equals(bridgeURI)).findFirst().get();
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
assertThat(bridgeConfigDescription, is(notNullValue()));
Collection<ConfigDescription> configDescriptions = configDescriptionRegistry.getConfigDescriptions();
assertThat(configDescriptions.size(), is(initialNumberOfConfigDescriptions + 3));
Collection<ConfigDescriptionParameter> parameters = bridgeConfigDescription.getParameters();
assertThat(parameters.size(), is(2));
URI bridgeURI = new URI("thing-type:hue:bridge");
ConfigDescription bridgeConfigDescription = configDescriptions.stream()
.filter(it -> it.getUID().equals(bridgeURI)).findFirst().get();
ConfigDescriptionParameter ipParameter = parameters.stream().filter(it -> it.getName().equals("ip"))
.findFirst().get();
assertThat(ipParameter, is(notNullValue()));
assertThat(ipParameter.getType(), is(Type.TEXT));
assertThat(ipParameter.getContext(), is("network-address"));
assertThat(ipParameter.getLabel(), is("Network Address"));
assertThat(ipParameter.getDescription(), is("Network address of the hue bridge."));
assertThat(ipParameter.isRequired(), is(true));
assertThat(bridgeConfigDescription, is(notNullValue()));
ConfigDescriptionParameter userNameParameter = parameters.stream()
.filter(it -> it.getName().equals("username")).findFirst().get();
assertThat(userNameParameter, is(notNullValue()));
Collection<ConfigDescriptionParameter> parameters = bridgeConfigDescription.getParameters();
assertThat(parameters.size(), is(2));
assertThat(userNameParameter.isAdvanced(), is(true));
ConfigDescriptionParameter ipParameter = parameters.stream().filter(it -> it.getName().equals("ip")).findFirst()
.get();
assertThat(ipParameter, is(notNullValue()));
assertThat(ipParameter.getType(), is(Type.TEXT));
assertThat(ipParameter.getContext(), is("network-address"));
assertThat(ipParameter.getLabel(), is("Network Address"));
assertThat(ipParameter.getDescription(), is("Network address of the hue bridge."));
assertThat(ipParameter.isRequired(), is(true));
assertThat(userNameParameter.getType(), is(Type.TEXT));
assertThat(userNameParameter.getContext(), is("password"));
assertThat(userNameParameter.getLabel(), is("Username"));
assertThat(userNameParameter.getDescription(),
is("Name of a registered hue bridge user, that allows to access the API."));
ConfigDescriptionParameter userNameParameter = parameters.stream().filter(it -> it.getName().equals("username"))
.findFirst().get();
assertThat(userNameParameter, is(notNullValue()));
URI colorURI = new URI("channel-type:hue:color");
ConfigDescription colorConfigDescription = configDescriptionRegistry.getConfigDescriptions().stream()
.filter(it -> it.getUID().equals(colorURI)).findFirst().get();
assertThat(userNameParameter.isAdvanced(), is(true));
assertThat(colorConfigDescription, is(notNullValue()));
assertThat(userNameParameter.getType(), is(Type.TEXT));
assertThat(userNameParameter.getContext(), is("password"));
assertThat(userNameParameter.getLabel(), is("Username"));
assertThat(userNameParameter.getDescription(),
is("Name of a registered hue bridge user, that allows to access the API."));
parameters = colorConfigDescription.getParameters();
assertThat(parameters.size(), is(1));
URI colorURI = new URI("channel-type:hue:color");
ConfigDescription colorConfigDescription = configDescriptions.stream()
.filter(it -> it.getUID().equals(colorURI)).findFirst().get();
ConfigDescriptionParameter lastDimValueParameter = parameters.stream()
.filter(it -> it.getName().equals("lastDimValue")).findFirst().get();
assertThat(lastDimValueParameter, is(notNullValue()));
assertThat(lastDimValueParameter.getType(), is(Type.BOOLEAN));
assertThat(colorConfigDescription, is(notNullValue()));
Collection<ConfigDescriptionParameterGroup> groups = bridgeConfigDescription.getParameterGroups();
assertThat(groups.size(), is(2));
parameters = colorConfigDescription.getParameters();
assertThat(parameters.size(), is(1));
ConfigDescriptionParameter lastDimValueParameter = parameters.stream()
.filter(it -> it.getName().equals("lastDimValue")).findFirst().get();
assertThat(lastDimValueParameter, is(notNullValue()));
assertThat(lastDimValueParameter.getType(), is(Type.BOOLEAN));
Collection<ConfigDescriptionParameterGroup> groups = bridgeConfigDescription.getParameterGroups();
assertThat(groups.size(), is(2));
ConfigDescriptionParameterGroup group1 = groups.stream().filter(it -> it.getName().equals("group1")).findFirst()
.get();
assertThat(group1, is(notNullValue()));
assertThat(group1.getContext(), is("Group1-context"));
assertThat(group1.getLabel(), is("Group Label 1"));
assertThat(group1.getDescription(), is("Group description 1"));
// uninstall test bundle
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
ConfigDescriptionParameterGroup group1 = groups.stream().filter(it -> it.getName().equals("group1"))
.findFirst().get();
assertThat(group1, is(notNullValue()));
assertThat(group1.getContext(), is("Group1-context"));
assertThat(group1.getLabel(), is("Group Label 1"));
assertThat(group1.getDescription(), is("Group description 1"));
}
}
@Test
public void parametersWithOptionsAndFiltersShouldLoadProperly() throws Exception {
int initialNumberOfConfigDescriptions = configDescriptionRegistry.getConfigDescriptions().size();
try (final AutoCloseable unused = loadedTestBundle()) {
URI dummyURI = new URI("thing-type:hue:dummy");
ConfigDescription bridgeConfigDescription = configDescriptionRegistry.getConfigDescriptions().stream()
.filter(it -> it.getUID().equals(dummyURI)).findFirst().get();
assertThat(bridgeConfigDescription, is(notNullValue()));
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
Collection<ConfigDescriptionParameter> parameters = bridgeConfigDescription.getParameters();
assertThat(parameters.size(), is(2));
Collection<ConfigDescription> configDescriptions = configDescriptionRegistry.getConfigDescriptions();
assertThat(configDescriptions.size(), is(initialNumberOfConfigDescriptions + 3));
ConfigDescriptionParameter unitParameter = parameters.stream().filter(it -> it.getName().equals("unit"))
.findFirst().get();
assertThat(unitParameter, is(notNullValue()));
assertThat(join(unitParameter.getOptions(), ","), is(
"ParameterOption [value=\"us\", label=\"US\"],ParameterOption [value=\"metric\", label=\"Metric\"]"));
URI dummyURI = new URI("thing-type:hue:dummy");
ConfigDescription bridgeConfigDescription = configDescriptions.stream()
.filter(it -> it.getUID().equals(dummyURI)).findFirst().get();
assertThat(bridgeConfigDescription, is(notNullValue()));
Collection<ConfigDescriptionParameter> parameters = bridgeConfigDescription.getParameters();
assertThat(parameters.size(), is(2));
ConfigDescriptionParameter unitParameter = parameters.stream().filter(it -> it.getName().equals("unit"))
.findFirst().get();
assertThat(unitParameter, is(notNullValue()));
assertThat(join(unitParameter.getOptions(), ","), is(
"ParameterOption [value=\"us\", label=\"US\"],ParameterOption [value=\"metric\", label=\"Metric\"]"));
ConfigDescriptionParameter lightParameter = parameters.stream()
.filter(it -> it.getName().equals("color-alarming-light")).findFirst().get();
assertThat(lightParameter, is(notNullValue()));
assertThat(join(lightParameter.getFilterCriteria(), ","), is(
"FilterCriteria [name=\"tags\", value=\"alarm, light\"],FilterCriteria [name=\"type\", value=\"color\"],FilterCriteria [name=\"binding-id\", value=\"hue\"]"));
ConfigDescriptionParameter lightParameter = parameters.stream()
.filter(it -> it.getName().equals("color-alarming-light")).findFirst().get();
assertThat(lightParameter, is(notNullValue()));
assertThat(join(lightParameter.getFilterCriteria(), ","), is(
"FilterCriteria [name=\"tags\", value=\"alarm, light\"],FilterCriteria [name=\"type\", value=\"color\"],FilterCriteria [name=\"binding-id\", value=\"hue\"]"));
}
}
private String join(Collection<?> elements, String separator) {

View File

@ -0,0 +1,132 @@
package org.eclipse.smarthome.core.thing.xml.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.core.ConfigDescriptionRegistry;
import org.eclipse.smarthome.core.thing.binding.ThingTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.eclipse.smarthome.test.java.JavaTest;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
public class LoadedTestBundle extends JavaTest implements AutoCloseable {
@FunctionalInterface
public interface ServiceProvider {
<T> @Nullable T getService(Class<T> clazz);
}
public static class StuffAddition {
public int addedThingTypes = -1;
public int addedChannelTypes = -1;
public int addedChannelGroupTypes = -1;
public int addedConfigDescriptions = -1;
public StuffAddition() {
}
StuffAddition thingTypes(int nr) {
addedThingTypes = nr;
return this;
}
StuffAddition channelTypes(int nr) {
addedChannelTypes = nr;
return this;
}
StuffAddition channelGroupTypes(int nr) {
addedChannelGroupTypes = nr;
return this;
}
StuffAddition configDescriptions(int nr) {
addedConfigDescriptions = nr;
return this;
}
}
private final ThingTypeProvider thingTypeProvider;
private final ChannelTypeRegistry channelTypeRegistry;
private final ChannelGroupTypeRegistry channelGroupTypeRegistry;
private final ConfigDescriptionRegistry configDescriptionRegistry;
private final int initialNumberOfThingTypes;
private final int initialNumberOfChannelTypes;
private final int initialNumberOfChannelGroupTypes;
private final int initialNumberOfConfigDescriptions;
private final Bundle bundle;
public LoadedTestBundle(String testBundleName, BundleContext bundleContext, ServiceProvider serviceProvider,
StuffAddition stuffAddition) throws Exception {
thingTypeProvider = serviceProvider.getService(ThingTypeProvider.class);
assertThat(thingTypeProvider, is(notNullValue()));
channelTypeRegistry = serviceProvider.getService(ChannelTypeRegistry.class);
assertThat(channelTypeRegistry, is(notNullValue()));
channelGroupTypeRegistry = serviceProvider.getService(ChannelGroupTypeRegistry.class);
assertThat(channelGroupTypeRegistry, is(notNullValue()));
configDescriptionRegistry = serviceProvider.getService(ConfigDescriptionRegistry.class);
assertThat(configDescriptionRegistry, is(notNullValue()));
initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
initialNumberOfChannelTypes = channelTypeRegistry.getChannelTypes().size();
initialNumberOfChannelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes().size();
initialNumberOfConfigDescriptions = configDescriptionRegistry.getConfigDescriptions().size();
this.bundle = SyntheticBundleInstaller.install(bundleContext, testBundleName);
assertThat(bundle, is(notNullValue()));
if (stuffAddition.addedThingTypes >= 0) {
waitForAssert(() -> {
assertThat(thingTypeProvider.getThingTypes(null).size(),
is(initialNumberOfThingTypes + stuffAddition.addedThingTypes));
});
}
if (stuffAddition.addedChannelTypes >= 0) {
waitForAssert(() -> {
assertThat(channelTypeRegistry.getChannelTypes().size(),
is(initialNumberOfChannelTypes + stuffAddition.addedChannelTypes));
});
}
if (stuffAddition.addedChannelGroupTypes >= 0) {
waitForAssert(() -> {
assertThat(channelGroupTypeRegistry.getChannelGroupTypes().size(),
is(initialNumberOfChannelGroupTypes + stuffAddition.addedChannelGroupTypes));
});
}
if (stuffAddition.addedConfigDescriptions >= 0) {
waitForAssert(() -> {
assertThat(configDescriptionRegistry.getConfigDescriptions().size(),
is(initialNumberOfConfigDescriptions + stuffAddition.addedConfigDescriptions));
});
}
}
@Override
public void close() throws BundleException {
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
waitForAssert(() -> {
assertThat(thingTypeProvider.getThingTypes(null).size(), is(initialNumberOfThingTypes));
});
waitForAssert(() -> {
assertThat(channelTypeRegistry.getChannelTypes().size(), is(initialNumberOfChannelTypes));
});
waitForAssert(() -> {
assertThat(channelGroupTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes));
});
waitForAssert(() -> {
assertThat(configDescriptionRegistry.getConfigDescriptions().size(), is(initialNumberOfConfigDescriptions));
});
}
}

View File

@ -15,7 +15,6 @@ package org.eclipse.smarthome.core.thing.xml.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@ -26,12 +25,10 @@ import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ThingType;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.eclipse.smarthome.core.thing.xml.test.LoadedTestBundle.StuffAddition;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
/**
* @author Simon Kaufmann - Initial contribution and API
@ -39,7 +36,10 @@ import org.osgi.framework.Bundle;
*/
public class SystemChannelsInChannelGroupsTest extends JavaOSGiTest {
private static final String SYSTEM_CHANNELS_IN_CHANNEL_GROUPS_BUNDLE_NAME = "SystemChannelsInChannelGroups.bundle";
private LoadedTestBundle loadedTestBundle() throws Exception {
return new LoadedTestBundle("SystemChannelsInChannelGroups.bundle", bundleContext, this::getService,
new StuffAddition().thingTypes(1).channelTypes(1).channelGroupTypes(1));
}
private ThingTypeProvider thingTypeProvider;
private ChannelTypeRegistry channelTypeRegistry;
@ -57,73 +57,46 @@ public class SystemChannelsInChannelGroupsTest extends JavaOSGiTest {
assertThat(channelGroupTypeRegistry, is(notNullValue()));
}
@After
public void tearDown() throws Exception {
SyntheticBundleInstaller.uninstall(bundleContext, SYSTEM_CHANNELS_IN_CHANNEL_GROUPS_BUNDLE_NAME);
}
@Test
public void systemChannelsInChannelGroupsShouldLoadAndUnload() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
int initialNumberOfChannelTypes = channelTypeRegistry.getChannelTypes().size();
int initialNumberOfChannelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes().size();
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_IN_CHANNEL_GROUPS_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 1));
assertThat(channelTypeRegistry.getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));
assertThat(channelGroupTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes + 1));
// uninstall test bundle
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
assertThat(thingTypeProvider.getThingTypes(null).size(), is(initialNumberOfThingTypes));
assertThat(channelTypeRegistry.getChannelTypes().size(), is(initialNumberOfChannelTypes));
assertThat(channelGroupTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes));
try (final AutoCloseable unused = loadedTestBundle()) {
}
}
@Test
public void thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDefinitions() throws Exception {
// install test bundle
Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext,
SYSTEM_CHANNELS_IN_CHANNEL_GROUPS_BUNDLE_NAME);
assertThat(sysBundle, is(notNullValue()));
try (final AutoCloseable unused = loadedTestBundle()) {
List<ThingType> thingTypes = thingTypeProvider.getThingTypes(null).stream()
.filter(it -> it.getUID().getId().equals("wireless-router")).collect(Collectors.toList());
assertThat(thingTypes.size(), is(1));
List<ThingType> thingTypes = thingTypeProvider.getThingTypes(null).stream()
.filter(it -> it.getUID().getId().equals("wireless-router")).collect(Collectors.toList());
List<ChannelGroupType> channelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes();
assertThat(thingTypes.size(), is(1));
ChannelGroupType channelGroup = channelGroupTypes.stream().filter(
it -> it.getUID().equals(new ChannelGroupTypeUID("SystemChannelsInChannelGroups:channelGroup")))
.findFirst().get();
assertThat(channelGroup, is(notNullValue()));
List<ChannelGroupType> channelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes();
List<ChannelDefinition> channelDefs = channelGroup.getChannelDefinitions();
ChannelGroupType channelGroup = channelGroupTypes.stream()
.filter(it -> it.getUID().equals(new ChannelGroupTypeUID("SystemChannelsInChannelGroups:channelGroup")))
.findFirst().get();
assertThat(channelGroup, is(notNullValue()));
List<ChannelDefinition> myChannel = channelDefs.stream().filter(
it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel"))
.collect(Collectors.toList());
List<ChannelDefinition> channelDefs = channelGroup.getChannelDefinitions();
List<ChannelDefinition> sigStr = channelDefs.stream()
.filter(it -> it.getId().equals("sigstr")
&& it.getChannelTypeUID().getAsString().equals("system:signal-strength"))
.collect(Collectors.toList());
List<ChannelDefinition> myChannel = channelDefs.stream().filter(
it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel"))
.collect(Collectors.toList());
List<ChannelDefinition> lowBat = channelDefs.stream()
.filter(it -> it.getId().equals("lowbat")
&& it.getChannelTypeUID().getAsString().equals("system:low-battery"))
.collect(Collectors.toList());
List<ChannelDefinition> sigStr = channelDefs.stream()
.filter(it -> it.getId().equals("sigstr")
&& it.getChannelTypeUID().getAsString().equals("system:signal-strength"))
.collect(Collectors.toList());
List<ChannelDefinition> lowBat = channelDefs.stream().filter(
it -> it.getId().equals("lowbat") && it.getChannelTypeUID().getAsString().equals("system:low-battery"))
.collect(Collectors.toList());
assertThat(myChannel.size(), is(1));
assertThat(sigStr.size(), is(1));
assertThat(lowBat.size(), is(1));
assertThat(myChannel.size(), is(1));
assertThat(sigStr.size(), is(1));
assertThat(lowBat.size(), is(1));
}
}
}

View File

@ -26,12 +26,10 @@ import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ThingType;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.eclipse.smarthome.core.thing.xml.test.LoadedTestBundle.StuffAddition;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
/**
* @author Ivan Iliev - Initial contribution
@ -39,11 +37,20 @@ import org.osgi.framework.Bundle;
*/
public class SystemWideChannelTypesTest extends JavaOSGiTest {
private static final String SYSTEM_CHANNELS_BUNDLE_NAME = "SystemChannels.bundle";
private LoadedTestBundle loadedSystemChannelsBundle() throws Exception {
return new LoadedTestBundle("SystemChannels.bundle", bundleContext, this::getService,
new StuffAddition().thingTypes(1).channelTypes(1));
}
private static final String SYSTEM_CHANNELS_USER_BUNDLE_NAME = "SystemChannelsUser.bundle";
private LoadedTestBundle loadedSystemChannelsUserBundle() throws Exception {
return new LoadedTestBundle("SystemChannelsUser.bundle", bundleContext, this::getService,
new StuffAddition().thingTypes(1).channelTypes(0));
}
private static final String SYSTEM_CHANNELS_WITHOUT_THING_TYPES_BUNDLE_NAME = "SystemChannelsNoThingTypes.bundle";
private LoadedTestBundle loadedSystemChannelsWithoutThingTypesBundle() throws Exception {
return new LoadedTestBundle("SystemChannelsNoThingTypes.bundle", bundleContext, this::getService,
new StuffAddition().thingTypes(0).channelTypes(1));
}
private ThingTypeProvider thingTypeProvider;
private ChannelTypeRegistry channelTypeRegistry;
@ -62,157 +69,94 @@ public class SystemWideChannelTypesTest extends JavaOSGiTest {
systemChannelTypeProvider = provider;
}
@After
public void tearDown() throws Exception {
SyntheticBundleInstaller.uninstall(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
SyntheticBundleInstaller.uninstall(bundleContext, SYSTEM_CHANNELS_USER_BUNDLE_NAME);
SyntheticBundleInstaller.uninstall(bundleContext, SYSTEM_CHANNELS_WITHOUT_THING_TYPES_BUNDLE_NAME);
}
@Test
public void systemChannelsShouldLoadAndUnload() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
int initialNumberOfChannelTypes = getChannelTypes().size();
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 1));
assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));
// uninstall test bundle
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes));
assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes));
try (final AutoCloseable unused = loadedSystemChannelsBundle()) {
}
}
@Test
public void systemChannelsShouldBeusedByOtherBinding() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
int initialNumberOfChannelTypes = getChannelTypes().size();
// install test bundle
Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
assertThat(sysBundle, is(notNullValue()));
Bundle sysUserBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_USER_BUNDLE_NAME);
assertThat(sysUserBundle, is(notNullValue()));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));
assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));
try (final AutoCloseable unused1 = loadedSystemChannelsBundle()) {
try (final AutoCloseable unused2 = loadedSystemChannelsUserBundle()) {
}
}
}
@Test
public void thingTyoesShouldHaveProperChannelDefinitions() throws Exception {
// install test bundle
Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
assertThat(sysBundle, is(notNullValue()));
try (final AutoCloseable unused = loadedSystemChannelsBundle()) {
ThingType wirelessRouterType = thingTypeProvider.getThingTypes(null).stream()
.filter(it -> it.getUID().getAsString().equals("SystemChannels:wireless-router")).findFirst().get();
assertThat(wirelessRouterType, is(notNullValue()));
ThingType wirelessRouterType = thingTypeProvider.getThingTypes(null).stream()
.filter(it -> it.getUID().getAsString().equals("SystemChannels:wireless-router")).findFirst().get();
assertThat(wirelessRouterType, is(notNullValue()));
Collection<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
assertThat(channelDefs.size(), is(3));
Collection<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
assertThat(channelDefs.size(), is(3));
ChannelDefinition myChannel = channelDefs.stream().filter(
it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel"))
.findFirst().get();
assertThat(myChannel, is(notNullValue()));
ChannelDefinition myChannel = channelDefs.stream().filter(
it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel"))
.findFirst().get();
assertThat(myChannel, is(notNullValue()));
ChannelDefinition sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr")
&& it.getChannelTypeUID().getAsString().equals("system:signal-strength")).findFirst().get();
assertThat(sigStr, is(notNullValue()));
ChannelDefinition sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr")
&& it.getChannelTypeUID().getAsString().equals("system:signal-strength")).findFirst().get();
assertThat(sigStr, is(notNullValue()));
ChannelDefinition lowBat = channelDefs.stream().filter(
it -> it.getId().equals("lowbat") && it.getChannelTypeUID().getAsString().equals("system:low-battery"))
.findFirst().get();
assertThat(lowBat, is(notNullValue()));
ChannelDefinition lowBat = channelDefs.stream().filter(it -> it.getId().equals("lowbat")
&& it.getChannelTypeUID().getAsString().equals("system:low-battery")).findFirst().get();
assertThat(lowBat, is(notNullValue()));
}
}
@Test
public void systemChannelsShouldBeAddedWithoutThingTypes() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
int initialNumberOfChannelTypes = getChannelTypes().size();
// install test bundle
Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext,
SYSTEM_CHANNELS_WITHOUT_THING_TYPES_BUNDLE_NAME);
assertThat(sysBundle, is(notNullValue()));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes));
assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));
// uninstall test bundle
sysBundle.uninstall();
assertThat(sysBundle.getState(), is(Bundle.UNINSTALLED));
assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes));
try (final AutoCloseable unused = loadedSystemChannelsWithoutThingTypesBundle()) {
}
}
@Test
public void systemChannelsShouldTranslateProperly() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
try (final AutoCloseable unused = loadedSystemChannelsBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
// install test bundle
Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
assertNotNull(sysBundle);
ThingType wirelessRouterType = thingTypes.stream()
.filter(it -> it.getUID().getAsString().equals("SystemChannels:wireless-router")).findFirst().get();
assertNotNull(wirelessRouterType);
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertEquals(initialNumberOfThingTypes + 1, thingTypes.size());
List<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
assertEquals(3, channelDefs.size());
ThingType wirelessRouterType = thingTypes.stream()
.filter(it -> it.getUID().getAsString().equals("SystemChannels:wireless-router")).findFirst().get();
assertNotNull(wirelessRouterType);
ChannelDefinition myChannel = channelDefs.stream().filter(
it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel"))
.findFirst().get();
assertNotNull(myChannel);
List<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
assertEquals(3, channelDefs.size());
ChannelDefinition sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr")
&& it.getChannelTypeUID().getAsString().equals("system:signal-strength")).findFirst().get();
assertNotNull(sigStr);
ChannelDefinition myChannel = channelDefs.stream().filter(
it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel"))
.findFirst().get();
assertNotNull(myChannel);
ChannelDefinition lowBat = channelDefs.stream().filter(it -> it.getId().equals("lowbat")
&& it.getChannelTypeUID().getAsString().equals("system:low-battery")).findFirst().get();
assertNotNull(lowBat);
ChannelDefinition sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr")
&& it.getChannelTypeUID().getAsString().equals("system:signal-strength")).findFirst().get();
assertNotNull(sigStr);
ChannelType lowBatType = systemChannelTypeProvider.getChannelType(lowBat.getChannelTypeUID(),
Locale.GERMAN);
ChannelDefinition lowBat = channelDefs.stream().filter(
it -> it.getId().equals("lowbat") && it.getChannelTypeUID().getAsString().equals("system:low-battery"))
.findFirst().get();
assertNotNull(lowBat);
ChannelType myChannelChannelType = channelTypeRegistry.getChannelType(myChannel.getChannelTypeUID(),
Locale.GERMAN);
assertNotNull(myChannelChannelType);
assertEquals("Mein String My Channel", myChannelChannelType.getLabel());
assertEquals("Wetterinformation mit My Channel Type Beschreibung", myChannelChannelType.getDescription());
ChannelType lowBatType = systemChannelTypeProvider.getChannelType(lowBat.getChannelTypeUID(), Locale.GERMAN);
assertEquals("Mein String My Channel", myChannel.getLabel());
assertEquals("Wetterinformation mit My Channel Type Beschreibung", myChannel.getDescription());
ChannelType myChannelChannelType = channelTypeRegistry.getChannelType(myChannel.getChannelTypeUID(),
Locale.GERMAN);
assertNotNull(myChannelChannelType);
assertEquals("Mein String My Channel", myChannelChannelType.getLabel());
assertEquals("Wetterinformation mit My Channel Type Beschreibung", myChannelChannelType.getDescription());
assertEquals("Meine spezial Signalstärke", sigStr.getLabel());
assertEquals("Meine spezial Beschreibung für Signalstärke", sigStr.getDescription());
assertEquals("Mein String My Channel", myChannel.getLabel());
assertEquals("Wetterinformation mit My Channel Type Beschreibung", myChannel.getDescription());
assertEquals("Meine spezial Signalstärke", sigStr.getLabel());
assertEquals("Meine spezial Beschreibung für Signalstärke", sigStr.getDescription());
assertEquals("Niedriger Batteriestatus", lowBatType.getLabel());
assertNull(lowBatType.getDescription());
assertEquals("Niedriger Batteriestatus", lowBatType.getLabel());
assertNull(lowBatType.getDescription());
}
}
private List<ChannelType> getChannelTypes() {
return getService(ChannelTypeRegistry.class).getChannelTypes();
}
}

View File

@ -26,16 +26,17 @@ import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ThingType;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.eclipse.smarthome.core.thing.xml.test.LoadedTestBundle.StuffAddition;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
public class ThingTypeI18nTest extends JavaOSGiTest {
private static final String TEST_BUNDLE_NAME = "yahooweather.bundle";
private LoadedTestBundle loadedTestBundle() throws Exception {
return new LoadedTestBundle("yahooweather.bundle", bundleContext, this::getService,
new StuffAddition().thingTypes(2));
}
private ThingTypeProvider thingTypeProvider;
private ChannelTypeRegistry channelTypeRegistry;
@ -53,193 +54,161 @@ public class ThingTypeI18nTest extends JavaOSGiTest {
assertNotNull(channelGroupTypeRegistry);
}
@After
public void tearDown() throws Exception {
SyntheticBundleInstaller.uninstall(bundleContext, TEST_BUNDLE_NAME);
}
@Test
public void thingTypeShouldBeLocalized() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
try (final AutoCloseable unused = loadedTestBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertNotNull(bundle);
ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather"))
.findFirst().get();
assertNotNull(weatherType);
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));
ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather"))
.findFirst().get();
assertNotNull(weatherType);
assertThat(weatherType.getLabel(), is("Wetterinformation"));
assertThat(weatherType.getDescription(), is("Stellt verschiedene Wetterdaten vom Yahoo Wetterdienst bereit"));
assertThat(weatherType.getLabel(), is("Wetterinformation"));
assertThat(weatherType.getDescription(),
is("Stellt verschiedene Wetterdaten vom Yahoo Wetterdienst bereit"));
}
}
@Test
public void channelGroupTypeShouldBeLocalized() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
try (final AutoCloseable unused = loadedTestBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertNotNull(bundle);
ThingType weatherGroupType = thingTypes.stream()
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertNotNull(weatherGroupType);
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));
ChannelGroupType channelGroupType = channelGroupTypeRegistry.getChannelGroupType(
weatherGroupType.getChannelGroupDefinitions().get(0).getTypeUID(), Locale.GERMAN);
assertNotNull(channelGroupType);
ThingType weatherGroupType = thingTypes.stream()
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertNotNull(weatherGroupType);
ChannelGroupType channelGroupType = channelGroupTypeRegistry
.getChannelGroupType(weatherGroupType.getChannelGroupDefinitions().get(0).getTypeUID(), Locale.GERMAN);
assertNotNull(channelGroupType);
assertThat(channelGroupType.getLabel(), is("Wetterinformation mit Gruppe"));
assertThat(channelGroupType.getDescription(), is("Wetterinformation mit Gruppe Beschreibung."));
assertThat(channelGroupType.getLabel(), is("Wetterinformation mit Gruppe"));
assertThat(channelGroupType.getDescription(), is("Wetterinformation mit Gruppe Beschreibung."));
}
}
@Test
public void channelGroupsShouldBeLocalized() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
try (final AutoCloseable unused = loadedTestBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertNotNull(bundle);
ThingType weatherGroupType = thingTypes.stream()
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertNotNull(weatherGroupType);
assertThat(weatherGroupType.getChannelGroupDefinitions().size(), is(2));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));
ChannelGroupDefinition forecastTodayChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions()
.stream().filter(it -> it.getId().equals("forecastToday")).findFirst().get();
assertNotNull(forecastTodayChannelGroupDefinition);
ThingType weatherGroupType = thingTypes.stream()
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertNotNull(weatherGroupType);
assertThat(weatherGroupType.getChannelGroupDefinitions().size(), is(2));
assertThat(forecastTodayChannelGroupDefinition.getLabel(), is("Wettervorhersage heute"));
assertThat(forecastTodayChannelGroupDefinition.getDescription(),
is("Wettervorhersage für den heutigen Tag."));
ChannelGroupDefinition forecastTodayChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions()
.stream().filter(it -> it.getId().equals("forecastToday")).findFirst().get();
assertNotNull(forecastTodayChannelGroupDefinition);
ChannelGroupDefinition forecastTomorrowChannelGroupDefinition = weatherGroupType
.getChannelGroupDefinitions().stream().filter(it -> it.getId().equals("forecastTomorrow"))
.findFirst().get();
assertNotNull(forecastTomorrowChannelGroupDefinition);
assertThat(forecastTodayChannelGroupDefinition.getLabel(), is("Wettervorhersage heute"));
assertThat(forecastTodayChannelGroupDefinition.getDescription(), is("Wettervorhersage für den heutigen Tag."));
ChannelGroupDefinition forecastTomorrowChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions()
.stream().filter(it -> it.getId().equals("forecastTomorrow")).findFirst().get();
assertNotNull(forecastTomorrowChannelGroupDefinition);
assertThat(forecastTomorrowChannelGroupDefinition.getLabel(), is("Wettervorhersage morgen"));
assertThat(forecastTomorrowChannelGroupDefinition.getDescription(),
is("Wettervorhersage für den morgigen Tag."));
assertThat(forecastTomorrowChannelGroupDefinition.getLabel(), is("Wettervorhersage morgen"));
assertThat(forecastTomorrowChannelGroupDefinition.getDescription(),
is("Wettervorhersage für den morgigen Tag."));
}
}
@Test
public void channelsInGroupTypeShouldBeLocalized() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
try (final AutoCloseable unused = loadedTestBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertNotNull(bundle);
ThingType weatherGroupType = thingTypes.stream()
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertNotNull(weatherGroupType);
assertEquals(2, weatherGroupType.getChannelGroupDefinitions().size());
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertEquals(initialNumberOfThingTypes + 2, thingTypes.size());
ChannelGroupDefinition forecastTodayChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions()
.stream().filter(it -> it.getId().equals("forecastToday")).findFirst().get();
assertNotNull(forecastTodayChannelGroupDefinition);
ThingType weatherGroupType = thingTypes.stream()
.filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
assertNotNull(weatherGroupType);
assertEquals(2, weatherGroupType.getChannelGroupDefinitions().size());
ChannelGroupType forecastTodayChannelGroupType = channelGroupTypeRegistry
.getChannelGroupType(forecastTodayChannelGroupDefinition.getTypeUID(), Locale.GERMAN);
assertNotNull(forecastTodayChannelGroupType);
assertEquals(3, forecastTodayChannelGroupType.getChannelDefinitions().size());
ChannelGroupDefinition forecastTodayChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions()
.stream().filter(it -> it.getId().equals("forecastToday")).findFirst().get();
assertNotNull(forecastTodayChannelGroupDefinition);
ChannelDefinition temperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("temperature")).findFirst().get();
assertNotNull(temperatureChannelDefinition);
ChannelGroupType forecastTodayChannelGroupType = channelGroupTypeRegistry
.getChannelGroupType(forecastTodayChannelGroupDefinition.getTypeUID(), Locale.GERMAN);
assertNotNull(forecastTodayChannelGroupType);
assertEquals(3, forecastTodayChannelGroupType.getChannelDefinitions().size());
assertEquals("Temperatur", temperatureChannelDefinition.getLabel());
assertEquals("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).",
temperatureChannelDefinition.getDescription());
ChannelDefinition temperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("temperature")).findFirst().get();
assertNotNull(temperatureChannelDefinition);
ChannelDefinition minTemperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("minTemperature")).findFirst().get();
assertNotNull(minTemperatureChannelDefinition);
assertEquals("Temperatur", temperatureChannelDefinition.getLabel());
assertEquals("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).",
temperatureChannelDefinition.getDescription());
assertEquals("Min. Temperatur", minTemperatureChannelDefinition.getLabel());
assertEquals("Minimale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).",
minTemperatureChannelDefinition.getDescription());
ChannelDefinition minTemperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("minTemperature")).findFirst().get();
assertNotNull(minTemperatureChannelDefinition);
ChannelDefinition maxTemperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("maxTemperature")).findFirst().get();
assertNotNull(maxTemperatureChannelDefinition);
assertEquals("Min. Temperatur", minTemperatureChannelDefinition.getLabel());
assertEquals("Minimale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).",
minTemperatureChannelDefinition.getDescription());
ChannelDefinition maxTemperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("maxTemperature")).findFirst().get();
assertNotNull(maxTemperatureChannelDefinition);
assertEquals("Max. Temperatur", maxTemperatureChannelDefinition.getLabel());
assertEquals("Maximale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).",
maxTemperatureChannelDefinition.getDescription());
assertEquals("Max. Temperatur", maxTemperatureChannelDefinition.getLabel());
assertEquals("Maximale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).",
maxTemperatureChannelDefinition.getDescription());
}
}
@Test
public void channelTypeShouldBeLocalized() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
try (final AutoCloseable unused = loadedTestBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertNotNull(bundle);
ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather"))
.findFirst().get();
assertNotNull(weatherType);
assertThat(weatherType.getChannelDefinitions().size(), is(2));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));
ChannelType temperatureChannelType = channelTypeRegistry.getChannelType(weatherType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("temperature")).findFirst().get().getChannelTypeUID(),
Locale.GERMAN);
assertNotNull(temperatureChannelType);
ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather"))
.findFirst().get();
assertNotNull(weatherType);
assertThat(weatherType.getChannelDefinitions().size(), is(2));
ChannelType temperatureChannelType = channelTypeRegistry.getChannelType(weatherType.getChannelDefinitions()
.stream().filter(it -> it.getId().equals("temperature")).findFirst().get().getChannelTypeUID(),
Locale.GERMAN);
assertNotNull(temperatureChannelType);
assertThat(temperatureChannelType.getLabel(), is("Temperatur"));
assertThat(temperatureChannelType.getDescription(),
is("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
assertThat(temperatureChannelType.getState().getPattern(), is("%d Grad Celsius"));
assertThat(temperatureChannelType.getState().getOptions().get(0).getLabel(), is("Mein String"));
assertThat(temperatureChannelType.getLabel(), is("Temperatur"));
assertThat(temperatureChannelType.getDescription(),
is("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
assertThat(temperatureChannelType.getState().getPattern(), is("%d Grad Celsius"));
assertThat(temperatureChannelType.getState().getOptions().get(0).getLabel(), is("Mein String"));
}
}
@Test
public void channelsShouldBeLocalized() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
try (final AutoCloseable unused = loadedTestBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertNotNull(bundle);
ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather"))
.findFirst().get();
assertNotNull(weatherType);
assertThat(weatherType.getChannelDefinitions().size(), is(2));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));
ChannelDefinition temperatureChannelDefinition = weatherType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("temperature")).findFirst().get();
assertNotNull(temperatureChannelDefinition);
ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather"))
.findFirst().get();
assertNotNull(weatherType);
assertThat(weatherType.getChannelDefinitions().size(), is(2));
assertThat(temperatureChannelDefinition.getLabel(), is("Temperatur"));
assertThat(temperatureChannelDefinition.getDescription(),
is("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
ChannelDefinition temperatureChannelDefinition = weatherType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("temperature")).findFirst().get();
assertNotNull(temperatureChannelDefinition);
ChannelDefinition minTemperatureChannelDefinition = weatherType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("minTemperature")).findFirst().get();
assertNotNull(minTemperatureChannelDefinition);
assertThat(temperatureChannelDefinition.getLabel(), is("Temperatur"));
assertThat(temperatureChannelDefinition.getDescription(),
is("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
ChannelDefinition minTemperatureChannelDefinition = weatherType.getChannelDefinitions().stream()
.filter(it -> it.getId().equals("minTemperature")).findFirst().get();
assertNotNull(minTemperatureChannelDefinition);
assertThat(minTemperatureChannelDefinition.getLabel(), is("Min. Temperatur"));
assertThat(minTemperatureChannelDefinition.getDescription(),
is("Minimale Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
assertThat(minTemperatureChannelDefinition.getLabel(), is("Min. Temperatur"));
assertThat(minTemperatureChannelDefinition.getDescription(),
is("Minimale Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
}
}
}

View File

@ -27,18 +27,18 @@ import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry;
import org.eclipse.smarthome.core.thing.type.ThingType;
import org.eclipse.smarthome.core.thing.xml.test.LoadedTestBundle.StuffAddition;
import org.eclipse.smarthome.core.types.StateDescription;
import org.eclipse.smarthome.test.SyntheticBundleInstaller;
import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
public class ThingTypesTest extends JavaOSGiTest {
private static final String TEST_BUNDLE_NAME = "ThingTypesTest.bundle";
private LoadedTestBundle loadedTestBundle() throws Exception {
return new LoadedTestBundle("ThingTypesTest.bundle", bundleContext, this::getService,
new StuffAddition().thingTypes(3));
}
private ThingTypeProvider thingTypeProvider;
private ChannelTypeRegistry channelTypeRegistry;
@ -52,152 +52,125 @@ public class ThingTypesTest extends JavaOSGiTest {
assertThat(channelTypeRegistry, is(notNullValue()));
}
@After
public void tearDown() throws BundleException {
SyntheticBundleInstaller.uninstall(bundleContext, TEST_BUNDLE_NAME);
}
@Test
public void thingTypesShouldLoad() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
try (final AutoCloseable unused = loadedTestBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
BridgeType bridgeType = (BridgeType) thingTypes.stream().filter(it -> it.toString().equals("hue:bridge"))
.findFirst().get();
assertThat(bridgeType, is(notNullValue()));
assertThat(bridgeType.getCategory(), is("NetworkAppliance"));
assertThat(bridgeType.isListed(), is(false));
assertThat(bridgeType.getLabel(), is("HUE Bridge"));
assertThat(bridgeType.getDescription(), is("The hue Bridge represents the Philips hue bridge."));
assertThat(bridgeType.getProperties().size(), is(1));
assertThat(bridgeType.getProperties().get("vendor"), is("Philips"));
assertThat(bridgeType.getRepresentationProperty(), is("serialNumber"));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 3));
ThingType thingType = thingTypes.stream().filter(it -> it.toString().equals("hue:lamp")).findFirst().get();
BridgeType bridgeType = (BridgeType) thingTypes.stream().filter(it -> it.toString().equals("hue:bridge"))
.findFirst().get();
assertThat(bridgeType, is(notNullValue()));
assertThat(bridgeType.getCategory(), is("NetworkAppliance"));
assertThat(bridgeType.isListed(), is(false));
assertThat(bridgeType.getLabel(), is("HUE Bridge"));
assertThat(bridgeType.getDescription(), is("The hue Bridge represents the Philips hue bridge."));
assertThat(bridgeType.getProperties().size(), is(1));
assertThat(bridgeType.getProperties().get("vendor"), is("Philips"));
assertThat(bridgeType.getRepresentationProperty(), is("serialNumber"));
assertThat(thingType, is(notNullValue()));
assertThat(thingType.getCategory(), is("Lightbulb"));
assertThat(thingType.isListed(), is(false));
assertThat(thingType.getLabel(), is("HUE Lamp"));
assertThat(thingType.getDescription(), is("My own great HUE Lamp."));
assertThat(thingType.getSupportedBridgeTypeUIDs().size(), is(1));
assertThat(thingType.getSupportedBridgeTypeUIDs().get(0), is("hue:bridge"));
assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("alarm", "brightness"));
assertThat(thingType.getProperties().size(), is(2));
assertThat(thingType.getProperties().get("key1"), is("value1"));
assertThat(thingType.getProperties().get("key2"), is("value2"));
assertThat(thingType.getRepresentationProperty(), is("uniqueId"));
ThingType thingType = thingTypes.stream().filter(it -> it.toString().equals("hue:lamp")).findFirst().get();
List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
assertThat(thingType, is(notNullValue()));
assertThat(thingType.getCategory(), is("Lightbulb"));
assertThat(thingType.isListed(), is(false));
assertThat(thingType.getLabel(), is("HUE Lamp"));
assertThat(thingType.getDescription(), is("My own great HUE Lamp."));
assertThat(thingType.getSupportedBridgeTypeUIDs().size(), is(1));
assertThat(thingType.getSupportedBridgeTypeUIDs().get(0), is("hue:bridge"));
assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("alarm", "brightness"));
assertThat(thingType.getProperties().size(), is(2));
assertThat(thingType.getProperties().get("key1"), is("value1"));
assertThat(thingType.getProperties().get("key2"), is("value2"));
assertThat(thingType.getRepresentationProperty(), is("uniqueId"));
assertThat(channelDefinitions.size(), is(3));
ChannelDefinition colorChannel = channelDefinitions.stream().filter(it -> it.getId().equals("color"))
.findFirst().get();
assertThat(colorChannel, is(notNullValue()));
List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
assertThat(colorChannel.getProperties().size(), is(2));
assertThat(colorChannel.getProperties().get("chan.key1"), is("value1"));
assertThat(colorChannel.getProperties().get("chan.key2"), is("value2"));
assertThat(channelDefinitions.size(), is(3));
ChannelDefinition colorChannel = channelDefinitions.stream().filter(it -> it.getId().equals("color"))
.findFirst().get();
assertThat(colorChannel, is(notNullValue()));
ChannelType colorChannelType = channelTypeRegistry.getChannelType(colorChannel.getChannelTypeUID());
assertThat(colorChannelType, is(notNullValue()));
assertThat(colorChannelType.toString(), is("hue:color"));
assertThat(colorChannelType.getItemType(), is("ColorItem"));
assertThat(colorChannelType.getLabel(), is("HUE Lamp Color"));
assertThat(colorChannelType.getDescription(), is(
"The color channel allows to control the color of the hue lamp. It is also possible to dim values and switch the lamp on and off."));
assertThat(colorChannel.getProperties().size(), is(2));
assertThat(colorChannel.getProperties().get("chan.key1"), is("value1"));
assertThat(colorChannel.getProperties().get("chan.key2"), is("value2"));
Set<String> tags = colorChannelType.getTags();
assertThat(tags, is(notNullValue()));
assertThat(tags.contains("Hue"), is(true));
assertThat(tags.contains("ColorLamp"), is(true));
assertThat(tags.contains("AmbientLamp"), is(false));
assertThat(tags.contains("AlarmSystem"), is(false));
ChannelType colorChannelType = channelTypeRegistry.getChannelType(colorChannel.getChannelTypeUID());
assertThat(colorChannelType, is(notNullValue()));
assertThat(colorChannelType.toString(), is("hue:color"));
assertThat(colorChannelType.getItemType(), is("ColorItem"));
assertThat(colorChannelType.getLabel(), is("HUE Lamp Color"));
assertThat(colorChannelType.getDescription(), is(
"The color channel allows to control the color of the hue lamp. It is also possible to dim values and switch the lamp on and off."));
ChannelDefinition colorTemperatureChannel = channelDefinitions.stream()
.filter(it -> it.getId().equals("color_temperature")).findFirst().get();
Set<String> tags = colorChannelType.getTags();
assertThat(tags, is(notNullValue()));
assertThat(tags.contains("Hue"), is(true));
assertThat(tags.contains("ColorLamp"), is(true));
assertThat(tags.contains("AmbientLamp"), is(false));
assertThat(tags.contains("AlarmSystem"), is(false));
assertThat(colorTemperatureChannel, is(notNullValue()));
assertThat(colorTemperatureChannel.getProperties().size(), is(0));
ChannelType colorTemperatureChannelType = channelTypeRegistry
.getChannelType(colorTemperatureChannel.getChannelTypeUID());
assertThat(colorTemperatureChannelType, is(notNullValue()));
ChannelDefinition colorTemperatureChannel = channelDefinitions.stream()
.filter(it -> it.getId().equals("color_temperature")).findFirst().get();
assertThat(colorTemperatureChannelType.toString(), is("hue:color_temperature"));
assertThat(colorTemperatureChannelType.getItemType(), is("DimmerItem"));
assertThat(colorTemperatureChannelType.getLabel(), is("HUE Lamp Color Temperature"));
assertThat(colorTemperatureChannelType.getDescription(), is(
"The color temperature channel allows to set the color temperature from 0 (cold) to 100 (warm)."));
assertThat(colorTemperatureChannel, is(notNullValue()));
assertThat(colorTemperatureChannel.getProperties().size(), is(0));
ChannelType colorTemperatureChannelType = channelTypeRegistry
.getChannelType(colorTemperatureChannel.getChannelTypeUID());
assertThat(colorTemperatureChannelType, is(notNullValue()));
tags = colorTemperatureChannelType.getTags();
assertThat(tags, is(notNullValue()));
assertThat(tags.contains("Hue"), is(true));
assertThat(tags.contains("AmbientLamp"), is(true));
assertThat(tags.contains("ColorLamp"), is(false));
assertThat(tags.contains("AlarmSystem"), is(false));
assertThat(colorTemperatureChannelType.toString(), is("hue:color_temperature"));
assertThat(colorTemperatureChannelType.getItemType(), is("DimmerItem"));
assertThat(colorTemperatureChannelType.getLabel(), is("HUE Lamp Color Temperature"));
assertThat(colorTemperatureChannelType.getDescription(),
is("The color temperature channel allows to set the color temperature from 0 (cold) to 100 (warm)."));
ChannelDefinition alarmChannel = channelDefinitions.stream().filter(it -> it.getId().equals("alarm"))
.findFirst().get();
assertThat(alarmChannel, is(notNullValue()));
ChannelType alarmChannelType = channelTypeRegistry.getChannelType(alarmChannel.getChannelTypeUID());
assertThat(alarmChannelType, is(notNullValue()));
tags = colorTemperatureChannelType.getTags();
assertThat(tags, is(notNullValue()));
assertThat(tags.contains("Hue"), is(true));
assertThat(tags.contains("AmbientLamp"), is(true));
assertThat(tags.contains("ColorLamp"), is(false));
assertThat(tags.contains("AlarmSystem"), is(false));
assertThat(alarmChannelType.toString(), is("hue:alarm"));
assertThat(alarmChannelType.getItemType(), is("Number"));
assertThat(alarmChannelType.getLabel(), is("Alarm System"));
assertThat(alarmChannelType.getDescription(), is("The light blinks if alarm is set."));
ChannelDefinition alarmChannel = channelDefinitions.stream().filter(it -> it.getId().equals("alarm"))
.findFirst().get();
assertThat(alarmChannel, is(notNullValue()));
ChannelType alarmChannelType = channelTypeRegistry.getChannelType(alarmChannel.getChannelTypeUID());
assertThat(alarmChannelType, is(notNullValue()));
tags = alarmChannelType.getTags();
assertThat(tags, is(notNullValue()));
assertThat(tags.contains("Hue"), is(true));
assertThat(tags.contains("AlarmSystem"), is(true));
assertThat(tags.contains("AmbientLamp"), is(false));
assertThat(tags.contains("ColorLamp"), is(false));
assertThat(alarmChannelType.getCategory(), is(equalTo("ALARM")));
assertThat(alarmChannelType.toString(), is("hue:alarm"));
assertThat(alarmChannelType.getItemType(), is("Number"));
assertThat(alarmChannelType.getLabel(), is("Alarm System"));
assertThat(alarmChannelType.getDescription(), is("The light blinks if alarm is set."));
StateDescription state = alarmChannelType.getState();
assertThat(state.getMinimum(), is(BigDecimal.ZERO));
assertThat(state.getMaximum(), is(BigDecimal.valueOf(100.0)));
assertThat(state.getStep(), is(BigDecimal.valueOf(10.0)));
assertThat(state.getPattern(), is(equalTo("%d Peek")));
assertThat(state.isReadOnly(), is(true));
assertThat(state.getOptions().size(), is(2));
assertThat(state.getOptions().get(0).getValue(), is(equalTo("SOUND")));
assertThat(state.getOptions().get(0).getLabel(), is(equalTo("My great sound.")));
tags = alarmChannelType.getTags();
assertThat(tags, is(notNullValue()));
assertThat(tags.contains("Hue"), is(true));
assertThat(tags.contains("AlarmSystem"), is(true));
assertThat(tags.contains("AmbientLamp"), is(false));
assertThat(tags.contains("ColorLamp"), is(false));
assertThat(alarmChannelType.getCategory(), is(equalTo("ALARM")));
StateDescription state = alarmChannelType.getState();
assertThat(state.getMinimum(), is(BigDecimal.ZERO));
assertThat(state.getMaximum(), is(BigDecimal.valueOf(100.0)));
assertThat(state.getStep(), is(BigDecimal.valueOf(10.0)));
assertThat(state.getPattern(), is(equalTo("%d Peek")));
assertThat(state.isReadOnly(), is(true));
assertThat(state.getOptions().size(), is(2));
assertThat(state.getOptions().get(0).getValue(), is(equalTo("SOUND")));
assertThat(state.getOptions().get(0).getLabel(), is(equalTo("My great sound.")));
thingType = thingTypes.stream().filter(it -> it.toString().equals("hue:lamp-with-group")).findFirst().get();
assertThat(thingType.getProperties().size(), is(0));
assertThat(thingType.getCategory(), is(nullValue()));
assertThat(thingType.isListed(), is(true));
assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("brightness", "alarm"));
// uninstall test bundle
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
thingType = thingTypes.stream().filter(it -> it.toString().equals("hue:lamp-with-group")).findFirst().get();
assertThat(thingType.getProperties().size(), is(0));
assertThat(thingType.getCategory(), is(nullValue()));
assertThat(thingType.isListed(), is(true));
assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("brightness", "alarm"));
}
}
@Test
public void thingTypesShouldBeRemoved_whenBundleIsUninstalled() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 3));
// uninstall test bundle
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
thingTypes = thingTypeProvider.getThingTypes(null);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes));
try (final AutoCloseable unused = loadedTestBundle()) {
}
}
}

View File

@ -53,7 +53,7 @@
<!-- <module>org.openhab.core.semantics.tests</module> -->
<!-- <module>org.openhab.core.storage.json.tests</module> -->
<module>org.openhab.core.thing.tests</module>
<!-- <module>org.openhab.core.thing.xml.tests</module> -->
<module>org.openhab.core.thing.xml.tests</module>
<module>org.openhab.core.transform.tests</module>
<module>org.openhab.core.ui.tests</module>
<module>org.openhab.core.ui.icon.tests</module>