2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mercedesme;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.io.IOException;
18 import java.net.InetAddress;
19 import java.net.SocketException;
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;
28 * The {@link ConfigurationTest} Test configuration settings
30 * @author Bernd Weymann - Initial contribution
33 class ConfigurationTest {
37 AccountConfiguration ac = new AccountConfiguration();
39 "openid offline_access mb:vehicle:mbdata:payasyoudrive mb:vehicle:mbdata:vehiclestatus mb:vehicle:mbdata:vehiclelock mb:vehicle:mbdata:fuelstatus mb:vehicle:mbdata:evstatus",
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);
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);
63 public void testCallbackUrl() throws SocketException {
64 String ip = Utils.getCallbackIP();
65 String message = "IP " + ip + " not reachable";
67 assertTrue(InetAddress.getByName(ip).isReachable(10000), message);
68 } catch (IOException e) {