forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dwdunwetter] Improve server problem handling (openhab#15405)
* Fix openhab#14691 * Add country tag --------- Signed-off-by: lsiepel <leosiepel@gmail.com> Signed-off-by: Leo Siepel <leosiepel@gmail.com> Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
- Loading branch information
Showing
5 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...src/test/java/org/openhab/binding/dwdunwetter/internal/dto/DwdWarningsDataAccessTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.dwdunwetter.internal.dto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.StringWriter; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests for {@link org.openhab.binding.dwdunwetter.internal.dto.DwdWarningsDataAccess} | ||
* | ||
* @author Leo Siepel - Initial contribution | ||
*/ | ||
public class DwdWarningsDataAccessTest { | ||
private TestDataProvider testDataProvider = new TestDataProvider(); | ||
|
||
@BeforeEach | ||
public void setUp() throws IOException { | ||
this.testDataProvider = new TestDataProvider(); | ||
loadXmlFromFile(); | ||
} | ||
|
||
@Test | ||
public void testNullOrBlank() { | ||
assertEquals(testDataProvider.getDataFromEndpoint(null), ""); | ||
assertEquals(testDataProvider.getDataFromEndpoint(""), ""); | ||
} | ||
|
||
@Test | ||
public void testInvalidResponse() { | ||
TestDataProvider testDataProvider = new TestDataProvider(); | ||
testDataProvider.rawData = "Server is not returning xml"; | ||
assertEquals(testDataProvider.getDataFromEndpoint("TestCity"), ""); | ||
} | ||
|
||
private void loadXmlFromFile() throws IOException { | ||
InputStream stream = getClass().getResourceAsStream("warnings.xml"); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); | ||
String line = null; | ||
|
||
StringWriter stringWriter = new StringWriter(); | ||
while ((line = reader.readLine()) != null) { | ||
stringWriter.write(line); | ||
} | ||
reader.close(); | ||
testDataProvider.rawData = stringWriter.toString(); | ||
} | ||
|
||
private class TestDataProvider extends DwdWarningDataAccess { | ||
|
||
private String rawData = ""; | ||
|
||
@Override | ||
public String getByURL(String url) { | ||
return rawData; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters