2 * Copyright (c) 2010-2022 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.hue.internal.discovery;
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.junit.jupiter.api.Assertions.fail;
18 import static org.openhab.binding.hue.internal.HueBindingConstants.*;
19 import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER;
21 import java.net.MalformedURLException;
24 import org.junit.jupiter.api.AfterEach;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27 import org.jupnp.model.ValidationException;
28 import org.jupnp.model.meta.DeviceDetails;
29 import org.jupnp.model.meta.ManufacturerDetails;
30 import org.jupnp.model.meta.ModelDetails;
31 import org.jupnp.model.meta.RemoteDevice;
32 import org.jupnp.model.meta.RemoteDeviceIdentity;
33 import org.jupnp.model.meta.RemoteService;
34 import org.jupnp.model.types.DeviceType;
35 import org.jupnp.model.types.UDN;
36 import org.openhab.core.config.discovery.DiscoveryResult;
37 import org.openhab.core.config.discovery.DiscoveryResultFlag;
38 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
39 import org.openhab.core.test.java.JavaOSGiTest;
40 import org.openhab.core.thing.ThingUID;
43 * Tests for {@link org.openhab.binding.hue.internal.discovery.HueBridgeDiscoveryParticipant}.
45 * @author Kai Kreuzer - Initial contribution
46 * @author Thomas Höfer - Added representation
47 * @author Markus Rathgeb - migrated to plain Java test
49 public class HueBridgeDiscoveryParticipantOSGITest extends JavaOSGiTest {
51 UpnpDiscoveryParticipant discoveryParticipant;
53 RemoteDevice hueDevice;
54 RemoteDevice otherDevice;
58 discoveryParticipant = getService(UpnpDiscoveryParticipant.class, HueBridgeDiscoveryParticipant.class);
59 assertThat(discoveryParticipant, is(notNullValue()));
62 final RemoteService remoteService = null;
64 hueDevice = new RemoteDevice(
65 new RemoteDeviceIdentity(new UDN("123"), 60, new URL("http://hue"), null, null),
66 new DeviceType("namespace", "type"),
67 new DeviceDetails(new URL("http://1.2.3.4/"), "Hue Bridge", new ManufacturerDetails("Philips"),
68 new ModelDetails("Philips hue bridge"), "serial123", "upc", null),
71 otherDevice = new RemoteDevice(
72 new RemoteDeviceIdentity(new UDN("567"), 60, new URL("http://acme"), null, null),
73 new DeviceType("namespace", "type"), new DeviceDetails("Some Device",
74 new ManufacturerDetails("Taiwan"), new ModelDetails("$%&/"), "serial567", "upc"),
76 } catch (final ValidationException | MalformedURLException ex) {
77 fail("Internal test error.");
82 public void cleanUp() {
86 public void correctSupportedTypes() {
87 assertThat(discoveryParticipant.getSupportedThingTypeUIDs().size(), is(1));
88 assertThat(discoveryParticipant.getSupportedThingTypeUIDs().iterator().next(), is(THING_TYPE_BRIDGE));
92 public void correctThingUID() {
93 assertThat(discoveryParticipant.getThingUID(hueDevice), is(new ThingUID("hue:bridge:serial123")));
97 public void validDiscoveryResult() {
98 final DiscoveryResult result = discoveryParticipant.createResult(hueDevice);
99 assertThat(result.getFlag(), is(DiscoveryResultFlag.NEW));
100 assertThat(result.getThingUID(), is(new ThingUID("hue:bridge:serial123")));
101 assertThat(result.getThingTypeUID(), is(THING_TYPE_BRIDGE));
102 assertThat(result.getBridgeUID(), is(nullValue()));
103 assertThat(result.getProperties().get(HOST), is("1.2.3.4"));
104 assertThat(result.getProperties().get(PROPERTY_SERIAL_NUMBER), is("serial123"));
105 assertThat(result.getRepresentationProperty(), is(PROPERTY_SERIAL_NUMBER));
109 public void noThingUIDForUnknownDevice() {
110 assertThat(discoveryParticipant.getThingUID(otherDevice), is(nullValue()));
114 public void noDiscoveryResultForUnknownDevice() {
115 assertThat(discoveryParticipant.createResult(otherDevice), is(nullValue()));