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