Skip to content

Commit

Permalink
Set openHAB system properties during tests (openhab#17592)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
wborn authored Oct 20, 2024
1 parent 273739f commit 2bdce1c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 2bdce1c

Please sign in to comment.