2 * Copyright (c) 2010-2023 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.dwdunwetter.internal.dto;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import java.io.BufferedReader;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.InputStreamReader;
21 import java.io.StringWriter;
22 import java.nio.charset.StandardCharsets;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
28 * Tests for {@link org.openhab.binding.dwdunwetter.internal.dto.DwdWarningsDataAccess}
30 * @author Leo Siepel - Initial contribution
32 public class DwdWarningsDataAccessTest {
33 private TestDataProvider testDataProvider = new TestDataProvider();
36 public void setUp() throws IOException {
37 this.testDataProvider = new TestDataProvider();
42 public void testNullOrBlank() {
43 assertEquals(testDataProvider.getDataFromEndpoint(null), "");
44 assertEquals(testDataProvider.getDataFromEndpoint(""), "");
48 public void testInvalidResponse() {
49 TestDataProvider testDataProvider = new TestDataProvider();
50 testDataProvider.rawData = "Server is not returning xml";
51 assertEquals(testDataProvider.getDataFromEndpoint("TestCity"), "");
54 private void loadXmlFromFile() throws IOException {
55 InputStream stream = getClass().getResourceAsStream("warnings.xml");
56 BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
59 StringWriter stringWriter = new StringWriter();
60 while ((line = reader.readLine()) != null) {
61 stringWriter.write(line);
64 testDataProvider.rawData = stringWriter.toString();
67 private class TestDataProvider extends DwdWarningDataAccess {
69 private String rawData = "";
72 public String getByURL(String url) {