Skip to content

Commit

Permalink
Recycle ScriptScopeOSGiTest.java
Browse files Browse the repository at this point in the history
It got removed in openhab/openhab-core#2994

Signed-off-by: Wouter Born <[email protected]>
  • Loading branch information
wborn committed Dec 23, 2022
1 parent 2ec19d9 commit d04b3eb
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 2 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bundles/org.openhab.automation.jsscriptingnashorn/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand All @@ -12,7 +12,7 @@

<artifactId>org.openhab.automation.jsscriptingnashorn</artifactId>

<name>openHAB Add-ons :: Bundles :: Automation :: JSScripting Nashorn</name>
<name>openHAB Add-ons :: Bundles :: Automation :: JavaScript Scripting (Nashorn)</name>

<properties>
<bnd.importpackage>jdk.dynalink.*;resolution:=optional</bnd.importpackage>
Expand Down
13 changes: 13 additions & 0 deletions itests/org.openhab.automation.jsscriptingnashorn.tests/NOTICE
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)'
25 changes: 25 additions & 0 deletions itests/org.openhab.automation.jsscriptingnashorn.tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.openhab.addons.itests</groupId>
<artifactId>org.openhab.addons.reactor.itests</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.automation.jsscriptingnashorn.tests</artifactId>

<name>openHAB Add-ons :: Integration Tests :: JavaScript Scripting (Nashorn)</name>

<dependencies>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.automation.jsscriptingnashorn</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

if(FOOBAR === undefined && UnDefType.FOOBAR === undefined) {
throw "FOOBAR and UnDefType.FOOBAR not defined";
}
Original file line number Diff line number Diff line change
@@ -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";
}
Loading

0 comments on commit d04b3eb

Please sign in to comment.