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.openhab.core.config.discovery.inbox.InboxPredicates.forThingUID;
16 import static org.hamcrest.CoreMatchers.*;
17 import static org.junit.Assert.*;
19 import java.io.IOException;
20 import java.net.MalformedURLException;
21 import java.net.URISyntaxException;
22 import java.util.Collection;
23 import java.util.List;
25 import org.eclipse.jdt.annotation.NonNullByDefault;
26 import org.openhab.core.config.discovery.DiscoveryResult;
27 import org.openhab.core.config.discovery.inbox.Inbox;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.ThingUID;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.jupnp.model.ValidationException;
35 import org.jupnp.model.meta.Device;
36 import org.openhab.binding.wemo.internal.WemoBindingConstants;
37 import org.openhab.binding.wemo.internal.discovery.WemoDiscoveryService;
38 import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
41 * Tests for {@link WemoDiscoveryService}.
43 * @author Svilen Valkanov - Initial contribution
44 * @author Stefan Triller - Ported Tests from Groovy to Java
47 public class WemoDiscoveryOSGiTest extends GenericWemoOSGiTest {
49 // UpnP service information
50 private static final String SERVICE_ID = "basicevent";
51 private static final String SERVICE_NUMBER = "1";
53 private @NonNullByDefault({}) Inbox inbox;
56 public void setUp() throws IOException {
59 inbox = getService(Inbox.class);
60 assertThat(inbox, is(notNullValue()));
64 public void tearDown() {
65 List<DiscoveryResult> results = inbox.getAll();
66 assertThat(results.size(), is(0));
70 public void assertSupportedThingIsDiscovered()
71 throws MalformedURLException, URISyntaxException, ValidationException {
72 ThingTypeUID thingType = WemoBindingConstants.THING_TYPE_INSIGHT;
73 String model = WemoBindingConstants.THING_TYPE_INSIGHT.getId();
75 addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, model);
78 Collection<Device> devices = mockUpnpService.getRegistry().getDevices();
79 assertThat(devices.size(), is(1));
80 Device device = devices.iterator().next();
81 assertThat(device.getDetails().getModelDetails().getModelName(), is(model));
84 ThingUID thingUID = new ThingUID(thingType, DEVICE_UDN);
87 assertTrue(inbox.stream().anyMatch(forThingUID(thingUID)));
90 inbox.approve(thingUID, DEVICE_FRIENDLY_NAME);
93 Thing thing = thingRegistry.get(thingUID);
94 assertThat(thing, is(notNullValue()));