From d04b3ebd7d28a5b39eeb8c77526d672a983fa6d1 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Fri, 23 Dec 2022 11:49:54 +0100 Subject: [PATCH] Recycle ScriptScopeOSGiTest.java It got removed in openhab/openhab-core#2994 Signed-off-by: Wouter Born --- CODEOWNERS | 1 + .../pom.xml | 4 +- .../NOTICE | 13 ++ .../itest.bndrun | 69 +++++++ .../pom.xml | 25 +++ .../ScriptScopeOSGiTest.java | 63 ++++++ .../automation/jsr223/scopeFailure.nashornjs | 5 + .../automation/jsr223/scopeWorking.nashornjs | 194 ++++++++++++++++++ itests/pom.xml | 1 + 9 files changed, 373 insertions(+), 2 deletions(-) create mode 100644 itests/org.openhab.automation.jsscriptingnashorn.tests/NOTICE create mode 100644 itests/org.openhab.automation.jsscriptingnashorn.tests/itest.bndrun create mode 100644 itests/org.openhab.automation.jsscriptingnashorn.tests/pom.xml create mode 100644 itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/java/org/openhab/automation/jsscriptingnashorn/ScriptScopeOSGiTest.java create mode 100644 itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/resources/OH-INF/automation/jsr223/scopeFailure.nashornjs create mode 100644 itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/resources/OH-INF/automation/jsr223/scopeWorking.nashornjs diff --git a/CODEOWNERS b/CODEOWNERS index 390f8f1eb214b..8a82b49aa7d0a 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -415,6 +415,7 @@ /bundles/org.openhab.voice.voicerss/ @JochenHiller @lolodomo /bundles/org.openhab.voice.voskstt/ @GiviMAD /bundles/org.openhab.voice.watsonstt/ @GiviMAD +/itests/org.openhab.automation.jsscriptingnashorn.tests/ @wborn /itests/org.openhab.binding.astro.tests/ @gerrieg /itests/org.openhab.binding.avmfritz.tests/ @cweitkamp /itests/org.openhab.binding.feed.tests/ @svilenvul diff --git a/bundles/org.openhab.automation.jsscriptingnashorn/pom.xml b/bundles/org.openhab.automation.jsscriptingnashorn/pom.xml index b0889b87f56af..45f0041690ceb 100644 --- a/bundles/org.openhab.automation.jsscriptingnashorn/pom.xml +++ b/bundles/org.openhab.automation.jsscriptingnashorn/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -12,7 +12,7 @@ org.openhab.automation.jsscriptingnashorn - openHAB Add-ons :: Bundles :: Automation :: JSScripting Nashorn + openHAB Add-ons :: Bundles :: Automation :: JavaScript Scripting (Nashorn) jdk.dynalink.*;resolution:=optional diff --git a/itests/org.openhab.automation.jsscriptingnashorn.tests/NOTICE b/itests/org.openhab.automation.jsscriptingnashorn.tests/NOTICE new file mode 100644 index 0000000000000..38d625e349232 --- /dev/null +++ b/itests/org.openhab.automation.jsscriptingnashorn.tests/NOTICE @@ -0,0 +1,13 @@ +This content is produced and maintained by the openHAB project. + +* Project home: https://www.openhab.org + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/openhab/openhab-addons diff --git a/itests/org.openhab.automation.jsscriptingnashorn.tests/itest.bndrun b/itests/org.openhab.automation.jsscriptingnashorn.tests/itest.bndrun new file mode 100644 index 0000000000000..ef5d722d1c174 --- /dev/null +++ b/itests/org.openhab.automation.jsscriptingnashorn.tests/itest.bndrun @@ -0,0 +1,69 @@ +-include: ../itest-common.bndrun + +Bundle-SymbolicName: ${project.artifactId} +Fragment-Host: org.openhab.automation.jsscriptingnashorn + +-runrequires: \ + bnd.identity;id='org.openhab.automation.jsscriptingnashorn.tests',\ + bnd.identity;id='org.openhab.core',\ + bnd.identity;id='org.openhab.automation.jsscriptingnashorn' + +# We would like to use the "volatile" storage only +-runblacklist: \ + bnd.identity;id='org.openhab.core.storage.json' + +# +# done +# +-runbundles: \ + org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\ + org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\ + org.osgi.service.event;version='[1.4.0,1.4.1)',\ + org.hamcrest;version='[2.2.0,2.2.1)',\ + org.opentest4j;version='[1.2.0,1.2.1)',\ + com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\ + jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\ + org.apache.servicemix.specs.activation-api-1.2.1;version='[1.2.1,1.2.2)',\ + org.glassfish.hk2.osgi-resource-locator;version='[1.0.3,1.0.4)',\ + jakarta.annotation-api;version='[2.0.0,2.0.1)',\ + jakarta.inject.jakarta.inject-api;version='[2.0.0,2.0.1)',\ + javax.measure.unit-api;version='[2.1.2,2.1.3)',\ + org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\ + org.jsr-305;version='[3.0.2,3.0.3)',\ + tech.units.indriya;version='[2.1.2,2.1.3)',\ + uom-lib-common;version='[2.1.0,2.1.1)',\ + si-units;version='[2.1.0,2.1.1)',\ + si.uom.si-quantity;version='[2.1.0,2.1.1)',\ + junit-jupiter-api;version='[5.8.1,5.8.2)',\ + junit-jupiter-engine;version='[5.8.1,5.8.2)',\ + junit-platform-commons;version='[1.8.1,1.8.2)',\ + junit-platform-engine;version='[1.8.1,1.8.2)',\ + junit-platform-launcher;version='[1.8.1,1.8.2)',\ + org.apache.felix.scr;version='[2.1.30,2.1.31)',\ + org.osgi.util.function;version='[1.2.0,1.2.1)',\ + org.osgi.util.promise;version='[1.2.0,1.2.1)',\ + org.eclipse.jetty.http;version='[9.4.46,9.4.47)',\ + org.eclipse.jetty.io;version='[9.4.46,9.4.47)',\ + org.eclipse.jetty.security;version='[9.4.46,9.4.47)',\ + org.eclipse.jetty.server;version='[9.4.46,9.4.47)',\ + org.eclipse.jetty.servlet;version='[9.4.46,9.4.47)',\ + org.eclipse.jetty.util;version='[9.4.46,9.4.47)',\ + org.eclipse.jetty.util.ajax;version='[9.4.46,9.4.47)',\ + org.ops4j.pax.logging.pax-logging-api;version='[2.0.16,2.0.17)',\ + ch.qos.logback.classic;version='[1.2.11,1.2.12)',\ + ch.qos.logback.core;version='[1.2.11,1.2.12)',\ + biz.aQute.tester.junit-platform;version='[6.4.0,6.4.1)',\ + org.openhab.core;version='[4.0.0,4.0.1)',\ + org.openhab.core.config.core;version='[4.0.0,4.0.1)',\ + org.openhab.core.test;version='[4.0.0,4.0.1)',\ + com.google.gson;version='[2.9.1,2.9.2)',\ + jollyday;version='[0.5.10,0.5.11)',\ + org.openhab.automation.jsscriptingnashorn;version='[4.0.0,4.0.1)',\ + org.openhab.automation.jsscriptingnashorn.tests;version='[4.0.0,4.0.1)',\ + org.openhab.core.automation;version='[4.0.0,4.0.1)',\ + org.openhab.core.automation.module.script;version='[4.0.0,4.0.1)',\ + org.openhab.core.ephemeris;version='[4.0.0,4.0.1)',\ + org.openhab.core.io.console;version='[4.0.0,4.0.1)',\ + org.openhab.core.thing;version='[4.0.0,4.0.1)',\ + org.openhab.core.transform;version='[4.0.0,4.0.1)',\ + org.threeten.extra;version='[1.5.0,1.5.1)' diff --git a/itests/org.openhab.automation.jsscriptingnashorn.tests/pom.xml b/itests/org.openhab.automation.jsscriptingnashorn.tests/pom.xml new file mode 100644 index 0000000000000..6f45ca6d05b61 --- /dev/null +++ b/itests/org.openhab.automation.jsscriptingnashorn.tests/pom.xml @@ -0,0 +1,25 @@ + + + + 4.0.0 + + + org.openhab.addons.itests + org.openhab.addons.reactor.itests + 4.0.0-SNAPSHOT + + + org.openhab.automation.jsscriptingnashorn.tests + + openHAB Add-ons :: Integration Tests :: JavaScript Scripting (Nashorn) + + + + org.openhab.addons.bundles + org.openhab.automation.jsscriptingnashorn + ${project.version} + + + + diff --git a/itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/java/org/openhab/automation/jsscriptingnashorn/ScriptScopeOSGiTest.java b/itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/java/org/openhab/automation/jsscriptingnashorn/ScriptScopeOSGiTest.java new file mode 100644 index 0000000000000..0260fd4eccdbd --- /dev/null +++ b/itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/java/org/openhab/automation/jsscriptingnashorn/ScriptScopeOSGiTest.java @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.automation.jsscriptingnashorn; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; + +import javax.script.ScriptEngine; +import javax.script.ScriptException; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openhab.core.automation.module.script.ScriptEngineContainer; +import org.openhab.core.automation.module.script.ScriptEngineManager; +import org.openhab.core.test.java.JavaOSGiTest; + +/** + * This tests the script modules using the Nashorn scripting engine. + * + * @author Kai Kreuzer - Initial contribution + */ +@NonNullByDefault +public class ScriptScopeOSGiTest extends JavaOSGiTest { + + private @NonNullByDefault({}) ScriptEngine engine; + + private final String path = "OH-INF/automation/jsr223/"; + private final String workingFile = "scopeWorking.nashornjs"; + private final String failureFile = "scopeFailure.nashornjs"; + + @BeforeEach + public void init() { + ScriptEngineManager scriptManager = getService(ScriptEngineManager.class); + ScriptEngineContainer container = scriptManager.createScriptEngine("nashornjs", "myJSEngine"); + engine = container.getScriptEngine(); + } + + @Test + public void testScopeDefinesItemTypes() throws ScriptException, IOException { + URL url = bundleContext.getBundle().getResource(path + workingFile); + engine.eval(new InputStreamReader(url.openStream())); + } + + @Test + public void testScopeDoesNotDefineFoobar() throws ScriptException, IOException { + URL url = bundleContext.getBundle().getResource(path + failureFile); + assertThrows(ScriptException.class, () -> engine.eval(new InputStreamReader(url.openStream()))); + } +} diff --git a/itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/resources/OH-INF/automation/jsr223/scopeFailure.nashornjs b/itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/resources/OH-INF/automation/jsr223/scopeFailure.nashornjs new file mode 100644 index 0000000000000..1fe2820b333db --- /dev/null +++ b/itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/resources/OH-INF/automation/jsr223/scopeFailure.nashornjs @@ -0,0 +1,5 @@ +'use strict'; + +if(FOOBAR === undefined && UnDefType.FOOBAR === undefined) { + throw "FOOBAR and UnDefType.FOOBAR not defined"; +} diff --git a/itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/resources/OH-INF/automation/jsr223/scopeWorking.nashornjs b/itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/resources/OH-INF/automation/jsr223/scopeWorking.nashornjs new file mode 100644 index 0000000000000..d0cd6ba536c64 --- /dev/null +++ b/itests/org.openhab.automation.jsscriptingnashorn.tests/src/main/resources/OH-INF/automation/jsr223/scopeWorking.nashornjs @@ -0,0 +1,194 @@ +'use strict'; + +if(State === undefined) { + throw "State not defined"; +} + +if(Command === undefined) { + throw "Command not defined"; +} + +if(URLEncoder === undefined) { + throw "URLEncoder not defined"; +} + +if(File === undefined) { + throw "File not defined"; +} + +if(Files === undefined) { + throw "Files not defined"; +} + +if(Path === undefined) { + throw "Path not defined"; +} + +if(Paths === undefined) { + throw "Paths not defined"; +} + +//types +if(IncreaseDecreaseType === undefined) { + throw "IncreaseDecreaseType not defined"; +} + +if(DECREASE === undefined) { + throw "DECREASE not defined"; +} + +if(INCREASE === undefined) { + throw "INCREASE not defined"; +} + +if(OnOffType === undefined) { + throw "OnOffType not defined"; +} + +if(ON === undefined) { + throw "OFF not defined"; +} + +if(OpenClosedType === undefined) { + throw "OpenClosedType not defined"; +} + +if(CLOSED === undefined) { + throw "CLOSED not defined"; +} + +if(OPEN === undefined) { + throw "OPEN not defined"; +} + +if(StopMoveType === undefined) { + throw "StopMoveType not defined"; +} + +if(MOVE === undefined) { + throw "MOVE not defined"; +} + +if(STOP === undefined) { + throw "STOP not defined"; +} + +if(UpDownType === undefined) { + throw "UpDownType not defined"; +} + +if(DOWN === undefined) { + throw "DOWN not defined"; +} + +if(UP === undefined) { + throw "UP not defined"; +} + +if(UnDefType === undefined) { + throw "UnDefType not defined"; +} + +if(NULL === undefined) { + throw "NULL not defined"; +} + +if(NextPreviousType === undefined) { + throw "NextPreviousType not defined"; +} + +if(NEXT === undefined) { + throw "NEXT not defined"; +} + +if(PREVIOUS === undefined) { + throw "PREVIOUS not defined"; +} + +if(PlayPauseType === undefined) { + throw "PlayPauseType not defined"; +} + +if(PLAY === undefined) { + throw "PLAY not defined"; +} + +if(PAUSE === undefined) { + throw "PAUSE not defined"; +} + +if(RewindFastforwardType === undefined) { + throw "RewindFastforwardType not defined"; +} + +if(REWIND === undefined) { + throw "REWIND not defined"; +} + +if(FASTFORWARD === undefined) { + throw "FASTFORWARD not defined"; +} + +if(QuantityType === undefined) { + throw "QuantityType not defined"; +} + +if(StringListType === undefined) { + throw "StringListType not defined"; +} + +if(RawType === undefined) { + throw "RawType not defined"; +} + +if(DateTimeType === undefined) { + throw "DateTimeType not defined"; +} + +if(DecimalType === undefined) { + throw "DecimalType not defined"; +} + +if(DateTimeType === undefined) { + throw "DateTimeType not defined"; +} + +if(HSBType === undefined) { + throw "HSBType not defined"; +} + +if(PercentType === undefined) { + throw "PercentType not defined"; +} + +if(PointType === undefined) { + throw "PointType not defined"; +} + +if(StringType === undefined) { + throw "StringType not defined"; +} + +if(items === undefined) { + throw "items not defined"; +} + +if(ir === undefined) { + throw "ir not defined"; +} + +if(itemRegistry === undefined) { + throw "itemRegistry not defined"; +} + +if(things === undefined) { + throw "things not defined"; +} + +if(events === undefined) { + throw "events not defined"; +} + +if(rules === undefined) { + throw "rules not defined"; +} diff --git a/itests/pom.xml b/itests/pom.xml index 09e2f785879b8..d83e3e60fda1c 100644 --- a/itests/pom.xml +++ b/itests/pom.xml @@ -17,6 +17,7 @@ openHAB Add-ons :: Integration Tests + org.openhab.automation.jsscriptingnashorn.tests org.openhab.binding.astro.tests org.openhab.binding.avmfritz.tests org.openhab.binding.feed.tests