2 * Copyright (c) 2010-2020 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.luftdateninfo.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.List;
18 import java.util.Objects;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.luftdateninfo.internal.dto.SensorDataValue;
23 import org.openhab.binding.luftdateninfo.internal.handler.HTTPHandler;
24 import org.openhab.binding.luftdateninfo.internal.util.FileReader;
27 * The {@link HTTPHandlerValueTest} test values decoding of HTTPHandler
29 * @author Bernd Weymann - Initial contribution
32 public class HTTPHandlerValueTest {
33 private HTTPHandler http = new HTTPHandler();
36 * test if really the latest values are returned
37 * resource1 is json with ordering according to time while resource2 the entries flipped
40 public void testValueDecoding() {
41 String resource1 = FileReader.readFileInString("src/test/resources/condition-result-no-pressure.json");
42 assertNotNull(resource1);
43 Objects.requireNonNull(resource1);
44 List<SensorDataValue> l = http.getLatestValues(resource1);
46 Objects.requireNonNull(l);
51 String resource2 = FileReader
52 .readFileInString("src/test/resources/condition-result-no-pressure-flipped-values.json");
53 assertNotNull(resource2);
54 Objects.requireNonNull(resource2);
55 l = http.getLatestValues(resource2);
57 Objects.requireNonNull(l);
63 private void testSensorValue(SensorDataValue s) {
64 if (s.getValueType().equals(HTTPHandler.TEMPERATURE)) {
65 assertEquals("22.70", s.getValue(), "Temperature resource 1");
66 } else if (s.getValueType().equals(HTTPHandler.HUMIDITY)) {
67 assertEquals("61.00", s.getValue(), "Humidity resource 1");
71 // System.out.println(s.getValue_type() + ":" + s.getValue());