]> git.basschouten.com Git - openhab-addons.git/blob
04096675447958d4c6e57d826cfc4d6e996b0bca
[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.mercedesme;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.io.IOException;
18 import java.net.InetAddress;
19 import java.net.SocketException;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.mercedesme.internal.Constants;
24 import org.openhab.binding.mercedesme.internal.config.AccountConfiguration;
25 import org.openhab.binding.mercedesme.internal.server.Utils;
26
27 /**
28  * The {@link ConfigurationTest} Test configuration settings
29  *
30  * @author Bernd Weymann - Initial contribution
31  */
32 @NonNullByDefault
33 class ConfigurationTest {
34
35     @Test
36     void testScope() {
37         AccountConfiguration ac = new AccountConfiguration();
38         assertEquals(
39                 "openid offline_access mb:vehicle:mbdata:payasyoudrive mb:vehicle:mbdata:vehiclestatus mb:vehicle:mbdata:vehiclelock mb:vehicle:mbdata:fuelstatus mb:vehicle:mbdata:evstatus",
40                 ac.getScope());
41     }
42
43     @Test
44     void testApiUrlEndpoint() {
45         String url = Constants.FUEL_URL;
46         String[] endpoint = url.split("/");
47         String finalEndpoint = endpoint[endpoint.length - 1];
48         assertEquals("fuelstatus", finalEndpoint);
49     }
50
51     @Test
52     void testRound() {
53         int socValue = 66;
54         double batteryCapacity = 66.5;
55         float chargedValue = Math.round(socValue * 1000 * (float) batteryCapacity / 1000) / (float) 100;
56         assertEquals(43.89, chargedValue, 0.01);
57         float unchargedValue = Math.round((100 - socValue) * 1000 * (float) batteryCapacity / 1000) / (float) 100;
58         assertEquals(22.61, unchargedValue, 0.01);
59         assertEquals(batteryCapacity, chargedValue + unchargedValue, 0.01);
60     }
61
62     @Test
63     public void testCallbackUrl() throws SocketException {
64         String ip = Utils.getCallbackIP();
65         String message = "IP " + ip + " not reachable";
66         try {
67             assertTrue(InetAddress.getByName(ip).isReachable(10000), message);
68         } catch (IOException e) {
69             fail(message);
70         }
71     }
72 }