[wemo] Delete integration tests (#18572)

* Delete WeMo integration tests

Resolves #12474

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
pull/18114/merge
Jacob Laursen 2025-04-18 19:26:02 +02:00 committed by GitHub
parent ea255612dd
commit 23e3e8427d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 0 additions and 1430 deletions

View File

@ -496,7 +496,6 @@
/itests/org.openhab.binding.ntp.tests/ @marcelrv
/itests/org.openhab.binding.systeminfo.tests/ @mherwege
/itests/org.openhab.binding.tradfri.tests/ @cweitkamp @kaikreuzer
/itests/org.openhab.binding.wemo.tests/ @hmerk
/itests/org.openhab.persistence.mapdb.tests/ @openhab/add-ons-maintainers
# PLEASE HELP ADDING FURTHER LINES HERE!

View File

@ -1,13 +0,0 @@
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

View File

@ -1,101 +0,0 @@
-include: ../itest-common.bndrun
Bundle-SymbolicName: ${project.artifactId}
Fragment-Host: org.openhab.binding.wemo
-includeresource: \
@org.jupnp-*-tests.jar!/org/jupnp/mock/*
-runrequires: \
bnd.identity;id='org.openhab.binding.wemo.tests'
# We would like to use the "volatile" storage only
-runblacklist: \
bnd.identity;id='org.openhab.core.storage.json'
#
# done
#
-runbundles: \
org.hamcrest;version='[3.0.0,3.0.1)',\
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
org.apache.servicemix.specs.activation-api-1.2.1;version='[1.2.1,1.2.2)',\
org.glassfish.hk2.osgi-resource-locator;version='[3.0.0,3.0.1)',\
jakarta.inject.jakarta.inject-api;version='[2.0.1,2.0.2)',\
si-units;version='[2.2.0,2.2.1)',\
si.uom.si-quantity;version='[2.2.0,2.2.1)',\
org.osgi.util.function;version='[1.2.0,1.2.1)',\
org.apache.felix.configadmin;version='[1.9.26,1.9.27)',\
org.apache.felix.http.servlet-api;version='[1.2.0,1.2.1)',\
org.osgi.service.component;version='[1.5.1,1.5.2)',\
net.bytebuddy.byte-buddy;version='[1.12.19,1.12.20)',\
net.bytebuddy.byte-buddy-agent;version='[1.12.19,1.12.20)',\
org.mockito.mockito-core;version='[4.11.0,4.11.1)',\
org.objenesis;version='[3.3.0,3.3.1)',\
xstream;version='[1.4.21,1.4.22)',\
javax.measure.unit-api;version='[2.2.0,2.2.1)',\
tech.units.indriya;version='[2.2.2,2.2.3)',\
uom-lib-common;version='[2.2.0,2.2.1)',\
io.methvin.directory-watcher;version='[0.18.0,0.18.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.9,2.3.10)',\
org.apache.felix.scr;version='[2.2.6,2.2.7)',\
org.eclipse.equinox.event;version='[1.6.200,1.6.201)',\
org.osgi.service.event;version='[1.4.1,1.4.2)',\
org.osgi.util.promise;version='[1.3.0,1.3.1)',\
com.google.gson;version='[2.11.0,2.11.1)',\
junit-jupiter-api;version='[5.12.1,5.12.2)',\
junit-jupiter-engine;version='[5.12.1,5.12.2)',\
junit-platform-commons;version='[1.12.1,1.12.2)',\
junit-platform-engine;version='[1.12.1,1.12.2)',\
junit-platform-launcher;version='[1.12.1,1.12.2)',\
org.opentest4j;version='[1.3.0,1.3.1)',\
ch.qos.logback.classic;version='[1.3.14,1.3.15)',\
ch.qos.logback.core;version='[1.3.14,1.3.15)',\
org.osgi.service.component.annotations;version='[1.5.1,1.5.2)',\
com.sun.jna;version='[5.16.0,5.16.1)',\
org.apache.aries.spifly.dynamic.bundle;version='[1.3.7,1.3.8)',\
org.eclipse.jetty.alpn.client;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.client;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.http;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.http2.client;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.http2.common;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.http2.hpack;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.io;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.jaas;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.security;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.server;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.servlet;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.util;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.util.ajax;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.websocket.api;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.websocket.client;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.websocket.common;version='[9.4.57,9.4.58)',\
org.eclipse.jetty.xml;version='[9.4.57,9.4.58)',\
org.objectweb.asm;version='[9.7.1,9.7.2)',\
org.objectweb.asm.commons;version='[9.6.0,9.6.1)',\
org.objectweb.asm.tree;version='[9.6.0,9.6.1)',\
org.objectweb.asm.tree.analysis;version='[9.6.0,9.6.1)',\
org.objectweb.asm.util;version='[9.6.0,9.6.1)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.2.8,2.2.9)',\
org.ops4j.pax.web.pax-web-api;version='[8.0.30,8.0.31)',\
org.ops4j.pax.web.pax-web-jetty;version='[8.0.30,8.0.31)',\
org.ops4j.pax.web.pax-web-runtime;version='[8.0.30,8.0.31)',\
org.ops4j.pax.web.pax-web-spi;version='[8.0.30,8.0.31)',\
org.ops4j.pax.web.pax-web-tomcat-common;version='[8.0.30,8.0.31)',\
org.openhab.binding.wemo;version='[5.0.0,5.0.1)',\
org.openhab.binding.wemo.tests;version='[5.0.0,5.0.1)',\
org.openhab.core;version='[5.0.0,5.0.1)',\
org.openhab.core.addon;version='[5.0.0,5.0.1)',\
org.openhab.core.config.core;version='[5.0.0,5.0.1)',\
org.openhab.core.config.discovery;version='[5.0.0,5.0.1)',\
org.openhab.core.config.discovery.upnp;version='[5.0.0,5.0.1)',\
org.openhab.core.io.console;version='[5.0.0,5.0.1)',\
org.openhab.core.io.net;version='[5.0.0,5.0.1)',\
org.openhab.core.io.transport.upnp;version='[5.0.0,5.0.1)',\
org.openhab.core.test;version='[5.0.0,5.0.1)',\
org.openhab.core.thing;version='[5.0.0,5.0.1)',\
org.openhab.core.transform;version='[5.0.0,5.0.1)',\
biz.aQute.tester.junit-platform;version='[7.1.0,7.1.1)',\
org.osgi.service.cm;version='[1.6.0,1.6.1)',\
org.jupnp;version='[3.0.3,3.0.4)',\
jakarta.annotation-api;version='[2.1.1,2.1.2)'

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://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>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.openhab.binding.wemo.tests</artifactId>
<name>openHAB Add-ons :: Integration Tests :: Wemo Binding Tests</name>
<dependencies>
<dependency>
<groupId>org.jupnp</groupId>
<artifactId>org.jupnp</artifactId>
<version>3.0.1</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.wemo</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,98 +0,0 @@
/*
* Copyright (c) 2010-2025 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.wemo.internal.discovery.test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openhab.core.config.discovery.inbox.InboxPredicates.forThingUID;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.jupnp.model.meta.Device;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.discovery.WemoDiscoveryService;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.inbox.Inbox;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
/**
* Tests for {@link WemoDiscoveryService}.
*
* @author Svilen Valkanov - Initial contribution
* @author Stefan Triller - Ported Tests from Groovy to Java
*/
@NonNullByDefault
public class WemoDiscoveryOSGiTest extends GenericWemoOSGiTest {
// UpnP service information
private static final String SERVICE_ID = "basicevent";
private static final String SERVICE_NUMBER = "1";
private @NonNullByDefault({}) Inbox inbox;
@BeforeEach
public void setUp() throws IOException {
setUpServices();
inbox = getService(Inbox.class);
assertThat(inbox, is(notNullValue()));
}
@AfterEach
public void tearDown() {
List<DiscoveryResult> results = inbox.getAll();
assertThat(results.size(), is(0));
}
@Test
public void assertSupportedThingIsDiscovered()
throws MalformedURLException, URISyntaxException, ValidationException {
ThingTypeUID thingType = WemoBindingConstants.THING_TYPE_INSIGHT;
String model = WemoBindingConstants.THING_TYPE_INSIGHT.getId();
addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, model);
waitForAssert(() -> {
Collection<Device> devices = mockUpnpService.getRegistry().getDevices();
assertThat(devices.size(), is(1));
Device device = devices.iterator().next();
assertThat(device.getDetails().getModelDetails().getModelName(), is(model));
});
ThingUID thingUID = new ThingUID(thingType, DEVICE_UDN);
waitForAssert(() -> {
assertTrue(inbox.stream().anyMatch(forThingUID(thingUID)));
});
inbox.approve(thingUID, DEVICE_FRIENDLY_NAME, null);
waitForAssert(() -> {
Thing thing = thingRegistry.get(thingUID);
assertThat(thing, is(notNullValue()));
});
}
}

