2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.wemo.internal.discovery.test;
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.junit.jupiter.api.Assertions.assertNotNull;
19 import java.net.MalformedURLException;
21 import java.net.URISyntaxException;
24 import org.junit.jupiter.api.Test;
25 import org.jupnp.model.ValidationException;
26 import org.jupnp.model.meta.DeviceDetails;
27 import org.jupnp.model.meta.ManufacturerDetails;
28 import org.jupnp.model.meta.ModelDetails;
29 import org.jupnp.model.meta.RemoteDevice;
30 import org.jupnp.model.meta.RemoteDeviceIdentity;
31 import org.jupnp.model.meta.RemoteService;
32 import org.jupnp.model.types.DeviceType;
33 import org.jupnp.model.types.UDN;
34 import org.openhab.binding.wemo.internal.WemoBindingConstants;
35 import org.openhab.binding.wemo.internal.discovery.WemoDiscoveryParticipant;
36 import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
37 import org.openhab.core.config.discovery.DiscoveryResult;
38 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
39 import org.openhab.core.thing.ThingTypeUID;
40 import org.openhab.core.thing.ThingUID;
43 * Tests for {@link WemoDiscoveryParticipant}.
45 * @author Svilen Valkanov - Initial contribution
46 * @author Stefan Triller - Ported Tests from Groovy to Java
48 public class WemoDiscoveryParticipantTest {
49 UpnpDiscoveryParticipant participant = new WemoDiscoveryParticipant();
51 private static final String DEVICE_UDN = GenericWemoOSGiTest.DEVICE_MANUFACTURER + "_3434xxx";
52 private static final String DEVICE_FRIENDLY_NAME = "Wemo Test";
54 RemoteDevice createUpnpDevice(String modelName)
55 throws MalformedURLException, ValidationException, URISyntaxException {
56 return new RemoteDevice(new RemoteDeviceIdentity(new UDN(DEVICE_UDN), 60, new URL("http://wemo"), null, null),
57 new DeviceType("namespace", "type"),
58 new DeviceDetails(DEVICE_FRIENDLY_NAME,
59 new ManufacturerDetails(GenericWemoOSGiTest.DEVICE_MANUFACTURER), new ModelDetails(modelName),
60 new URI("http://1.2.3.4/")),
61 (RemoteService) null);
65 public void assertDiscoveryResultForSocketIsCorrect()
66 throws MalformedURLException, ValidationException, URISyntaxException {
67 testDiscoveryResult(WemoBindingConstants.THING_TYPE_SOCKET);
71 public void assertDiscoveryRresultForInsightIsCorrect()
72 throws MalformedURLException, ValidationException, URISyntaxException {
73 testDiscoveryResult(WemoBindingConstants.THING_TYPE_INSIGHT);
77 public void assertDiscoveryResultForLightswitchIsCorrect()
78 throws MalformedURLException, ValidationException, URISyntaxException {
79 testDiscoveryResult(WemoBindingConstants.THING_TYPE_LIGHTSWITCH);
83 public void assertDiscoveryResultForMotionIsCorrect()
84 throws MalformedURLException, ValidationException, URISyntaxException {
85 testDiscoveryResult(WemoBindingConstants.THING_TYPE_MOTION);
89 public void assertDiscoveryResultForBridgeIsCorrect()
90 throws MalformedURLException, ValidationException, URISyntaxException {
91 testDiscoveryResult(WemoBindingConstants.THING_TYPE_BRIDGE);
95 public void assertDiscoveryResultForMakerIsCorrect()
96 throws MalformedURLException, ValidationException, URISyntaxException {
97 testDiscoveryResult(WemoBindingConstants.THING_TYPE_MAKER);
100 public void testDiscoveryResult(ThingTypeUID thingTypeUid)
101 throws MalformedURLException, ValidationException, URISyntaxException {
102 String thingTypeId = thingTypeUid.getId();
103 RemoteDevice device = createUpnpDevice(thingTypeId);
104 DiscoveryResult result = participant.createResult(device);
106 assertNotNull(result);
107 assertThat(result.getThingUID(), is(new ThingUID(thingTypeUid, DEVICE_UDN)));
108 assertThat(result.getThingTypeUID(), is(thingTypeUid));
109 assertThat(result.getBridgeUID(), is(nullValue()));
110 assertThat(result.getProperties().get(WemoBindingConstants.UDN), is(DEVICE_UDN));
111 assertThat(result.getRepresentationProperty(), is(WemoBindingConstants.UDN));