]> git.basschouten.com Git - openhab-addons.git/blob
cc2fc7c93f6f09f136a960cb1948202e7b75ae7b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.wemo.internal.discovery.test;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.ArgumentMatchers.any;
17 import static org.mockito.Mockito.*;
18
19 import java.io.IOException;
20 import java.net.MalformedURLException;
21 import java.net.URISyntaxException;
22 import java.util.List;
23
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;
37
38 /**
39  * Tests for {@link WemoLinkDiscoveryService}.
40  *
41  * @author Svilen Valkanov - Initial contribution
42  * @author Stefan Triller - Ported Tests from Groovy to Java
43  */
44 public class WemoLinkDiscoveryServiceOSGiTest extends GenericWemoLightOSGiTestParent {
45
46     @BeforeEach
47     public void setUp() throws IOException {
48         setUpServices();
49     }
50
51     @Test
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);
56
57         Configuration config = new Configuration();
58         config.put(WemoBindingConstants.UDN, GenericWemoOSGiTest.DEVICE_UDN);
59
60         Bridge bridge = mock(Bridge.class);
61         when(bridge.getThingTypeUID()).thenReturn(WemoBindingConstants.THING_TYPE_BRIDGE);
62         when(bridge.getConfiguration()).thenReturn(config);
63
64         WemoBridgeHandler handler = mock(WemoBridgeHandler.class);
65         when(handler.getThing()).thenReturn(bridge);
66
67         WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall());
68
69         WemoLinkDiscoveryService discoveryService = new WemoLinkDiscoveryService(handler, upnpIOService, mockCaller);
70         discoveryService.startScan();
71
72         ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class);
73         verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture());
74
75         List<String> results = captur.getAllValues();
76         boolean found = false;
77         for (String result : results) {
78             if (result.contains(
79                     "<u:GetEndDevices xmlns:u=\"urn:Belkin:service:bridge:1\"><DevUDN>uuid:Test-1_0-22124</DevUDN><ReqListType>PAIRED_LIST</ReqListType></u:GetEndDevices>")) {
80                 found = true;
81                 break;
82             }
83         }
84         assertTrue(found);
85     }
86 }