View File

@ -1,113 +0,0 @@
/*
* Copyright (c) 2010-2025 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.wemo.internal.discovery.test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.jupnp.model.meta.DeviceDetails;
import org.jupnp.model.meta.ManufacturerDetails;
import org.jupnp.model.meta.ModelDetails;
import org.jupnp.model.meta.RemoteDevice;
import org.jupnp.model.meta.RemoteDeviceIdentity;
import org.jupnp.model.meta.RemoteService;
import org.jupnp.model.types.DeviceType;
import org.jupnp.model.types.UDN;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.discovery.WemoDiscoveryParticipant;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
/**
* Tests for {@link WemoDiscoveryParticipant}.
*
* @author Svilen Valkanov - Initial contribution
* @author Stefan Triller - Ported Tests from Groovy to Java
*/
public class WemoDiscoveryParticipantTest {
UpnpDiscoveryParticipant participant = new WemoDiscoveryParticipant();
private static final String DEVICE_UDN = GenericWemoOSGiTest.DEVICE_MANUFACTURER + "_3434xxx";
private static final String DEVICE_FRIENDLY_NAME = "Wemo Test";
RemoteDevice createUpnpDevice(String modelName)
throws MalformedURLException, ValidationException, URISyntaxException {
return new RemoteDevice(new RemoteDeviceIdentity(new UDN(DEVICE_UDN), 60, new URL("http://wemo"), null, null),
new DeviceType("namespace", "type"),
new DeviceDetails(DEVICE_FRIENDLY_NAME,
new ManufacturerDetails(GenericWemoOSGiTest.DEVICE_MANUFACTURER), new ModelDetails(modelName),
new URI("http://1.2.3.4/")),
(RemoteService) null);
}
@Test
public void assertDiscoveryResultForSocketIsCorrect()
throws MalformedURLException, ValidationException, URISyntaxException {
testDiscoveryResult(WemoBindingConstants.THING_TYPE_SOCKET);
}
@Test
public void assertDiscoveryRresultForInsightIsCorrect()
throws MalformedURLException, ValidationException, URISyntaxException {
testDiscoveryResult(WemoBindingConstants.THING_TYPE_INSIGHT);
}
@Test
public void assertDiscoveryResultForLightswitchIsCorrect()
throws MalformedURLException, ValidationException, URISyntaxException {
testDiscoveryResult(WemoBindingConstants.THING_TYPE_LIGHTSWITCH);
}
@Test
public void assertDiscoveryResultForMotionIsCorrect()
throws MalformedURLException, ValidationException, URISyntaxException {
testDiscoveryResult(WemoBindingConstants.THING_TYPE_MOTION);
}
@Test
public void assertDiscoveryResultForBridgeIsCorrect()
throws MalformedURLException, ValidationException, URISyntaxException {
testDiscoveryResult(WemoBindingConstants.THING_TYPE_BRIDGE);
}
@Test
public void assertDiscoveryResultForMakerIsCorrect()
throws MalformedURLException, ValidationException, URISyntaxException {
testDiscoveryResult(WemoBindingConstants.THING_TYPE_MAKER);
}
public void testDiscoveryResult(ThingTypeUID thingTypeUid)
throws MalformedURLException, ValidationException, URISyntaxException {
String thingTypeId = thingTypeUid.getId();
RemoteDevice device = createUpnpDevice(thingTypeId);
DiscoveryResult result = participant.createResult(device);
assertNotNull(result);
assertThat(result.getThingUID(), is(new ThingUID(thingTypeUid, DEVICE_UDN)));
assertThat(result.getThingTypeUID(), is(thingTypeUid));
assertThat(result.getBridgeUID(), is(nullValue()));
assertThat(result.getProperties().get(WemoBindingConstants.UDN), is(DEVICE_UDN));
assertThat(result.getRepresentationProperty(), is(WemoBindingConstants.UDN));
}
}

View File

@ -1,86 +0,0 @@
/*
* Copyright (c) 2010-2025 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.wemo.internal.discovery.test;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.discovery.WemoLinkDiscoveryService;
import org.openhab.binding.wemo.internal.handler.WemoBridgeHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.binding.wemo.internal.test.GenericWemoLightOSGiTestParent;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Bridge;
/**
* Tests for {@link WemoLinkDiscoveryService}.
*
* @author Svilen Valkanov - Initial contribution
* @author Stefan Triller - Ported Tests from Groovy to Java
*/
public class WemoLinkDiscoveryServiceOSGiTest extends GenericWemoLightOSGiTestParent {
@BeforeEach
public void setUp() throws IOException {
setUpServices();
}
@Test
public void assertSupportedThingIsDiscovered()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
String model = WemoBindingConstants.THING_TYPE_MZ100.getId();
addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, model);
Configuration config = new Configuration();
config.put(WemoBindingConstants.UDN, GenericWemoOSGiTest.DEVICE_UDN);
Bridge bridge = mock(Bridge.class);
when(bridge.getThingTypeUID()).thenReturn(WemoBindingConstants.THING_TYPE_BRIDGE);
when(bridge.getConfiguration()).thenReturn(config);
WemoBridgeHandler handler = mock(WemoBridgeHandler.class);
when(handler.getThing()).thenReturn(bridge);
WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall());
WemoLinkDiscoveryService discoveryService = new WemoLinkDiscoveryService(handler, upnpIOService, mockCaller);
discoveryService.startScan();
ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class);
verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture());
List<String> results = captur.getAllValues();
boolean found = false;
for (String result : results) {
if (result.contains(
"<u:GetEndDevices xmlns:u=\"urn:Belkin:service:bridge:1\"><DevUDN>uuid:Test-1_0-22124</DevUDN><ReqListType>PAIRED_LIST</ReqListType></u:GetEndDevices>")) {
found = true;
break;
}
}
assertTrue(found);
}
}

View File

