]> git.basschouten.com Git - openhab-addons.git/blob
91515260fe2f4b1787859175be054b04bf7638f7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.network.internal;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.junit.jupiter.api.Assertions.*;
18
19 import org.junit.jupiter.api.Test;
20
21 /**
22  * Tests cases for {@see PresenceDetectionValue}
23  *
24  * @author David Graeff - Initial contribution
25  */
26 public class PresenceDetectionValuesTest {
27     @Test
28     public void updateLatencyTests() {
29         PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
30         assertThat(value.getLowestLatency(), is(10.0));
31         value.updateLatency(20.0);
32         assertThat(value.getLowestLatency(), is(10.0));
33         value.updateLatency(0.0);
34         assertThat(value.getLowestLatency(), is(10.0));
35         value.updateLatency(5.0);
36         assertThat(value.getLowestLatency(), is(5.0));
37     }
38
39     @Test
40     public void tcpTests() {
41         PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
42         assertFalse(value.isTCPServiceReachable());
43         value.addReachableTcpService(1010);
44         assertThat(value.getReachableTCPports(), hasItem(1010));
45         value.addType(PresenceDetectionType.TCP_CONNECTION);
46         assertTrue(value.isTCPServiceReachable());
47         assertThat(value.getSuccessfulDetectionTypes(), is("TCP_CONNECTION"));
48     }
49
50     @Test
51     public void isFinishedTests() {
52         PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
53         assertFalse(value.isFinished());
54         value.setDetectionIsFinished(true);
55         assertTrue(value.isFinished());
56     }
57
58     @Test
59     public void pingTests() {
60         PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
61         assertFalse(value.isPingReachable());
62         value.addType(PresenceDetectionType.ICMP_PING);
63         assertTrue(value.isPingReachable());
64
65         value.addType(PresenceDetectionType.ARP_PING);
66         value.addType(PresenceDetectionType.TCP_CONNECTION);
67         assertThat(value.getSuccessfulDetectionTypes(), is("ARP_PING, ICMP_PING, TCP_CONNECTION"));
68     }
69 }