]> git.basschouten.com Git - openhab-addons.git/commitdiff
Set openHAB system properties during tests (#17592)
authorWouter Born <github@maindrain.net>
Sun, 20 Oct 2024 16:57:35 +0000 (18:57 +0200)
committerGitHub <noreply@github.com>
Sun, 20 Oct 2024 16:57:35 +0000 (18:57 +0200)
* 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 <github@maindrain.net>
bundles/org.openhab.transform.xslt/conf/transform/http/google_weather.xsl [deleted file]
bundles/org.openhab.transform.xslt/src/test/java/org/openhab/transform/xslt/internal/XsltTransformationServiceTest.java
bundles/org.openhab.transform.xslt/src/test/resources/org/openhab/transform/xslt/internal/google_weather.xsl [new file with mode: 0644]
pom.xml

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 (file)
index b0de623..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-
-       <xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />
-
-       <xsl:template match="//current_conditions">
-               <xsl:value-of select="temp_c/@data" />
-       </xsl:template>
-       
-</xsl:stylesheet>
index fd73a2acf71f3a2440f5433a4bc83533f7913887..40b8518f47343cb296475f69f0b4fe089d93efce 100644 (file)
@@ -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 (file)
index 0000000..b0de623
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+       <xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />
+
+       <xsl:template match="//current_conditions">
+               <xsl:value-of select="temp_c/@data" />
+       </xsl:template>
+       
+</xsl:stylesheet>
diff --git a/pom.xml b/pom.xml
index c760b31437a350e423dffe05bf24ae1ed61ca0ef..0b2c159a5dc6d5207a82b329068a698b71581167 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -419,6 +419,9 @@ Import-Package: \\
             </argLine>
             <systemPropertyVariables>
               <junit.jupiter.execution.timeout.default>15 m</junit.jupiter.execution.timeout.default>
+              <openhab.conf>${project.build.directory}/openhab/conf</openhab.conf>
+              <openhab.runtime>${project.build.directory}/openhab/runtime</openhab.runtime>
+              <openhab.userdata>${project.build.directory}/openhab/userdata</openhab.userdata>
             </systemPropertyVariables>
           </configuration>
         </plugin>