@ -1,155 +0,0 @@
/*
* Copyright (c) 2010-2025 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.wemo.internal.handler.test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoHandler;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
/**
* Tests for {@link WemoHandler}.
*
* @author Svilen Valkanov - Initial contribution
* @author Stefan Triller - Ported Tests from Groovy to Java
*/
public class WemoHandlerOSGiTest extends GenericWemoOSGiTest {
// Thing information
private static final String DEFAULT_TEST_CHANNEL = WemoBindingConstants.CHANNEL_STATE;
private static final String DEFAULT_TEST_CHANNEL_TYPE = "Switch";
private static final ThingTypeUID THING_TYPE_UID = WemoBindingConstants.THING_TYPE_SOCKET;
// UPnP information
private static final String MODEL_NAME = WemoBindingConstants.THING_TYPE_SOCKET.getId();
private static final String SERVICE_ID = "basicevent";
private static final String SERVICE_NUMBER = "1";
@BeforeEach
public void setUp() throws IOException {
setUpServices();
}
@AfterEach
public void tearDown() {
removeThing();
}
@Test
@Disabled("https://github.com/openhab/openhab-addons/issues/12474")
public void assertThatThingHandlesOnOffCommandCorrectly()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
Command command = OnOffType.OFF;
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.UNKNOWN));
});
// The device is registered as UPnP Device after the initialization, this will ensure that the polling job will
// not start
addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, MODEL_NAME);
WemoHandler handler = (WemoHandler) thing.getHandler();
assertNotNull(handler);
ChannelUID channelUID = new ChannelUID(thing.getUID(), DEFAULT_TEST_CHANNEL);
handler.handleCommand(channelUID, command);
ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class);
verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture());
List<String> results = captur.getAllValues();
boolean found = false;
for (String result : results) {
// Binary state 0 is equivalent to OFF
if (result.contains("<BinaryState>0</BinaryState>")) {
found = true;
break;
}
}
assertTrue(found);
}
@Test
@Disabled("https://github.com/openhab/openhab-addons/issues/12474")
public void assertThatThingHandlesREFRESHCommandCorrectly()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
Command command = RefreshType.REFRESH;
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.UNKNOWN));
});
// The device is registered as UPnP Device after the initialization, this will ensure that the polling job will
// not start
addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, MODEL_NAME);
WemoHandler handler = (WemoHandler) thing.getHandler();
assertNotNull(handler);
ChannelUID channelUID = new ChannelUID(thing.getUID(), DEFAULT_TEST_CHANNEL);
handler.handleCommand(channelUID, command);
ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class);
verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture());
List<String> results = captur.getAllValues();
boolean found = false;
for (String result : results) {
if (result.contains("<u:GetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\"></u:GetBinaryState>")) {
found = true;
break;
}
}
assertTrue(found);
}
private void removeThing() {
if (thing != null) {
Thing removedThing = thingRegistry.remove(thing.getUID());
assertThat(removedThing, is(notNullValue()));
}
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.UNINITIALIZED));
});
}
}

View File

@ -1,181 +0,0 @@
/*
* Copyright (c) 2010-2025 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.wemo.internal.handler.test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.*;
import static org.openhab.binding.wemo.internal.WemoBindingConstants.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoInsightHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.types.State;
/**
* Tests for {@link WemoInsightHandler}.
*
* @author Svilen Valkanov - Initial contribution
* @author Stefan Triller - Ported Tests from Groovy to Java
*/
public class WemoInsightHandlerTest {
private static final ThingTypeUID THING_TYPE = WemoBindingConstants.THING_TYPE_INSIGHT;
private static final String THING_ID = "test";
private MockWemoInsightHandler handler;
private static final String SERVICE_ID = "insight";
private static final String PARAMS_NAME = "InsightParams";
private WemoInsightParams insightParams;
/** Used for all tests, where expected value is time in seconds **/
private static final int TIME_PARAM = 4702;
/** Represents a state parameter, where 1 stays for ON and 0 stays for OFF **/
private static final int STATE_PARAM = 1;
/** Represents power in Wats **/
private static final int POWER_PARAM = 54;
private final Thing thing = mock(Thing.class);
@BeforeEach
public void setUp() {
insightParams = new WemoInsightParams();
when(thing.getUID()).thenReturn(new ThingUID(THING_TYPE, THING_ID));
when(thing.getThingTypeUID()).thenReturn(THING_TYPE);
when(thing.getStatus()).thenReturn(ThingStatus.ONLINE);
}
@AfterEach
public void clear() {
handler.channelState = null;
handler.channelToWatch = null;
}
@Test
public void assertThatChannelSTATEisUpdatedOnReceivedValue() {
insightParams.state = STATE_PARAM;
State expectedStateType = OnOffType.ON;
String expectedChannel = CHANNEL_STATE;
testOnValueReceived(expectedChannel, expectedStateType, insightParams.toString());
}
@Test
public void assertThatChannelLASTONFORIsUpdatedOnReceivedValue() {
insightParams.lastOnFor = TIME_PARAM;
State expectedStateType = new DecimalType(TIME_PARAM);
String expectedChannel = CHANNEL_LAST_ON_FOR;
testOnValueReceived(expectedChannel, expectedStateType, insightParams.toString());
}
@Test
public void assertThatChannelONTODAYIsUpdatedOnReceivedValue() {
insightParams.onToday = TIME_PARAM;
State expectedStateType = new DecimalType(TIME_PARAM);
String expectedChannel = CHANNEL_ON_TODAY;
testOnValueReceived(expectedChannel, expectedStateType, insightParams.toString());
}
@Test
public void assertThatChannelONTOTALIsUpdatedOnReceivedValue() {
insightParams.onTotal = TIME_PARAM;
State expectedStateType = new DecimalType(TIME_PARAM);
String expectedChannel = CHANNEL_ON_TOTAL;
testOnValueReceived(expectedChannel, expectedStateType, insightParams.toString());
}
@Test
public void assertThatChannelTIMESPANIsUpdatedOnReceivedValue() {
insightParams.timespan = TIME_PARAM;
State expectedStateType = new DecimalType(TIME_PARAM);
String expectedChannel = CHANNEL_TIMESPAN;
testOnValueReceived(expectedChannel, expectedStateType, insightParams.toString());
}
@Test
public void assertThatChannelAVERAGEPOWERIsUpdatedOnReceivedValue() {
insightParams.avgPower = POWER_PARAM;
State expectedStateType = new QuantityType<>(POWER_PARAM, Units.WATT);
String expectedChannel = CHANNEL_AVERAGE_POWER;
testOnValueReceived(expectedChannel, expectedStateType, insightParams.toString());
}
private void testOnValueReceived(String expectedChannel, State expectedState, String insightParams) {
handler = new MockWemoInsightHandler(thing, expectedChannel);
handler.onValueReceived(PARAMS_NAME, insightParams, SERVICE_ID);
assertThat(handler.channelState, is(notNullValue()));
assertThat(handler.channelState, is(expectedState));
}
class MockWemoInsightHandler extends WemoInsightHandler {
State channelState;
String channelToWatch;
public MockWemoInsightHandler(Thing thing, String channelToWatch) {
super(thing, null, new WemoHttpCall());
this.channelToWatch = channelToWatch;
}
@Override
protected void updateState(String channelID, State channelState) {
if (channelID.equals(channelToWatch)) {
this.channelState = channelState;
}
}
@Override
protected void updateStatus(ThingStatus status, ThingStatusDetail statusDetail, String description) {
}
@Override
protected void updateStatus(ThingStatus status, ThingStatusDetail statusDetail) {
}
@Override
protected void updateStatus(ThingStatus status) {
}
}
class WemoInsightParams {
int state, lastChangedAt, lastOnFor, onToday, onTotal, timespan, avgPower, currPower, todayEnergy, totalEnergy,
standbyLimit;
@Override
public String toString() {
// Example string looks like "1|1427230660|4702|25528|82406|1209600|39|40880|15620649|54450534.000000|8000"
return state + "|" + lastChangedAt + "|" + lastOnFor + "|" + onToday + "|" + onTotal + "|" + timespan + "|"
+ avgPower + "|" + currPower + "|" + todayEnergy + "|" + totalEnergy + "|" + standbyLimit;
}
}
}

