]> git.basschouten.com Git - openhab-addons.git/blob
1aa631fc3484206eefe53c9ceac58dec70db2b60
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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(), is(
44                 "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage"
45                         + "&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z&timestep=61&fmisid=101023"
46                         + "&parameters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa"));
47     }
48
49     @Test
50     public void testForecastRequestToUrl() {
51         ForecastRequest request = new ForecastRequest(new LatLon(new BigDecimal("9"), new BigDecimal("8")), 1552215664L,
52                 1552215665L, 61);
53         assertThat(request.toUrl(), is(
54                 "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::forecast::harmonie::surface::point::multipointcoverage"
55                         + "&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z&timestep=61&latlon=9,8"
56                         + "&parameters=Temperature,Humidity,WindDirection,WindSpeedMS,WindGust,Pressure,Precipitation1h,TotalCloudCover,WeatherSymbol3"));
57     }
58
59     @Test
60     public void testCustomLocation() {
61         QueryParameter location = new QueryParameter() {
62
63             @Override
64             public List<Entry<String, String>> toRequestParameters() {
65                 return Arrays.asList(new AbstractMap.SimpleImmutableEntry<>("lat", "MYLAT"),
66                         new AbstractMap.SimpleImmutableEntry<>("lon", "FOO"),
67                         new AbstractMap.SimpleImmutableEntry<>("special", "x,y,z"));
68             }
69         };
70         ObservationRequest request = new ObservationRequest(location, 1552215664L, 1552215665L, 61);
71         assertThat(request.toUrl(), is(
72                 "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage"
73                         + "&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z&timestep=61&lat=MYLAT&lon=FOO&special=x,y,z"
74                         + "&parameters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa"));
75     }
76 }