]> git.basschouten.com Git - openhab-addons.git/blob
5ff8760a4a263363ccc6a768e9cb9ee64b4658f0
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.lcn.internal.pchkdiscovery;
14
15 import static org.hamcrest.MatcherAssert.assertThat;
16 import static org.hamcrest.Matchers.is;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
21
22 /**
23  * Test class for {@link LcnPchkDiscoveryService}.
24  *
25  * @author Fabian Wolter - Initial contribution
26  */
27 @NonNullByDefault
28 public class LcnPchkDiscoveryServiceTest {
29     private LcnPchkDiscoveryService s = new LcnPchkDiscoveryService();
30     private ServicesResponse r = s.xmlToServiceResponse(RESPONSE);
31     private static final String RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><ServicesResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"servicesresponse.xsd\"><Version major=\"1\" minor=\"0\" /><Server requestId=\"1548\" machineId=\"b8:27:eb:fe:a4:bb\" machineName=\"raspberrypi\" osShort=\"Unix/Linux\" osLong=\"Unix/Linux\">LCN-PCHK 3.2.2 running on Unix/Linux</Server><Services /><ExtServices><ExtService name=\"LcnPchkBus\" major=\"1\" minor=\"0\" prot=\"TCP\" localPort=\"4114\">PCHK 3.2.2 bus</ExtService></ExtServices></ServicesResponse>";
32
33     @BeforeEach
34     public void setUp() {
35         s = new LcnPchkDiscoveryService();
36         r = s.xmlToServiceResponse(RESPONSE);
37     }
38
39     @Test
40     public void testXmlMachineId() {
41         assertThat(r.getServer().getMachineId(), is("b8:27:eb:fe:a4:bb"));
42     }
43
44     @Test
45     public void testXmlMachineName() {
46         assertThat(r.getServer().getMachineName(), is("raspberrypi"));
47     }
48
49     @Test
50     public void testXmlServerContent() {
51         assertThat(r.getServer().getContent(), is("LCN-PCHK 3.2.2 running on Unix/Linux"));
52     }
53
54     @Test
55     public void testXmlPort() {
56         assertThat(r.getExtServices().getExtService().getLocalPort(), is(4114));
57     }
58 }