added migrated 2.x add-ons
Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
27
itests/org.openhab.binding.tradfri.tests/.classpath
Normal file
27
itests/org.openhab.binding.tradfri.tests/.classpath
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
23
itests/org.openhab.binding.tradfri.tests/.project
Normal file
23
itests/org.openhab.binding.tradfri.tests/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.openhab.binding.tradfri.tests</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
13
itests/org.openhab.binding.tradfri.tests/NOTICE
Normal file
13
itests/org.openhab.binding.tradfri.tests/NOTICE
Normal file
@@ -0,0 +1,13 @@
|
||||
This content is produced and maintained by the openHAB project.
|
||||
|
||||
* Project home: https://www.openhab.org
|
||||
|
||||
== Declared Project Licenses
|
||||
|
||||
This program and the accompanying materials are made available under the terms
|
||||
of the Eclipse Public License 2.0 which is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/.
|
||||
|
||||
== Source Code
|
||||
|
||||
https://github.com/openhab/openhab-addons
|
||||
62
itests/org.openhab.binding.tradfri.tests/itest.bndrun
Normal file
62
itests/org.openhab.binding.tradfri.tests/itest.bndrun
Normal file
@@ -0,0 +1,62 @@
|
||||
-include: ../itest-common.bndrun
|
||||
|
||||
Bundle-SymbolicName: ${project.artifactId}
|
||||
Fragment-Host: org.openhab.binding.tradfri
|
||||
|
||||
-runrequires: \
|
||||
bnd.identity;id='org.openhab.binding.tradfri.tests',\
|
||||
bnd.identity;id='org.openhab.core.binding.xml',\
|
||||
bnd.identity;id='org.openhab.core.thing.xml'
|
||||
|
||||
#
|
||||
# done
|
||||
#
|
||||
-runbundles: \
|
||||
javax.measure.unit-api;version='[1.0.0,1.0.1)',\
|
||||
org.apache.commons.io;version='[2.2.0,2.2.1)',\
|
||||
org.apache.commons.lang;version='[2.6.0,2.6.1)',\
|
||||
org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\
|
||||
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
|
||||
org.osgi.service.event;version='[1.4.0,1.4.1)',\
|
||||
org.openhab.core;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.config.core;version='[2.5.0,2.5.1)',\
|
||||
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
|
||||
org.openhab.core.config.discovery;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.io.console;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.thing;version='[2.5.0,2.5.1)',\
|
||||
slf4j.api;version='[1.7.25,1.7.26)',\
|
||||
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
|
||||
com.google.gson;version='[2.8.2,2.8.3)',\
|
||||
javax.jmdns;version='[3.5.5,3.5.6)',\
|
||||
org.apache.servicemix.specs.activation-api-1.1;version='[2.9.0,2.9.1)',\
|
||||
org.apache.servicemix.specs.jaxb-api-2.2;version='[2.9.0,2.9.1)',\
|
||||
org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\
|
||||
org.openhab.core.config.discovery.mdns;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.io.transport.mdns;version='[2.5.0,2.5.1)',\
|
||||
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
|
||||
org.objenesis;version='[2.6.0,2.6.1)',\
|
||||
org.openhab.core.test;version='[2.5.0,2.5.1)',\
|
||||
osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\
|
||||
osgi.enroute.junit.wrapper;version='[4.12.0,4.12.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.config.xml;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.thing.xml;version='[2.5.0,2.5.1)',\
|
||||
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
|
||||
tec.uom.se;version='[1.0.10,1.0.11)',\
|
||||
org.apache.servicemix.bundles.jaxb-impl;version='[2.2.11,2.2.12)',\
|
||||
net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\
|
||||
net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\
|
||||
org.mockito.mockito-core;version='[3.1.0,3.1.1)',\
|
||||
org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.security;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.server;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.servlet;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.util;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.californium.core;version='[2.0.0,2.0.1)',\
|
||||
org.eclipse.californium.element-connector;version='[2.0.0,2.0.1)',\
|
||||
org.eclipse.californium.scandium;version='[2.0.0,2.0.1)',\
|
||||
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
|
||||
org.openhab.binding.tradfri;version='[2.5.9,2.5.10)',\
|
||||
org.openhab.binding.tradfri.tests;version='[2.5.9,2.5.10)'
|
||||
25
itests/org.openhab.binding.tradfri.tests/pom.xml
Normal file
25
itests/org.openhab.binding.tradfri.tests/pom.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.addons.itests</groupId>
|
||||
<artifactId>org.openhab.addons.reactor.itests</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.binding.tradfri.tests</artifactId>
|
||||
|
||||
<name>openHAB Add-ons :: Integration Tests :: TRÅDFRI Binding</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.binding.tradfri</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.addons.itests</groupId>
|
||||
<artifactId>org.openhab.addons.reactor.itests</artifactId>
|
||||
<version>2.5.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.binding.tradfri.tests</artifactId>
|
||||
|
||||
<name>openHAB Add-ons :: Integration Tests :: TRÅDFRI Binding</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.binding.tradfri</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.binding.tradfri.internal.discovery;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
|
||||
|
||||
import javax.jmdns.ServiceInfo;
|
||||
|
||||
import org.openhab.core.config.discovery.DiscoveryResult;
|
||||
import org.openhab.core.config.discovery.DiscoveryResultFlag;
|
||||
import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingUID;
|
||||
import org.openhab.core.test.java.JavaOSGiTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link TradfriDiscoveryParticipant}.
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
public class TradfriDiscoveryParticipantOSGITest extends JavaOSGiTest {
|
||||
|
||||
private MDNSDiscoveryParticipant discoveryParticipant;
|
||||
|
||||
@Mock
|
||||
private ServiceInfo tradfriGateway;
|
||||
|
||||
@Mock
|
||||
private ServiceInfo otherDevice;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
initMocks(this);
|
||||
discoveryParticipant = getService(MDNSDiscoveryParticipant.class, TradfriDiscoveryParticipant.class);
|
||||
|
||||
when(tradfriGateway.getType()).thenReturn("_coap._udp.local.");
|
||||
when(tradfriGateway.getName()).thenReturn("gw:12-34-56-78-90-ab");
|
||||
when(tradfriGateway.getHostAddresses()).thenReturn(new String[] { "192.168.0.5" });
|
||||
when(tradfriGateway.getPort()).thenReturn(1234);
|
||||
when(tradfriGateway.getPropertyString("version")).thenReturn("1.1");
|
||||
|
||||
when(otherDevice.getType()).thenReturn("_coap._udp.local.");
|
||||
when(otherDevice.getName()).thenReturn("something");
|
||||
when(otherDevice.getHostAddresses()).thenReturn(new String[] { "192.168.0.5" });
|
||||
when(otherDevice.getPort()).thenReturn(1234);
|
||||
when(otherDevice.getPropertyString("version")).thenReturn("1.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctSupportedTypes() {
|
||||
assertThat(discoveryParticipant.getSupportedThingTypeUIDs().size(), is(1));
|
||||
assertThat(discoveryParticipant.getSupportedThingTypeUIDs().iterator().next(), is(GATEWAY_TYPE_UID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctThingUID() {
|
||||
when(tradfriGateway.getName()).thenReturn("gw:12-34-56-78-90-ab");
|
||||
assertThat(discoveryParticipant.getThingUID(tradfriGateway),
|
||||
is(new ThingUID("tradfri:gateway:gw1234567890ab")));
|
||||
|
||||
when(tradfriGateway.getName()).thenReturn("gw:1234567890ab");
|
||||
assertThat(discoveryParticipant.getThingUID(tradfriGateway),
|
||||
is(new ThingUID("tradfri:gateway:gw1234567890ab")));
|
||||
|
||||
when(tradfriGateway.getName()).thenReturn("gw-12-34-56-78-90-ab");
|
||||
assertThat(discoveryParticipant.getThingUID(tradfriGateway),
|
||||
is(new ThingUID("tradfri:gateway:gw1234567890ab")));
|
||||
|
||||
when(tradfriGateway.getName()).thenReturn("gw:1234567890ab");
|
||||
assertThat(discoveryParticipant.getThingUID(tradfriGateway),
|
||||
is(new ThingUID("tradfri:gateway:gw1234567890ab")));
|
||||
|
||||
when(tradfriGateway.getName()).thenReturn("gw:1234567890abServiceInfo");
|
||||
assertThat(discoveryParticipant.getThingUID(tradfriGateway),
|
||||
is(new ThingUID("tradfri:gateway:gw1234567890ab")));
|
||||
|
||||
when(tradfriGateway.getName()).thenReturn("gw:12-34-56-78-90-ab-service-info");
|
||||
assertThat(discoveryParticipant.getThingUID(tradfriGateway),
|
||||
is(new ThingUID("tradfri:gateway:gw1234567890ab")));
|
||||
|
||||
// restore original value
|
||||
when(tradfriGateway.getName()).thenReturn("gw:12-34-56-78-90-ab");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validDiscoveryResult() {
|
||||
DiscoveryResult result = discoveryParticipant.createResult(tradfriGateway);
|
||||
|
||||
assertNotNull(result);
|
||||
assertThat(result.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is("1.1"));
|
||||
assertThat(result.getFlag(), is(DiscoveryResultFlag.NEW));
|
||||
assertThat(result.getThingUID(), is(new ThingUID("tradfri:gateway:gw1234567890ab")));
|
||||
assertThat(result.getThingTypeUID(), is(GATEWAY_TYPE_UID));
|
||||
assertThat(result.getBridgeUID(), is(nullValue()));
|
||||
assertThat(result.getProperties().get(Thing.PROPERTY_VENDOR), is("IKEA of Sweden"));
|
||||
assertThat(result.getProperties().get(GATEWAY_CONFIG_HOST), is("192.168.0.5"));
|
||||
assertThat(result.getProperties().get(GATEWAY_CONFIG_PORT), is(1234));
|
||||
assertThat(result.getRepresentationProperty(), is(GATEWAY_CONFIG_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noThingUIDForUnknownDevice() {
|
||||
when(otherDevice.getName()).thenReturn("something");
|
||||
assertThat(discoveryParticipant.getThingUID(otherDevice), is(nullValue()));
|
||||
|
||||
when(otherDevice.getName()).thenReturn("gw_1234567890ab");
|
||||
assertThat(discoveryParticipant.getThingUID(otherDevice), is(nullValue()));
|
||||
|
||||
when(otherDevice.getName()).thenReturn("gw:12-3456--7890-ab");
|
||||
assertThat(discoveryParticipant.getThingUID(otherDevice), is(nullValue()));
|
||||
|
||||
when(otherDevice.getName()).thenReturn("gw1234567890ab");
|
||||
assertThat(discoveryParticipant.getThingUID(otherDevice), is(nullValue()));
|
||||
|
||||
// restore original value
|
||||
when(otherDevice.getName()).thenReturn("something");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noDiscoveryResultForUnknownDevice() {
|
||||
assertThat(discoveryParticipant.createResult(otherDevice), is(nullValue()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.binding.tradfri.internal.handler;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
|
||||
import static org.openhab.binding.tradfri.internal.config.TradfriDeviceConfig.CONFIG_ID;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
import org.openhab.core.thing.ManagedThingProvider;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingProvider;
|
||||
import org.openhab.core.thing.binding.builder.BridgeBuilder;
|
||||
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
import org.openhab.core.test.java.JavaOSGiTest;
|
||||
import org.openhab.core.test.storage.VolatileStorageService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests cases for {@link TradfriGatewayHandler}.
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
public class TradfriHandlerOSGiTest extends JavaOSGiTest {
|
||||
|
||||
private ManagedThingProvider managedThingProvider;
|
||||
private VolatileStorageService volatileStorageService = new VolatileStorageService();
|
||||
private Bridge bridge;
|
||||
private Thing thing;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
registerService(volatileStorageService);
|
||||
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put(GATEWAY_CONFIG_HOST, "1.2.3.4");
|
||||
properties.put(GATEWAY_CONFIG_IDENTITY, "identity");
|
||||
properties.put(GATEWAY_CONFIG_PRE_SHARED_KEY, "pre-shared-secret-key");
|
||||
bridge = BridgeBuilder.create(GATEWAY_TYPE_UID, "1").withLabel("My Gateway")
|
||||
.withConfiguration(new Configuration(properties)).build();
|
||||
|
||||
properties = new HashMap<>();
|
||||
properties.put(CONFIG_ID, "65537");
|
||||
thing = ThingBuilder.create(THING_TYPE_DIMMABLE_LIGHT, "1").withLabel("My Bulb").withBridge(bridge.getUID())
|
||||
.withConfiguration(new Configuration(properties)).build();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
managedThingProvider.remove(thing.getUID());
|
||||
managedThingProvider.remove(bridge.getUID());
|
||||
unregisterService(volatileStorageService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void creationOfTradfriGatewayHandler() {
|
||||
assertThat(bridge.getHandler(), is(nullValue()));
|
||||
managedThingProvider.add(bridge);
|
||||
waitForAssert(() -> assertThat(bridge.getHandler(), notNullValue()));
|
||||
|
||||
configurationOfTradfriGatewayHandler();
|
||||
}
|
||||
|
||||
private void configurationOfTradfriGatewayHandler() {
|
||||
Configuration configuration = bridge.getConfiguration();
|
||||
assertThat(configuration, is(notNullValue()));
|
||||
|
||||
assertThat(configuration.get(GATEWAY_CONFIG_HOST), is("1.2.3.4"));
|
||||
assertThat(configuration.get(GATEWAY_CONFIG_IDENTITY), is("identity"));
|
||||
assertThat(configuration.get(GATEWAY_CONFIG_PRE_SHARED_KEY), is("pre-shared-secret-key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void creationOfTradfriLightHandler() {
|
||||
assertThat(thing.getHandler(), is(nullValue()));
|
||||
managedThingProvider.add(bridge);
|
||||
managedThingProvider.add(thing);
|
||||
waitForAssert(() -> assertThat(thing.getHandler(), notNullValue()));
|
||||
|
||||
configurationOfTradfriLightHandler();
|
||||
}
|
||||
|
||||
private void configurationOfTradfriLightHandler() {
|
||||
Configuration configuration = thing.getConfiguration();
|
||||
assertThat(configuration, is(notNullValue()));
|
||||
|
||||
assertThat(configuration.get(CONFIG_ID), is("65537"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user