2 * Copyright (c) 2010-2024 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.fmiweather;
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
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;
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;
33 * Tests for converting Request objects to URLs
35 * @author Sami Salonen - Initial contribution
38 public class FMIRequestTest {
41 public void testObservationRequestToUrl() {
42 ObservationRequest request = new ObservationRequest(new FMISID("101023"), 1552215664L, 1552215665L, 61);
43 assertThat(request.toUrl(),
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×tep=61&fmisid=101023\
47 ¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa\
52 public void testForecastRequestToUrl() {
53 ForecastRequest request = new ForecastRequest(new LatLon(new BigDecimal("9"), new BigDecimal("8")), 1552215664L,
55 assertThat(request.toUrl(),
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×tep=61&latlon=9,8\
59 ¶meters=Temperature,Humidity,WindDirection,WindSpeedMS,WindGust,Pressure,Precipitation1h,TotalCloudCover,WeatherSymbol3\
64 public void testCustomLocation() {
65 QueryParameter location = new QueryParameter() {
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"));
74 ObservationRequest request = new ObservationRequest(location, 1552215664L, 1552215665L, 61);
75 assertThat(request.toUrl(),
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×tep=61&lat=MYLAT&lon=FOO&special=x,y,z\
79 ¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa\