]> git.basschouten.com Git - openhab-addons.git/blob
1ea6da258093a9db1dc2f28a54d7e2eea2ac2aa8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.luftdateninfo.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
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.luftdateninfo.internal.dto.SensorDataValue;
22 import org.openhab.binding.luftdateninfo.internal.handler.HTTPHandler;
23 import org.openhab.binding.luftdateninfo.internal.util.FileReader;
24
25 /**
26  * The {@link HTTPHandlerValueTest} test values decoding of HTTPHandler
27  *
28  * @author Bernd Weymann - Initial contribution
29  */
30 @NonNullByDefault
31 public class HTTPHandlerValueTest {
32     private HTTPHandler http = new HTTPHandler();
33
34     /**
35      * test if really the latest values are returned
36      * resource1 is json with ordering according to time while resource2 the entries flipped
37      */
38     @Test
39     public void testValueDecoding() {
40         String resource1 = FileReader.readFileInString("src/test/resources/condition-result-no-pressure.json");
41         assertNotNull(resource1);
42         List<SensorDataValue> l = http.getLatestValues(resource1);
43         assertNotNull(l);
44         l.forEach(sd -> {
45             testSensorValue(sd);
46         });
47
48         String resource2 = FileReader
49                 .readFileInString("src/test/resources/condition-result-no-pressure-flipped-values.json");
50         assertNotNull(resource2);
51         l = http.getLatestValues(resource2);
52         assertNotNull(l);
53         l.forEach(sd -> {
54             testSensorValue(sd);
55         });
56     }
57
58     private void testSensorValue(SensorDataValue s) {
59         if (s.getValueType().equals(HTTPHandler.TEMPERATURE)) {
60             assertEquals("22.70", s.getValue(), "Temperature resource 1");
61         } else if (s.getValueType().equals(HTTPHandler.HUMIDITY)) {
62             assertEquals("61.00", s.getValue(), "Humidity resource 1");
63         } else {
64             assertTrue(false);
65         }
66         // System.out.println(s.getValue_type() + ":" + s.getValue());
67     }
68 }