View File

@ -1,209 +0,0 @@
/*
* Copyright (c) 2010-2025 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.wemo.internal.handler.test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoLightHandler;
import org.openhab.binding.wemo.internal.test.GenericWemoLightOSGiTestParent;
import org.openhab.core.library.types.IncreaseDecreaseType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
/**
* Tests for {@link WemoLightHandler}.
*
* @author Svilen Valkanov - Initial contribution
* @author Stefan Triller - Ported Tests from Groovy to Java
*/
public class WemoLightHandlerOSGiTest extends GenericWemoLightOSGiTestParent {
private static final String GET_ACTION = "GetDeviceStatus";
private static final String SET_ACTION = "SetDeviceStatus";
@BeforeEach
public void setUp() throws IOException {
setUpServices();
}
@AfterEach
public void tearDown() {
removeThing();
}
@Test
public void handleONcommandForBRIGHTNESSchannel()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
Command command = OnOffType.ON;
String channelID = WemoBindingConstants.CHANNEL_BRIGHTNESS;
// Command ON for this channel sends the following data to the device
String action = SET_ACTION;
// ON is equal to brightness value of 255
String value = "255:0";
String capitability = "10008";
assertRequestForCommand(channelID, command, action, value, capitability);
}
@Test
public void handlePercentCommandForBRIGHTNESSChannel()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
// Set brightness value to 20 Percent
Command command = new PercentType(20);
String channelID = WemoBindingConstants.CHANNEL_BRIGHTNESS;
String action = SET_ACTION;
// 20 Percent brightness is equal to a brightness value of 51
String value = "51:0";
String capitability = "10008";
assertRequestForCommand(channelID, command, action, value, capitability);
}
@Test
public void handleIncreaseCommandForBRIGHTNESSchannel()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
// The value is increased by 5 Percents by default
Command command = IncreaseDecreaseType.INCREASE;
String channelID = WemoBindingConstants.CHANNEL_BRIGHTNESS;
String action = SET_ACTION;
// 5 Percents brightness is equal to a brightness value of 12
String value = "12:0";
String capitability = "10008";
assertRequestForCommand(channelID, command, action, value, capitability);
}
@Test
public void handleDecreaseCommandForBRIGHTNESSchannel()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
// The value can not be decreased below 0
Command command = IncreaseDecreaseType.DECREASE;
String channelID = WemoBindingConstants.CHANNEL_BRIGHTNESS;
String action = SET_ACTION;
String value = "0:0";
String capitability = "10008";
assertRequestForCommand(channelID, command, action, value, capitability);
}
@Test
public void handleOnCommandForSTATEChannel()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
Command command = OnOffType.ON;
String channelID = WemoBindingConstants.CHANNEL_STATE;
// Command ON for this channel sends the following data to the device
String action = SET_ACTION;
String value = "1";
String capitability = "10006";
assertRequestForCommand(channelID, command, action, value, capitability);
}
@Test
public void handleREFRESHCommandForChannelSTATE()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
Command command = RefreshType.REFRESH;
String channelID = WemoBindingConstants.CHANNEL_STATE;
String action = GET_ACTION;
String value = null;
String capitability = null;
assertRequestForCommand(channelID, command, action, value, capitability);
}
private void assertRequestForCommand(String channelID, Command command, String action, String value,
String capitability) throws MalformedURLException, URISyntaxException, ValidationException, IOException {
Thing bridge = createBridge(BRIDGE_TYPE_UID);
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(bridge.getStatus(), is(ThingStatus.ONLINE));
});
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.UNKNOWN));
});
// The device is registered as UPnP Device after the initialization, this will ensure that the polling job will
// not start
addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, DEVICE_MODEL_NAME);
ThingUID thingUID = new ThingUID(THING_TYPE_UID, TEST_THING_ID);
ChannelUID channelUID = new ChannelUID(thingUID, channelID);
ThingHandler handler = thing.getHandler();
assertNotNull(handler);
handler.handleCommand(channelUID, command);
ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class);
verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture());
List<String> results = captur.getAllValues();
// we might catch multiple calls. iterate through them to find the one matching our settings
boolean found = false;
for (String result : results) {
boolean matchesCapability = result.contains("CapabilityID&gt;" + capitability + "&lt;");
boolean matchesValue = result.contains("CapabilityValue&gt;" + value + "&lt;");
boolean matchesAction = result.contains("<s:Body><u:" + action);
if (action != null) {
if (!matchesAction) {
continue;
}
}
if (capitability != null) {
if (!matchesCapability) {
continue;
}
}
if (value != null) {
if (!matchesValue) {
continue;
}
}
found = true;
break;
}
assertTrue(found);
}
}

