]> git.basschouten.com Git - openhab-addons.git/blob
efe52a86e463892c0fd6cec05022347eea5b65bb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.wemo.internal.discovery.test;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.junit.jupiter.api.Assertions.assertNotNull;
18
19 import java.net.MalformedURLException;
20 import java.net.URI;
21 import java.net.URISyntaxException;
22 import java.net.URL;
23
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;
41
42 /**
43  * Tests for {@link WemoDiscoveryParticipant}.
44  *
45  * @author Svilen Valkanov - Initial contribution
46  * @author Stefan Triller - Ported Tests from Groovy to Java
47  */
48 public class WemoDiscoveryParticipantTest {
49     UpnpDiscoveryParticipant participant = new WemoDiscoveryParticipant();
50
51     private static final String DEVICE_UDN = GenericWemoOSGiTest.DEVICE_MANUFACTURER + "_3434xxx";
52     private static final String DEVICE_FRIENDLY_NAME = "Wemo Test";
53
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);
62     }
63
64     @Test
65     public void assertDiscoveryResultForSocketIsCorrect()
66             throws MalformedURLException, ValidationException, URISyntaxException {
67         testDiscoveryResult(WemoBindingConstants.THING_TYPE_SOCKET);
68     }
69
70     @Test
71     public void assertDiscoveryRresultForInsightIsCorrect()
72             throws MalformedURLException, ValidationException, URISyntaxException {
73         testDiscoveryResult(WemoBindingConstants.THING_TYPE_INSIGHT);
74     }
75
76     @Test
77     public void assertDiscoveryResultForLightswitchIsCorrect()
78             throws MalformedURLException, ValidationException, URISyntaxException {
79         testDiscoveryResult(WemoBindingConstants.THING_TYPE_LIGHTSWITCH);
80     }
81
82     @Test
83     public void assertDiscoveryResultForMotionIsCorrect()
84             throws MalformedURLException, ValidationException, URISyntaxException {
85         testDiscoveryResult(WemoBindingConstants.THING_TYPE_MOTION);
86     }
87
88     @Test
89     public void assertDiscoveryResultForBridgeIsCorrect()
90             throws MalformedURLException, ValidationException, URISyntaxException {
91         testDiscoveryResult(WemoBindingConstants.THING_TYPE_BRIDGE);
92     }
93
94     @Test
95     public void assertDiscoveryResultForMakerIsCorrect()
96             throws MalformedURLException, ValidationException, URISyntaxException {
97         testDiscoveryResult(WemoBindingConstants.THING_TYPE_MAKER);
98     }
99
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);
105
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));
112     }
113 }