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 <github@maindrain.net>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Wouter Born 2024-10-20 18:57:35 +02:00 committed by Ciprian Pascu
parent 46f3e9aa8c
commit c8c40d44bd
3 changed files with 21 additions and 2 deletions

View 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);

View File

@ -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>