View File

@ -1,155 +0,0 @@
/*
* Copyright (c) 2010-2025 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.wemo.internal.handler.test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoMakerHandler;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
/**
* Tests for {@link WemoMakerHandler}.
*
* @author Svilen Valkanov - Initial contribution
* @author Stefan Triller - Ported Tests from Groovy to Java
*/
public class WemoMakerHandlerOSGiTest extends GenericWemoOSGiTest {
// Specific Thing information
private static final String DEFAULT_TEST_CHANNEL = WemoBindingConstants.CHANNEL_RELAY;
private static final String DEFAULT_TEST_CHANNEL_TYPE = "Switch";
private static final ThingTypeUID THING_TYPE_UID = WemoBindingConstants.THING_TYPE_MAKER;
// Specific UpnP service information
private static final String MODEL = THING_TYPE_UID.getId();
private static final String BASIC_EVENT_SERVICE_ID = "basicevent";
private static final String SERVICE_NUMBER = "1";
@BeforeEach
public void setUp() throws IOException {
setUpServices();
}
@AfterEach
public void tearDown() {
removeThing();
}
@Test
@Disabled("https://github.com/openhab/openhab-addons/issues/12474")
public void assertThatThingHandlesOnOffCommandCorrectly()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
Command command = OnOffType.OFF;
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.OFFLINE));
});
// The Device is registered as UPnP Device after the initialization, this will ensure that the polling job will
// not start
addUpnpDevice(BASIC_EVENT_SERVICE_ID, SERVICE_NUMBER, MODEL);
ChannelUID channelUID = new ChannelUID(thing.getUID(), DEFAULT_TEST_CHANNEL);
ThingHandler handler = thing.getHandler();
assertNotNull(handler);
handler.handleCommand(channelUID, command);
ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class);
verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture());
List<String> results = captur.getAllValues();
boolean found = false;
for (String result : results) {
// Binary state 0 is equivalent to OFF
if (result.contains("<BinaryState>0</BinaryState>")) {
found = true;
break;
}
}
assertTrue(found);
}
@Test
@Disabled("https://github.com/openhab/openhab-addons/issues/12474")
public void assertThatThingHandlesREFRESHCommand()
throws MalformedURLException, URISyntaxException, ValidationException, IOException {
Command command = RefreshType.REFRESH;
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.OFFLINE));
});
// The Device is registered as UPnP Device after the initialization, this will ensure that the polling job will
// not start
addUpnpDevice(BASIC_EVENT_SERVICE_ID, SERVICE_NUMBER, MODEL);
ChannelUID channelUID = new ChannelUID(thing.getUID(), DEFAULT_TEST_CHANNEL);
ThingHandler handler = thing.getHandler();
assertNotNull(handler);
handler.handleCommand(channelUID, command);
ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class);
verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture());
List<String> results = captur.getAllValues();
boolean found = false;
for (String result : results) {
if (result.contains("<u:GetAttributes xmlns:u=\"urn:Belkin:service:deviceevent:1\"></u:GetAttributes>")) {
found = true;
break;
}
}
assertTrue(found);
}
private void removeThing() {
if (thing != null) {
Thing removedThing = thingRegistry.remove(thing.getUID());
assertThat(removedThing, is(notNullValue()));
}
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.UNINITIALIZED));
});
}
}

