2 * Copyright (c) 2010-2020 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.junit.Assert.*;
18 import java.net.MalformedURLException;
20 import java.net.URISyntaxException;
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;
42 * Tests for {@link WemoDiscoveryParticipant}.
44 * @author Svilen Valkanov - Initial contribution
45 * @author Stefan Triller - Ported Tests from Groovy to Java
47 public class WemoDiscoveryParticipantTest {
48 UpnpDiscoveryParticipant participant = new WemoDiscoveryParticipant();
50 private final String DEVICE_UDN = GenericWemoOSGiTest.DEVICE_MANUFACTURER + "_3434xxx";
51 private final String DEVICE_FRIENDLY_NAME = "Wemo Test";
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);
64 public void assertDiscoveryResultForSocketIsCorrect()
65 throws MalformedURLException, ValidationException, URISyntaxException {
66 testDiscoveryResult(WemoBindingConstants.THING_TYPE_SOCKET);
70 public void assertDiscoveryRresultForInsightIsCorrect()
71 throws MalformedURLException, ValidationException, URISyntaxException {
72 testDiscoveryResult(WemoBindingConstants.THING_TYPE_INSIGHT);
76 public void assertDiscoveryResultForLightswitchIsCorrect()
77 throws MalformedURLException, ValidationException, URISyntaxException {
78 testDiscoveryResult(WemoBindingConstants.THING_TYPE_LIGHTSWITCH);
82 public void assertDiscoveryResultForMotionIsCorrect()
83 throws MalformedURLException, ValidationException, URISyntaxException {
84 testDiscoveryResult(WemoBindingConstants.THING_TYPE_MOTION);
88 public void assertDiscoveryResultForBridgeIsCorrect()
89 throws MalformedURLException, ValidationException, URISyntaxException {
90 testDiscoveryResult(WemoBindingConstants.THING_TYPE_BRIDGE);
94 public void assertDiscoveryResultForMakerIsCorrect()
95 throws MalformedURLException, ValidationException, URISyntaxException {
96 testDiscoveryResult(WemoBindingConstants.THING_TYPE_MAKER);
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);
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));