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.wemo.internal.discovery.test;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.ArgumentMatchers.any;
17 import static org.mockito.Mockito.*;
19 import java.io.IOException;
20 import java.net.MalformedURLException;
21 import java.net.URISyntaxException;
22 import java.util.List;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.jupnp.model.ValidationException;
27 import org.mockito.ArgumentCaptor;
28 import org.mockito.Mockito;
29 import org.openhab.binding.wemo.internal.WemoBindingConstants;
30 import org.openhab.binding.wemo.internal.discovery.WemoLinkDiscoveryService;
31 import org.openhab.binding.wemo.internal.handler.WemoBridgeHandler;
32 import org.openhab.binding.wemo.internal.http.WemoHttpCall;
33 import org.openhab.binding.wemo.internal.test.GenericWemoLightOSGiTestParent;
34 import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
35 import org.openhab.core.config.core.Configuration;
36 import org.openhab.core.thing.Bridge;
39 * Tests for {@link WemoLinkDiscoveryService}.
41 * @author Svilen Valkanov - Initial contribution
42 * @author Stefan Triller - Ported Tests from Groovy to Java
44 public class WemoLinkDiscoveryServiceOSGiTest extends GenericWemoLightOSGiTestParent {
47 public void setUp() throws IOException {
52 public void assertSupportedThingIsDiscovered()
53 throws MalformedURLException, URISyntaxException, ValidationException, IOException {
54 String model = WemoBindingConstants.THING_TYPE_MZ100.getId();
55 addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, model);
57 Configuration config = new Configuration();
58 config.put(WemoBindingConstants.UDN, GenericWemoOSGiTest.DEVICE_UDN);
60 Bridge bridge = mock(Bridge.class);
61 when(bridge.getThingTypeUID()).thenReturn(WemoBindingConstants.THING_TYPE_BRIDGE);
62 when(bridge.getConfiguration()).thenReturn(config);
64 WemoBridgeHandler handler = mock(WemoBridgeHandler.class);
65 when(handler.getThing()).thenReturn(bridge);
67 WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall());
69 WemoLinkDiscoveryService discoveryService = new WemoLinkDiscoveryService(handler, upnpIOService, mockCaller);
70 discoveryService.startScan();
72 ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class);
73 verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture());
75 List<String> results = captur.getAllValues();
76 boolean found = false;
77 for (String result : results) {
79 "<u:GetEndDevices xmlns:u=\"urn:Belkin:service:bridge:1\"><DevUDN>uuid:Test-1_0-22124</DevUDN><ReqListType>PAIRED_LIST</ReqListType></u:GetEndDevices>")) {