View File

@ -1,108 +0,0 @@
/*
* Copyright (c) 2010-2025 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.wemo.internal.test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.type.ChannelKind;
/**
* Generic test class for all WemoLight related tests that contains methods and constants used across the different test
* classes
*
* @author Svilen Valkanov - Initial contribution
* @author Stefan Triller - Ported Tests from Groovy to Java
*/
public class GenericWemoLightOSGiTestParent extends GenericWemoOSGiTest {
// Thing information
protected static final ThingTypeUID THING_TYPE_UID = WemoBindingConstants.THING_TYPE_MZ100;
protected static final ThingTypeUID BRIDGE_TYPE_UID = WemoBindingConstants.THING_TYPE_BRIDGE;
protected static final String WEMO_BRIDGE_ID = BRIDGE_TYPE_UID.getId();
protected static final String DEFAULT_TEST_CHANNEL = WemoBindingConstants.CHANNEL_STATE;
protected static final String DEFAULT_TEST_CHANNEL_TYPE = "Switch";
private static final String WEMO_LIGHT_ID = THING_TYPE_UID.getId();
// UPnP service information
protected static final String DEVICE_MODEL_NAME = WEMO_LIGHT_ID;
protected static final String SERVICE_ID = "bridge";
protected static final String SERVICE_NUMBER = "1";
protected static final String SERVLET_URL = DEVICE_CONTROL_PATH + SERVICE_ID + SERVICE_NUMBER;
private Bridge bridge;
protected Bridge createBridge(ThingTypeUID bridgeTypeUID) {
Configuration configuration = new Configuration();
configuration.put(WemoBindingConstants.UDN, DEVICE_UDN);
ThingUID bridgeUID = new ThingUID(bridgeTypeUID, WEMO_BRIDGE_ID);
bridge = BridgeBuilder.create(bridgeTypeUID, bridgeUID).withConfiguration(configuration).build();
managedThingProvider.add(bridge);
return bridge;
}
@Override
protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType) {
Configuration configuration = new Configuration();
configuration.put(WemoBindingConstants.DEVICE_ID, WEMO_LIGHT_ID);
ThingUID thingUID = new ThingUID(thingTypeUID, TEST_THING_ID);
ChannelUID channelUID = new ChannelUID(thingUID, channelID);
Channel channel = ChannelBuilder.create(channelUID, itemAcceptedType).withType(DEFAULT_CHANNEL_TYPE_UID)
.withKind(ChannelKind.STATE).withLabel("label").build();
ThingUID bridgeUID = new ThingUID(BRIDGE_TYPE_UID, WEMO_BRIDGE_ID);
thing = ThingBuilder.create(thingTypeUID, thingUID).withConfiguration(configuration).withChannel(channel)
.withBridge(bridgeUID).build();
managedThingProvider.add(thing);
return thing;
}
protected void removeThing() {
if (thing != null) {
Thing removedThing = thingRegistry.remove(thing.getUID());
assertThat(removedThing, is(notNullValue()));
}
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.UNINITIALIZED));
});
if (bridge != null) {
Bridge bridgeThing = (Bridge) thingRegistry.remove(bridge.getUID());
assertThat(bridgeThing, is(notNullValue()));
}
waitForAssert(() -> {
assertThat(bridge.getStatus(), is(ThingStatus.UNINITIALIZED));
});
}
}

View File

