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.mybmw.internal.handler.backend;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.junit.jupiter.api.Assertions.assertFalse;
17 import static org.junit.jupiter.api.Assertions.assertNotNull;
19 import java.util.List;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.mybmw.internal.dto.charge.ChargingSessionsContainer;
24 import org.openhab.binding.mybmw.internal.dto.charge.ChargingStatisticsContainer;
25 import org.openhab.binding.mybmw.internal.dto.remote.ExecutionStatusContainer;
26 import org.openhab.binding.mybmw.internal.dto.vehicle.VehicleBase;
27 import org.openhab.binding.mybmw.internal.dto.vehicle.VehicleStateContainer;
28 import org.openhab.binding.mybmw.internal.util.FileReader;
30 import com.google.gson.Gson;
33 * This test checks if the file can be parsed correctly to the object. Additionally
34 * it can be used to check if there are properties in the files not mapped to the objects
35 * The output of Junit (at least in VSCode) shows the differences between the original file
36 * and the string generated by GSON to identify the gap.
38 * @author Martin Grassl - Initial contribution
41 public class JsonStringDeserializerTest {
43 Gson gson = new Gson();
45 void testGetChargeSessions() {
46 String content = FileReader.fileToString("responses/BEV/charging_sessions.json");
47 ChargingSessionsContainer chargeSessionsContainer = JsonStringDeserializer.getChargingSessions(content);
48 assertNotNull(chargeSessionsContainer);
52 void testGetChargeStatistics() {
53 String content = FileReader.fileToString("responses/BEV/charging_statistics.json");
54 ChargingStatisticsContainer chargeStatisticsContainer = JsonStringDeserializer.getChargingStatistics(content);
55 assertNotNull(chargeStatisticsContainer);
59 void testGetExecutionStatus() {
60 String content = FileReader.fileToString("responses/MILD_HYBRID/remote_service_status.json");
61 ExecutionStatusContainer executionStatusContainer = JsonStringDeserializer.getExecutionStatus(content);
62 assertNotNull(executionStatusContainer);
66 void testGetExecutionError() {
67 String content = FileReader.fileToString("responses/MILD_HYBRID/remote_service_error.json");
68 ExecutionStatusContainer executionStatusContainer = JsonStringDeserializer.getExecutionStatus(content);
69 assertNotNull(executionStatusContainer);
73 void testGetVehicleBaseList() {
74 String content = FileReader.fileToString("responses/BEV/vehicles_base.json");
75 List<VehicleBase> vehicleBases = JsonStringDeserializer.getVehicleBaseList(content);
76 assertNotNull(vehicleBases);
77 assertFalse(vehicleBases.isEmpty());
78 assertEquals(1, vehicleBases.size());
82 void testGetVehicleStateBEV() {
83 String content = FileReader.fileToString("responses/BEV/vehicles_state.json");
84 VehicleStateContainer vehicleStateContainer = JsonStringDeserializer.getVehicleState(content);
85 assertNotNull(vehicleStateContainer);
87 vehicleStateContainer.setRawStateJson(null);
88 String jsonString = gson.toJson(vehicleStateContainer);
89 assertNotNull(jsonString);
93 void testGetVehicleStateMILDHYBRID() {
94 String content = FileReader.fileToString("responses/MILD_HYBRID/vehicles_state.json");
95 VehicleStateContainer vehicleStateContainer = JsonStringDeserializer.getVehicleState(content);
96 assertNotNull(vehicleStateContainer);
100 void testGetVehicleStatePHEV() {
101 String content = FileReader.fileToString("responses/PHEV/vehicles_state.json");
102 VehicleStateContainer vehicleStateContainer = JsonStringDeserializer.getVehicleState(content);
103 assertNotNull(vehicleStateContainer);
107 void testGetVehicleStateICE() {
108 String content = FileReader.fileToString("responses/ICE/vehicles_state.json");
109 VehicleStateContainer vehicleStateContainer = JsonStringDeserializer.getVehicleState(content);
110 assertNotNull(vehicleStateContainer);