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.dto.vehicle;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.junit.jupiter.api.Assertions.assertNotNull;
18 import java.util.List;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.mybmw.internal.handler.backend.JsonStringDeserializer;
23 import org.openhab.binding.mybmw.internal.util.FileReader;
24 import org.openhab.binding.mybmw.internal.utils.Constants;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.google.gson.Gson;
30 import ch.qos.logback.classic.Level;
34 * checks the vehicleBase response
36 * @author Martin Grassl - Initial contribution
38 public class VehicleBaseTest {
40 private Logger logger = LoggerFactory.getLogger(VehicleBaseTest.class);
43 public void setupLogger() {
44 Logger root = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
46 if ("debug".equals(System.getenv("LOG_LEVEL"))) {
47 ((ch.qos.logback.classic.Logger) root).setLevel(Level.DEBUG);
48 } else if ("trace".equals(System.getenv("LOG_LEVEL"))) {
49 ((ch.qos.logback.classic.Logger) root).setLevel(Level.TRACE);
52 logger.trace("tracing enabled");
53 logger.debug("debugging enabled");
54 logger.info("info enabled");
58 public void testVehicleBaseDeserializationByGson() {
59 String vehicleBaseJson = FileReader.fileToString("responses/MILD_HYBRID/vehicles_base.json");
60 Gson gson = new Gson();
62 VehicleBase[] vehicleBaseArray = gson.fromJson(vehicleBaseJson, VehicleBase[].class);
64 assertNotNull(vehicleBaseArray);
68 public void testVehicleBaseDeserializationByConverter() {
69 String vehicleBaseJson = FileReader.fileToString("responses/MILD_HYBRID/vehicles_base.json");
71 List<VehicleBase> vehicleBaseList = JsonStringDeserializer.getVehicleBaseList(vehicleBaseJson);
73 assertNotNull(vehicleBaseList);
75 assertEquals(1, vehicleBaseList.size(), "Number of Vehicles");
76 VehicleBase vehicle = vehicleBaseList.get(0);
77 assertEquals(Constants.ANONYMOUS + "MILD_HYBRID", vehicle.getVin(), "VIN");
78 assertEquals("M340i xDrive", vehicle.getAttributes().getModel(), "Model");
79 assertEquals(Constants.DRIVETRAIN_MILD_HYBRID, vehicle.getAttributes().getDriveTrain(), "DriveTrain");
80 assertEquals("bmw", vehicle.getAttributes().getBrand(), "Brand");
81 assertEquals(2022, vehicle.getAttributes().getYear(), "Year of Construction");