From: Wouter Born Date: Sun, 20 Oct 2024 16:57:35 +0000 (+0200) Subject: Set openHAB system properties during tests (#17592) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=2bdce1ccf95152205d569b564085fdace0e70da6;p=openhab-addons.git Set openHAB system properties during tests (#17592) * Set openHAB system properties during tests This will make sure tests write data to './target/openhab/userdata' instead of './userdata' etc. Prevents new files from appearing whenever running the Mi IO Binding tests. Signed-off-by: Wouter Born --- diff --git a/bundles/org.openhab.transform.xslt/conf/transform/http/google_weather.xsl b/bundles/org.openhab.transform.xslt/conf/transform/http/google_weather.xsl deleted file mode 100644 index b0de623f5a..0000000000 --- a/bundles/org.openhab.transform.xslt/conf/transform/http/google_weather.xsl +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/bundles/org.openhab.transform.xslt/src/test/java/org/openhab/transform/xslt/internal/XsltTransformationServiceTest.java b/bundles/org.openhab.transform.xslt/src/test/java/org/openhab/transform/xslt/internal/XsltTransformationServiceTest.java index fd73a2acf7..40b8518f47 100644 --- a/bundles/org.openhab.transform.xslt/src/test/java/org/openhab/transform/xslt/internal/XsltTransformationServiceTest.java +++ b/bundles/org.openhab.transform.xslt/src/test/java/org/openhab/transform/xslt/internal/XsltTransformationServiceTest.java @@ -14,8 +14,15 @@ package org.openhab.transform.xslt.internal; import static org.junit.jupiter.api.Assertions.*; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.openhab.core.OpenHAB; import org.openhab.core.transform.TransformationException; /** @@ -25,13 +32,22 @@ public class XsltTransformationServiceTest extends AbstractTransformationService private XsltTransformationService processor; + private final Path transformHttpPath = Paths.get(OpenHAB.getConfigFolder()).resolve("transform/http"); + @BeforeEach - public void init() { + public void init() throws IOException { + if (!Files.exists(transformHttpPath)) { + Files.createDirectories(transformHttpPath); + } + processor = new XsltTransformationService(); } @Test - public void testTransformByXSLT() throws TransformationException { + public void testTransformByXSLT() throws TransformationException, IOException { + Files.copy(getClass().getResourceAsStream("google_weather.xsl"), + transformHttpPath.resolve("google_weather.xsl"), StandardCopyOption.REPLACE_EXISTING); + // method under test String transformedResponse = processor.transform("http/google_weather.xsl", source); diff --git a/bundles/org.openhab.transform.xslt/src/test/resources/org/openhab/transform/xslt/internal/google_weather.xsl b/bundles/org.openhab.transform.xslt/src/test/resources/org/openhab/transform/xslt/internal/google_weather.xsl new file mode 100644 index 0000000000..b0de623f5a --- /dev/null +++ b/bundles/org.openhab.transform.xslt/src/test/resources/org/openhab/transform/xslt/internal/google_weather.xsl @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/pom.xml b/pom.xml index c760b31437..0b2c159a5d 100644 --- a/pom.xml +++ b/pom.xml @@ -419,6 +419,9 @@ Import-Package: \\ 15 m + ${project.build.directory}/openhab/conf + ${project.build.directory}/openhab/runtime + ${project.build.directory}/openhab/userdata