]> git.basschouten.com Git - openhab-addons.git/blob
f6a179399a22b7917445f966dc18a93b2adc4a0d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.junit.Assert.*;
17
18 import java.net.MalformedURLException;
19 import java.net.URI;
20 import java.net.URISyntaxException;
21 import java.net.URL;
22
23 import org.openhab.core.config.discovery.DiscoveryResult;
24 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.ThingUID;
27 import org.junit.Test;
28 import org.jupnp.model.ValidationException;
29 import org.jupnp.model.meta.DeviceDetails;
30 import org.jupnp.model.meta.ManufacturerDetails;
31 import org.jupnp.model.meta.ModelDetails;
32 import org.jupnp.model.meta.RemoteDevice;
33 import org.jupnp.model.meta.RemoteDeviceIdentity;
34 import org.jupnp.model.meta.RemoteService;
35 import org.jupnp.model.types.DeviceType;
36 import org.jupnp.model.types.UDN;
37 import org.openhab.binding.wemo.internal.WemoBindingConstants;
38 import org.openhab.binding.wemo.internal.discovery.WemoDiscoveryParticipant;
39 import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
40
41 /**
42  * Tests for {@link WemoDiscoveryParticipant}.
43  *
44  * @author Svilen Valkanov - Initial contribution
45  * @author Stefan Triller - Ported Tests from Groovy to Java
46  */
47 public class WemoDiscoveryParticipantTest {
48     UpnpDiscoveryParticipant participant = new WemoDiscoveryParticipant();
49
50     private final String DEVICE_UDN = GenericWemoOSGiTest.DEVICE_MANUFACTURER + "_3434xxx";
51     private final String DEVICE_FRIENDLY_NAME = "Wemo Test";
52
53     RemoteDevice createUpnpDevice(String modelName)
54             throws MalformedURLException, ValidationException, URISyntaxException {
55         return new RemoteDevice(new RemoteDeviceIdentity(new UDN(DEVICE_UDN), 60, new URL("http://wemo"), null, null),
56                 new DeviceType("namespace", "type"),
57                 new DeviceDetails(DEVICE_FRIENDLY_NAME,
58                         new ManufacturerDetails(GenericWemoOSGiTest.DEVICE_MANUFACTURER), new ModelDetails(modelName),
59                         new URI("http://1.2.3.4/")),
60                 (RemoteService) null);
61     }
62
63     @Test
64     public void assertDiscoveryResultForSocketIsCorrect()
65             throws MalformedURLException, ValidationException, URISyntaxException {
66         testDiscoveryResult(WemoBindingConstants.THING_TYPE_SOCKET);
67     }
68
69     @Test
70     public void assertDiscoveryRresultForInsightIsCorrect()
71             throws MalformedURLException, ValidationException, URISyntaxException {
72         testDiscoveryResult(WemoBindingConstants.THING_TYPE_INSIGHT);
73     }
74
75     @Test
76     public void assertDiscoveryResultForLightswitchIsCorrect()
77             throws MalformedURLException, ValidationException, URISyntaxException {
78         testDiscoveryResult(WemoBindingConstants.THING_TYPE_LIGHTSWITCH);
79     }
80
81     @Test
82     public void assertDiscoveryResultForMotionIsCorrect()
83             throws MalformedURLException, ValidationException, URISyntaxException {
84         testDiscoveryResult(WemoBindingConstants.THING_TYPE_MOTION);
85     }
86
87     @Test
88     public void assertDiscoveryResultForBridgeIsCorrect()
89             throws MalformedURLException, ValidationException, URISyntaxException {
90         testDiscoveryResult(WemoBindingConstants.THING_TYPE_BRIDGE);
91     }
92
93     @Test
94     public void assertDiscoveryResultForMakerIsCorrect()
95             throws MalformedURLException, ValidationException, URISyntaxException {
96         testDiscoveryResult(WemoBindingConstants.THING_TYPE_MAKER);
97     }
98
99     public void testDiscoveryResult(ThingTypeUID thingTypeUid)
100             throws MalformedURLException, ValidationException, URISyntaxException {
101         String thingTypeId = thingTypeUid.getId();
102         RemoteDevice device = createUpnpDevice(thingTypeId);
103         DiscoveryResult result = participant.createResult(device);
104
105         assertNotNull(result);
106         assertThat(result.getThingUID(), is(new ThingUID(thingTypeUid, DEVICE_UDN)));
107         assertThat(result.getThingTypeUID(), is(thingTypeUid));
108         assertThat(result.getBridgeUID(), is(nullValue()));
109         assertThat(result.getProperties().get(WemoBindingConstants.UDN), is(DEVICE_UDN.toString()));
110         assertThat(result.getRepresentationProperty(), is(WemoBindingConstants.UDN));
111     }
112 }