]> git.basschouten.com Git - openhab-addons.git/blob
4bbd9a13a0878a6922994750d7f59330342de720
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.fmiweather;
14
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
17
18 import java.math.BigDecimal;
19 import java.util.AbstractMap;
20 import java.util.Arrays;
21 import java.util.List;
22 import java.util.Map.Entry;
23
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.binding.fmiweather.internal.client.FMISID;
27 import org.openhab.binding.fmiweather.internal.client.ForecastRequest;
28 import org.openhab.binding.fmiweather.internal.client.LatLon;
29 import org.openhab.binding.fmiweather.internal.client.ObservationRequest;
30 import org.openhab.binding.fmiweather.internal.client.QueryParameter;
31
32 /**
33  * Tests for converting Request objects to URLs
34  *
35  * @author Sami Salonen - Initial contribution
36  */
37 @NonNullByDefault
38 public class FMIRequestTest {
39
40     @Test
41     public void testObservationRequestToUrl() {
42         ObservationRequest request = new ObservationRequest(new FMISID("101023"), 1552215664L, 1552215665L, 61);
43         assertThat(request.toUrl(),
44                 is("""
45                         https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage\
46                         &starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z&timestep=61&fmisid=101023\
47                         &parameters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa\
48                         """));
49     }
50
51     @Test
52     public void testForecastRequestToUrl() {
53         ForecastRequest request = new ForecastRequest(new LatLon(new BigDecimal("9"), new BigDecimal("8")), 1552215664L,
54                 1552215665L, 61);
55         assertThat(request.toUrl(),
56                 is("""
57                         https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::forecast::harmonie::surface::point::multipointcoverage\
58                         &starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z&timestep=61&latlon=9,8\
59                         &parameters=Temperature,Humidity,WindDirection,WindSpeedMS,WindGust,Pressure,Precipitation1h,TotalCloudCover,WeatherSymbol3\
60                         """));
61     }
62
63     @Test
64     public void testCustomLocation() {
65         QueryParameter location = new QueryParameter() {
66
67             @Override
68             public List<Entry<String, String>> toRequestParameters() {
69                 return Arrays.asList(new AbstractMap.SimpleImmutableEntry<>("lat", "MYLAT"),
70                         new AbstractMap.SimpleImmutableEntry<>("lon", "FOO"),
71                         new AbstractMap.SimpleImmutableEntry<>("special", "x,y,z"));
72             }
73         };
74         ObservationRequest request = new ObservationRequest(location, 1552215664L, 1552215665L, 61);
75         assertThat(request.toUrl(),
76                 is("""
77                         https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage\
78                         &starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z&timestep=61&lat=MYLAT&lon=FOO&special=x,y,z\
79                         &parameters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa\
80                         """));
81     }
82 }