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.assertTrue;
18 import static org.openhab.core.config.discovery.inbox.InboxPredicates.forThingUID;
20 import java.io.IOException;
21 import java.net.MalformedURLException;
22 import java.net.URISyntaxException;
23 import java.util.Collection;
24 import java.util.List;
26 import org.eclipse.jdt.annotation.NonNullByDefault;
27 import org.junit.jupiter.api.AfterEach;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.jupnp.model.ValidationException;
31 import org.jupnp.model.meta.Device;
32 import org.openhab.binding.wemo.internal.WemoBindingConstants;
33 import org.openhab.binding.wemo.internal.discovery.WemoDiscoveryService;
34 import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
35 import org.openhab.core.config.discovery.DiscoveryResult;
36 import org.openhab.core.config.discovery.inbox.Inbox;
37 import org.openhab.core.thing.Thing;
38 import org.openhab.core.thing.ThingTypeUID;
39 import org.openhab.core.thing.ThingUID;
42 * Tests for {@link WemoDiscoveryService}.
44 * @author Svilen Valkanov - Initial contribution
45 * @author Stefan Triller - Ported Tests from Groovy to Java
48 public class WemoDiscoveryOSGiTest extends GenericWemoOSGiTest {
50 // UpnP service information
51 private static final String SERVICE_ID = "basicevent";
52 private static final String SERVICE_NUMBER = "1";
54 private @NonNullByDefault({}) Inbox inbox;
57 public void setUp() throws IOException {
60 inbox = getService(Inbox.class);
61 assertThat(inbox, is(notNullValue()));
65 public void tearDown() {
66 List<DiscoveryResult> results = inbox.getAll();
67 assertThat(results.size(), is(0));
71 public void assertSupportedThingIsDiscovered()
72 throws MalformedURLException, URISyntaxException, ValidationException {
73 ThingTypeUID thingType = WemoBindingConstants.THING_TYPE_INSIGHT;
74 String model = WemoBindingConstants.THING_TYPE_INSIGHT.getId();
76 addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, model);
79 Collection<Device> devices = mockUpnpService.getRegistry().getDevices();
80 assertThat(devices.size(), is(1));
81 Device device = devices.iterator().next();
82 assertThat(device.getDetails().getModelDetails().getModelName(), is(model));
85 ThingUID thingUID = new ThingUID(thingType, DEVICE_UDN);
88 assertTrue(inbox.stream().anyMatch(forThingUID(thingUID)));
91 inbox.approve(thingUID, DEVICE_FRIENDLY_NAME, null);
94 Thing thing = thingRegistry.get(thingUID);
95 assertThat(thing, is(notNullValue()));