Skip to content

Commit ca65ed2

Browse files
authored
[jsscripting] Add integration tests (#20517)
Signed-off-by: Florian Hotze <dev@florianhotze.com>
1 parent 2594d4f commit ca65ed2

9 files changed

Lines changed: 559 additions & 2 deletions

File tree

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@
508508
/bundles/org.openhab.voice.watsonstt/ @GiviMAD
509509
/bundles/org.openhab.voice.whisperstt/ @GiviMAD
510510
/itests/org.openhab.automation.groovyscripting.tests/ @wborn
511+
/itests/org.openhab.automation.jsscripting.tests/ @florian-h05
511512
/itests/org.openhab.automation.jsscriptingnashorn.tests/ @wborn
512-
/itests/org.openhab.binding.astro.tests/ @gerrieg
513513
/itests/org.openhab.binding.avmfritz.tests/ @cweitkamp
514514
/itests/org.openhab.binding.feed.tests/ @openhab/add-ons-maintainers
515515
/itests/org.openhab.binding.homeassistant.tests/ @ccutrer

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ mvn clean install -DwithResolver -DskipChecks
153153

154154
The build generates a `.jar` file per bundle in the respective bundle `/target` directory.
155155

156+
#### Troubleshooting
157+
158+
When having issues with running the integration tests, try the following steps:
159+
160+
1. Clear the bnd cache: Remove the `~/.bnd` directory.
161+
1. Rebuild the `bom` index: Execute `mvn clean install` in the [`bom`](bom) directory.
162+
1. Rebuild the `itests` index: Execute `mvn clean install -N` in the [`itests`](itests) directory.
163+
156164
### How to develop via an Integrated Development Environment (IDE)
157165

158166
We have assembled some step-by-step guides for different IDEs on our developer documentation website:

bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* @author Jonathan Gilbert - Initial contribution
3939
* @author Florian Hotze - Improve logger name, Fix memory leak caused by exception logging
4040
*/
41-
class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable & AutoCloseable & Compilable & Lock>
41+
public class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable & AutoCloseable & Compilable & Lock>
4242
extends InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable<T> implements Lock {
4343

4444
private static final int STACK_TRACE_LENGTH = 5;
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
-include: ../itest-common.bndrun
2+
3+
Bundle-SymbolicName: ${project.artifactId}
4+
Fragment-Host: org.openhab.automation.jsscripting
5+
6+
Import-Package: \
7+
*
8+
9+
-runrequires: \
10+
bnd.identity;id='org.openhab.automation.jsscripting.tests',\
11+
bnd.identity;id='org.graalvm.js.js-language',\
12+
bnd.identity;id='org.graalvm.regex.regex'
13+
14+
-runblacklist: \
15+
bnd.identity;id='org.openhab.core.storage.json'
16+
17+
#
18+
# done
19+
#
20+
21+
-runbundles: \
22+
biz.aQute.tester.junit-platform;version='[7.2.1,7.2.2)',\
23+
ch.qos.logback.classic;version='[1.5.27,1.5.28)',\
24+
ch.qos.logback.core;version='[1.5.27,1.5.28)',\
25+
com.fasterxml.jackson.core.jackson-annotations;version='[2.21.0,2.21.1)',\
26+
com.fasterxml.jackson.core.jackson-core;version='[2.21.1,2.21.2)',\
27+
com.fasterxml.jackson.core.jackson-databind;version='[2.21.1,2.21.2)',\
28+
com.fasterxml.jackson.dataformat.jackson-dataformat-xml;version='[2.21.1,2.21.2)',\
29+
com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.21.1,2.21.2)',\
30+
com.google.gson;version='[2.13.2,2.13.3)',\
31+
com.sun.jna;version='[5.18.1,5.18.2)',\
32+
com.sun.xml.bind.jaxb-osgi;version='[2.3.9,2.3.10)',\
33+
de.focus_shift.jollyday-core;version='[1.8.1,1.8.2)',\
34+
de.focus_shift.jollyday-jackson;version='[1.8.1,1.8.2)',\
35+
io.methvin.directory-watcher;version='[0.19.1,0.19.2)',\
36+
jakarta.annotation-api;version='[2.1.1,2.1.2)',\
37+
jakarta.inject.jakarta.inject-api;version='[2.0.1,2.0.2)',\
38+
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
39+
javax.measure.unit-api;version='[2.2.0,2.2.1)',\
40+
junit-jupiter-api;version='[5.14.2,5.14.3)',\
41+
junit-jupiter-engine;version='[5.14.2,5.14.3)',\
42+
junit-platform-commons;version='[1.14.2,1.14.3)',\
43+
junit-platform-engine;version='[1.14.2,1.14.3)',\
44+
junit-platform-launcher;version='[1.14.2,1.14.3)',\
45+
net.bytebuddy.byte-buddy;version='[1.17.7,1.17.8)',\
46+
net.bytebuddy.byte-buddy-agent;version='[1.17.7,1.17.8)',\
47+
org.apache.aries.spifly.dynamic.bundle;version='[1.3.7,1.3.8)',\
48+
org.apache.felix.configadmin;version='[1.9.26,1.9.27)',\
49+
org.apache.felix.http.servlet-api;version='[1.2.0,1.2.1)',\
50+
org.apache.felix.scr;version='[2.2.6,2.2.7)',\
51+
org.apache.servicemix.specs.activation-api-1.2.1;version='[1.2.1,1.2.2)',\
52+
org.eclipse.equinox.event;version='[1.6.300,1.6.301)',\
53+
org.eclipse.jetty.http;version='[9.4.58,9.4.59)',\
54+
org.eclipse.jetty.io;version='[9.4.58,9.4.59)',\
55+
org.eclipse.jetty.security;version='[9.4.58,9.4.59)',\
56+
org.eclipse.jetty.server;version='[9.4.58,9.4.59)',\
57+
org.eclipse.jetty.servlet;version='[9.4.58,9.4.59)',\
58+
org.eclipse.jetty.util;version='[9.4.58,9.4.59)',\
59+
org.eclipse.jetty.util.ajax;version='[9.4.58,9.4.59)',\
60+
org.glassfish.hk2.osgi-resource-locator;version='[3.0.0,3.0.1)',\
61+
org.graalvm.js.js-language;version='[25.0.1,25.0.2)',\
62+
org.graalvm.js.js-scriptengine;version='[25.0.1,25.0.2)',\
63+
org.graalvm.polyglot.polyglot;version='[25.0.1,25.0.2)',\
64+
org.graalvm.sdk.collections;version='[25.0.1,25.0.2)',\
65+
org.graalvm.sdk.nativeimage;version='[25.0.1,25.0.2)',\
66+
org.graalvm.sdk.word;version='[25.0.1,25.0.2)',\
67+
org.graalvm.shadowed.icu4j;version='[25.0.1,25.0.2)',\
68+
org.graalvm.shadowed.xz;version='[25.0.1,25.0.2)',\
69+
org.graalvm.truffle.truffle-api;version='[25.0.1,25.0.2)',\
70+
org.graalvm.truffle.truffle-compiler;version='[25.0.1,25.0.2)',\
71+
org.graalvm.truffle.truffle-runtime;version='[25.0.1,25.0.2)',\
72+
org.graalvm.regex.regex;version='[25.0.1,25.0.2)',\
73+
org.hamcrest;version='[3.0.0,3.0.1)',\
74+
org.mockito.junit-jupiter;version='[5.21.0,5.21.1)',\
75+
org.mockito.mockito-core;version='[5.21.0,5.21.1)',\
76+
org.objectweb.asm;version='[9.9.0,9.9.1)',\
77+
org.objectweb.asm.commons;version='[9.6.0,9.6.1)',\
78+
org.objectweb.asm.tree;version='[9.6.0,9.6.1)',\
79+
org.objectweb.asm.tree.analysis;version='[9.6.0,9.6.1)',\
80+
org.objectweb.asm.util;version='[9.6.0,9.6.1)',\
81+
org.objenesis;version='[3.3.0,3.3.1)',\
82+
org.openhab.automation.jsscripting;version='[5.2.0,5.2.1)',\
83+
org.openhab.automation.jsscripting.tests;version='[5.2.0,5.2.1)',\
84+
org.openhab.core;version='[5.2.0,5.2.1)',\
85+
org.openhab.core.addon;version='[5.2.0,5.2.1)',\
86+
org.openhab.core.automation;version='[5.2.0,5.2.1)',\
87+
org.openhab.core.automation.module.script;version='[5.2.0,5.2.1)',\
88+
org.openhab.core.automation.module.script.rulesupport;version='[5.2.0,5.2.1)',\
89+
org.openhab.core.config.core;version='[5.2.0,5.2.1)',\
90+
org.openhab.core.ephemeris;version='[5.2.0,5.2.1)',\
91+
org.openhab.core.io.console;version='[5.2.0,5.2.1)',\
92+
org.openhab.core.semantics;version='[5.2.0,5.2.1)',\
93+
org.openhab.core.test;version='[5.2.0,5.2.1)',\
94+
org.openhab.core.thing;version='[5.2.0,5.2.1)',\
95+
org.openhab.core.transform;version='[5.2.0,5.2.1)',\
96+
org.opentest4j;version='[1.3.0,1.3.1)',\
97+
org.ops4j.pax.logging.pax-logging-api;version='[2.3.2,2.3.3)',\
98+
org.osgi.service.component;version='[1.5.1,1.5.2)',\
99+
org.osgi.service.component.annotations;version='[1.5.1,1.5.2)',\
100+
org.osgi.service.event;version='[1.4.1,1.4.2)',\
101+
org.osgi.util.function;version='[1.2.0,1.2.1)',\
102+
org.osgi.util.promise;version='[1.3.0,1.3.1)',\
103+
org.threeten.extra;version='[1.8.0,1.8.1)',\
104+
org.yaml.snakeyaml;version='[2.5.0,2.5.1)',\
105+
si-quantity;version='[2.2.3,2.2.4)',\
106+
si-units;version='[2.2.3,2.2.4)',\
107+
stax2-api;version='[4.2.2,4.2.3)',\
108+
tech.units.indriya;version='[2.2.3,2.2.4)',\
109+
uom-lib-common;version='[2.2.0,2.2.1)',\
110+
xstream;version='[1.4.21,1.4.22)'
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.openhab.addons.itests</groupId>
7+
<artifactId>org.openhab.addons.reactor.itests</artifactId>
8+
<version>5.2.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>org.openhab.automation.jsscripting.tests</artifactId>
12+
13+
<name>openHAB Add-ons :: Integration Tests :: JavaScript Scripting</name>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.openhab.addons.bundles</groupId>
18+
<artifactId>org.openhab.automation.jsscripting</artifactId>
19+
<version>${project.version}</version>
20+
</dependency>
21+
<!-- GraalVM dependencies -->
22+
<dependency>
23+
<groupId>org.openhab.osgiify</groupId>
24+
<artifactId>org.graalvm.polyglot.polyglot</artifactId>
25+
<version>${graalvm.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.openhab.osgiify</groupId>
29+
<artifactId>org.graalvm.js.js-scriptengine</artifactId>
30+
<version>${graalvm.version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.openhab.osgiify</groupId>
34+
<artifactId>org.graalvm.js.js-language</artifactId>
35+
<version>${graalvm.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.openhab.osgiify</groupId>
39+
<artifactId>org.graalvm.regex.regex</artifactId>
40+
<version>${graalvm.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.openhab.osgiify</groupId>
44+
<artifactId>org.graalvm.sdk.collections</artifactId>
45+
<version>${graalvm.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.openhab.osgiify</groupId>
49+
<artifactId>org.graalvm.sdk.nativeimage</artifactId>
50+
<version>${graalvm.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.openhab.osgiify</groupId>
54+
<artifactId>org.graalvm.sdk.jniutils</artifactId>
55+
<version>${graalvm.version}</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.openhab.osgiify</groupId>
59+
<artifactId>org.graalvm.sdk.word</artifactId>
60+
<version>${graalvm.version}</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.openhab.osgiify</groupId>
64+
<artifactId>org.graalvm.shadowed.icu4j</artifactId>
65+
<version>${graalvm.version}</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.openhab.osgiify</groupId>
69+
<artifactId>org.graalvm.shadowed.json</artifactId>
70+
<version>${graalvm.version}</version>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.openhab.osgiify</groupId>
74+
<artifactId>org.graalvm.shadowed.xz</artifactId>
75+
<version>${graalvm.version}</version>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.openhab.osgiify</groupId>
79+
<artifactId>org.graalvm.tools.chromeinspector-tool</artifactId>
80+
<version>${graalvm.version}</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.openhab.osgiify</groupId>
84+
<artifactId>org.graalvm.tools.profiler-tool</artifactId>
85+
<version>${graalvm.version}</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.openhab.osgiify</groupId>
89+
<artifactId>org.graalvm.truffle.truffle-api</artifactId>
90+
<version>${graalvm.version}</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.openhab.osgiify</groupId>
94+
<artifactId>org.graalvm.truffle.truffle-compiler</artifactId>
95+
<version>${graalvm.version}</version>
96+
</dependency>
97+
<dependency>
98+
<groupId>org.openhab.osgiify</groupId>
99+
<artifactId>org.graalvm.truffle.truffle-runtime</artifactId>
100+
<version>${graalvm.version}</version>
101+
</dependency>
102+
</dependencies>
103+
104+
</project>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2010-2026 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.automation.jsscripting;
14+
15+
import static org.mockito.Mockito.clearInvocations;
16+
import static org.mockito.Mockito.when;
17+
18+
import java.nio.file.Path;
19+
import java.util.Map;
20+
21+
import org.eclipse.jdt.annotation.NonNullByDefault;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.extension.ExtendWith;
25+
import org.junit.jupiter.api.io.TempDir;
26+
import org.mockito.Mock;
27+
import org.mockito.junit.jupiter.MockitoExtension;
28+
import org.mockito.junit.jupiter.MockitoSettings;
29+
import org.mockito.quality.Strictness;
30+
import org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory;
31+
import org.openhab.automation.jsscripting.internal.JSScriptServiceUtil;
32+
import org.openhab.automation.jsscripting.internal.fs.watch.JSDependencyTracker;
33+
import org.openhab.core.automation.module.script.action.ScriptExecution;
34+
import org.openhab.core.scheduler.Scheduler;
35+
import org.openhab.core.service.WatchService;
36+
import org.openhab.core.test.java.JavaOSGiTest;
37+
38+
/**
39+
* Base class for GraalJS-related tests.
40+
*
41+
* @author Florian Hotze - Initial contribution
42+
*/
43+
@ExtendWith(MockitoExtension.class)
44+
@MockitoSettings(strictness = Strictness.LENIENT)
45+
@NonNullByDefault
46+
public abstract class GraalJSOSGiTest extends JavaOSGiTest {
47+
static final String SCRIPT_TYPE = "application/javascript";
48+
static final String SCRIPT_FILE_EXTENSION = "js";
49+
50+
final Map<String, Object> config;
51+
52+
@TempDir
53+
@NonNullByDefault({})
54+
Path tempDir;
55+
56+
@Mock
57+
@NonNullByDefault({})
58+
WatchService watchService;
59+
@Mock
60+
@NonNullByDefault({})
61+
Scheduler scheduler;
62+
@Mock
63+
@NonNullByDefault({})
64+
ScriptExecution scriptExecution;
65+
66+
@NonNullByDefault({})
67+
JSScriptServiceUtil jsScriptServiceUtil;
68+
@NonNullByDefault({})
69+
JSDependencyTracker jsDependencyTracker;
70+
@NonNullByDefault({})
71+
GraalJSScriptEngineFactory scriptEngineFactory;
72+
73+
GraalJSOSGiTest() {
74+
config = Map.of();
75+
}
76+
77+
GraalJSOSGiTest(Map<String, Object> config) {
78+
this.config = config;
79+
}
80+
81+
@BeforeEach
82+
public void beforeEach() throws Exception {
83+
when(watchService.getWatchPath()).thenReturn(tempDir);
84+
85+
jsScriptServiceUtil = new JSScriptServiceUtil(scheduler, scriptExecution);
86+
jsDependencyTracker = new JSDependencyTracker(watchService);
87+
88+
scriptEngineFactory = new GraalJSScriptEngineFactory(jsScriptServiceUtil, jsDependencyTracker, config);
89+
}
90+
91+
@AfterEach
92+
public void afterEach() throws Exception {
93+
scriptEngineFactory.dispose();
94+
scriptEngineFactory = null;
95+
96+
jsDependencyTracker.deactivate();
97+
jsDependencyTracker = null;
98+
99+
clearInvocations(watchService, scheduler, scriptExecution);
100+
}
101+
}

0 commit comments

Comments
 (0)