]> git.basschouten.com Git - openhab-addons.git/blob
12e9f8201e776f33c245097eccc22ad353dc6d5c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.bmwconnecteddrive.internal.dto;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.bmwconnecteddrive.internal.dto.compat.VehicleAttributesContainer;
22 import org.openhab.binding.bmwconnecteddrive.internal.dto.status.CBSMessage;
23 import org.openhab.binding.bmwconnecteddrive.internal.dto.status.Position;
24 import org.openhab.binding.bmwconnecteddrive.internal.dto.status.VehicleStatus;
25 import org.openhab.binding.bmwconnecteddrive.internal.dto.status.VehicleStatusContainer;
26 import org.openhab.binding.bmwconnecteddrive.internal.util.FileReader;
27
28 import com.google.gson.Gson;
29
30 /**
31  * The {@link VehicleStatusTest} Test json responses from ConnectedDrive Portal
32  *
33  * @author Bernd Weymann - Initial contribution
34  */
35 @NonNullByDefault
36 @SuppressWarnings("null")
37 public class VehicleStatusTest {
38     private static final Gson GSON = new Gson();
39
40     @Test
41     public void testBevRexValues() {
42         String resource1 = FileReader.readFileInString("src/test/resources/webapi/vehicle-status.json");
43         VehicleStatusContainer status = GSON.fromJson(resource1, VehicleStatusContainer.class);
44         VehicleStatus vStatus = status.vehicleStatus;
45         assertEquals(17273.0, vStatus.mileage, 0.1, "Mileage");
46         Position p = vStatus.position;
47         assertEquals(219, p.heading, "Heading");
48
49         assertEquals("NA", vStatus.dcsCchActivation, "DCS Activation");
50         assertEquals(false, vStatus.dcsCchOngoing, "DCS Ongoing");
51     }
52
53     @Test
54     public void testServices() {
55         String resource1 = FileReader.readFileInString("src/test/resources/webapi/vehicle-status.json");
56         VehicleStatusContainer status = GSON.fromJson(resource1, VehicleStatusContainer.class);
57         VehicleStatus vStatus = status.vehicleStatus;
58         List<CBSMessage> services = vStatus.cbsData;
59         CBSMessage message = services.get(0);
60         assertEquals(15345, message.cbsRemainingMileage, "Service Mileage");
61         message = services.get(1);
62         assertEquals(-1, message.cbsRemainingMileage, "Service Mileage ");
63     }
64
65     @Test
66     public void testCompatibility() {
67         String resource = FileReader.readFileInString("src/test/resources/api/vehicle/vehicle-ccm.json");
68         VehicleAttributesContainer vac = GSON.fromJson(resource, VehicleAttributesContainer.class);
69         assertEquals("Laden nicht möglich", vac.vehicleMessages.ccmMessages.get(0).text, "CCM");
70         // Time Test to be removed - different Machines = different Time Zones
71         // VehicleStatusContainer vsc = GSON.fromJson(vac.transform(), VehicleStatusContainer.class);
72         // assertEquals("27.09.2020 13:18", vsc.vehicleStatus.getUpdateTime(), "UTC DateTime");
73         // String ldt = Converter.getLocalDateTime(vsc.vehicleStatus.getUpdateTime());
74         // assertEquals("2020-09-27T15:18:00", ldt.toString(), "Local DateTime");
75     }
76 }