]> git.basschouten.com Git - openhab-addons.git/blob
db55983dfbab3cd284c9ebc0ea5975aeee49170a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.mybmw.internal.dto.vehicle;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.junit.jupiter.api.Assertions.assertNotNull;
17
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.mybmw.internal.handler.backend.JsonStringDeserializer;
20 import org.openhab.binding.mybmw.internal.util.FileReader;
21 import org.openhab.binding.mybmw.internal.utils.VehicleStatusUtils;
22 import org.openhab.core.library.types.DateTimeType;
23
24 import com.google.gson.Gson;
25
26 /**
27  * 
28  * checks basic data of state of vehicle
29  * 
30  * @author Bernd Weymann - Initial contribution
31  * @author Martin Grassl - refactoring
32  */
33 public class VehicleStateContainerTest {
34     @Test
35     public void testVehicleStateDeserializationByGson() {
36         String vehicleStateJson = FileReader.fileToString("responses/MILD_HYBRID/vehicles_state.json");
37         Gson gson = new Gson();
38
39         VehicleStateContainer vehicle = gson.fromJson(vehicleStateJson, VehicleStateContainer.class);
40
41         assertNotNull(vehicle);
42     }
43
44     @Test
45     public void testVehicleStateDeserializationByConverter() {
46         String vehicleStateJson = FileReader.fileToString("responses/MILD_HYBRID/vehicles_state.json");
47
48         VehicleStateContainer vehicleStateContainer = JsonStringDeserializer.getVehicleState(vehicleStateJson);
49
50         assertNotNull(vehicleStateContainer);
51         assertEquals("2024-06-01T00:00",
52                 ((DateTimeType) VehicleStatusUtils
53                         .getNextServiceDate(vehicleStateContainer.getState().getRequiredServices())).getZonedDateTime()
54                         .toLocalDateTime().toString(),
55                 "Service Date");
56
57         assertEquals("2022-12-21T15:41:23Z", vehicleStateContainer.getState().getLastUpdatedAt(), "Last update time");
58     }
59 }