@ -1,178 +0,0 @@
/*
* Copyright (c) 2010-2025 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.wemo.internal.test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;
import org.jupnp.UpnpService;
import org.jupnp.mock.MockUpnpService;
import org.jupnp.model.ValidationException;
import org.jupnp.model.meta.DeviceDetails;
import org.jupnp.model.meta.ManufacturerDetails;
import org.jupnp.model.meta.ModelDetails;
import org.jupnp.model.meta.RemoteDevice;
import org.jupnp.model.meta.RemoteDeviceIdentity;
import org.jupnp.model.meta.RemoteService;
import org.jupnp.model.types.DeviceType;
import org.jupnp.model.types.ServiceId;
import org.jupnp.model.types.ServiceType;
import org.jupnp.model.types.UDN;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.WemoHttpCallFactory;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.io.transport.upnp.UpnpIOService;
import org.openhab.core.library.CoreItemFactory;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ManagedThingProvider;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingRegistry;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.type.ChannelKind;
import org.openhab.core.thing.type.ChannelTypeBuilder;
import org.openhab.core.thing.type.ChannelTypeProvider;
import org.openhab.core.thing.type.ChannelTypeUID;
/**
* Generic test class for all Wemo related tests that contains methods and constants used across the different test
* classes
*
* @author Svilen Valkanov - Initial contribution
* @author Stefan Triller - Ported Tests from Groovy to Java
*/
public abstract class GenericWemoOSGiTest extends JavaOSGiTest {
public static final String DEVICE_MANUFACTURER = "Belkin";
// This port is included in the run configuration
private static final int ORG_OSGI_SERVICE_HTTP_PORT = 9090;
// Thing information
protected static final String TEST_THING_ID = "TestThing";
// UPnP Device information
public static final String DEVICE_UDN = "Test-1_0-22124";
private static final String DEVICE_TYPE = "Test";
private static final int DEVICE_VERSION = 1;
private static final String DEVICE_URL = "http://127.0.0.1:" + ORG_OSGI_SERVICE_HTTP_PORT;
private static final String DEVICE_DESCRIPTION_PATH = "/setup.xml";
protected static final String DEVICE_FRIENDLY_NAME = "WeMo Test";
protected static final String DEVICE_CONTROL_PATH = "/upnp/control/";
protected static final ChannelTypeUID DEFAULT_CHANNEL_TYPE_UID = new ChannelTypeUID(
WemoBindingConstants.BINDING_ID + ":channelType");
protected ManagedThingProvider managedThingProvider;
protected UpnpIOService upnpIOService;
protected ThingRegistry thingRegistry;
protected WemoHttpCall mockCaller;
protected MockUpnpService mockUpnpService;
protected Thing thing;
protected void setUpServices() throws IOException {
// StorageService is required from the ManagedThingProvider
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
// Mock the UPnP Service, that is required from the UPnP IO Service
mockUpnpService = new MockUpnpService(false, true);
mockUpnpService.startup();
registerService(mockUpnpService, UpnpService.class.getName());
managedThingProvider = getService(ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
thingRegistry = getService(ThingRegistry.class);
assertThat(thingRegistry, is(notNullValue()));
// UPnP IO Service is required from the WemoDiscoveryService and WemoHandlerFactory
upnpIOService = getService(UpnpIOService.class);
assertThat(upnpIOService, is(notNullValue()));
mockCaller = Mockito.spy(new WemoHttpCall());
doReturn(true).when(mockCaller).probeURL(any());
WemoHttpCallFactory wemoHttpCallFactory = () -> mockCaller;
registerService(wemoHttpCallFactory, WemoHttpCallFactory.class.getName());
ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), nullable(Locale.class))).thenReturn(
ChannelTypeBuilder.state(DEFAULT_CHANNEL_TYPE_UID, "label", CoreItemFactory.SWITCH).build());
registerService(channelTypeProvider);
}
protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType) {
Configuration configuration = new Configuration();
configuration.put(WemoBindingConstants.UDN, DEVICE_UDN);
ThingUID thingUID = new ThingUID(thingTypeUID, TEST_THING_ID);
ChannelUID channelUID = new ChannelUID(thingUID, channelID);
Channel channel = ChannelBuilder.create(channelUID, itemAcceptedType).withType(DEFAULT_CHANNEL_TYPE_UID)
.withKind(ChannelKind.STATE).withLabel("label").build();
thing = ThingBuilder.create(thingTypeUID, thingUID).withConfiguration(configuration).withChannel(channel)
.build();
managedThingProvider.add(thing);
return thing;
}
protected void addUpnpDevice(String serviceTypeID, String serviceNumber, String modelName)
throws MalformedURLException, URISyntaxException, ValidationException {
UDN udn = new UDN(DEVICE_UDN);
URL deviceURL = new URL(DEVICE_URL + DEVICE_DESCRIPTION_PATH);
RemoteDeviceIdentity identity = new RemoteDeviceIdentity(udn,
WemoBindingConstants.SUBSCRIPTION_DURATION_SECONDS, deviceURL, new byte[1], null);
DeviceType type = new DeviceType(DEVICE_MANUFACTURER, DEVICE_TYPE, DEVICE_VERSION);
ManufacturerDetails manufacturerDetails = new ManufacturerDetails(DEVICE_MANUFACTURER);
ModelDetails modelDetails = new ModelDetails(modelName);
DeviceDetails details = new DeviceDetails(DEVICE_FRIENDLY_NAME, manufacturerDetails, modelDetails);
ServiceType serviceType = new ServiceType(DEVICE_MANUFACTURER, serviceTypeID);
ServiceId serviceId = new ServiceId(DEVICE_MANUFACTURER, serviceNumber);
// Use the same URI for control, event subscription and device description
URI mockURI = new URI(DEVICE_URL + DEVICE_DESCRIPTION_PATH);
URI descriptorURI = mockURI;
URI controlURI = mockURI;
URI eventSubscriptionURI = mockURI;
RemoteService service = new RemoteService(serviceType, serviceId, descriptorURI, controlURI,
eventSubscriptionURI);
RemoteDevice localDevice = new RemoteDevice(identity, type, details, service);
mockUpnpService.getRegistry().addDevice(localDevice);
}
}

View File

@ -32,7 +32,6 @@
<module>org.openhab.binding.ntp.tests</module>
<module>org.openhab.binding.systeminfo.tests</module>
<module>org.openhab.binding.tradfri.tests</module>
<module>org.openhab.binding.wemo.tests</module>
<module>org.openhab.persistence.mapdb.tests</module>
</modules>