From 2bdce1ccf95152205d569b564085fdace0e70da6 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sun, 20 Oct 2024 18:57:35 +0200 Subject: [PATCH] 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 --- .../XsltTransformationServiceTest.java | 20 +++++++++++++++++-- .../xslt/internal}/google_weather.xsl | 0 pom.xml | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) rename bundles/org.openhab.transform.xslt/{conf/transform/http => src/test/resources/org/openhab/transform/xslt/internal}/google_weather.xsl (100%) 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 fd73a2acf71f3..40b8518f47343 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 @@ 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/conf/transform/http/google_weather.xsl b/bundles/org.openhab.transform.xslt/src/test/resources/org/openhab/transform/xslt/internal/google_weather.xsl similarity index 100% rename from bundles/org.openhab.transform.xslt/conf/transform/http/google_weather.xsl rename to bundles/org.openhab.transform.xslt/src/test/resources/org/openhab/transform/xslt/internal/google_weather.xsl diff --git a/pom.xml b/pom.xml index c760b31437a35..0b2c159a5dc6d 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