You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2018/03/21 11:51:01 UTC

[sling-org-apache-sling-scripting-core] 02/02: SLING-7545 - add an integration test for that issue

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-core.git

commit 9b67b6c92655df89c3297df4c25895af4b70dc39
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Wed Mar 21 12:41:14 2018 +0100

    SLING-7545 - add an integration test for that issue
---
 .../impl/jsr223/Jsr223ScriptEngineBundleIT.java    | 91 ++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/src/test/java/org/apache/sling/scripting/core/impl/jsr223/Jsr223ScriptEngineBundleIT.java b/src/test/java/org/apache/sling/scripting/core/impl/jsr223/Jsr223ScriptEngineBundleIT.java
new file mode 100644
index 0000000..b2f7674
--- /dev/null
+++ b/src/test/java/org/apache/sling/scripting/core/impl/jsr223/Jsr223ScriptEngineBundleIT.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.scripting.core.impl.jsr223;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.inject.Inject;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptEngineManager;
+import org.apache.sling.scripting.core.it.ScriptingCoreTestSupport;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+
+/** Verify that adding a JSR223 script engine bundle causes the corresponding
+ *  ScriptEngineFactory service to be registered (SLING-7545)
+ */
+@RunWith(PaxExam.class)
+public class Jsr223ScriptEngineBundleIT  extends ScriptingCoreTestSupport{
+
+    @Inject
+    private BundleContext bundleContext;
+    
+    @Inject
+    private ScriptEngineManager scriptEngineManager;
+    
+    private final String TEST_BUNDLE_ID = "groovy-all";
+    private final String TEST_ENGINE_NAME = "Groovy Scripting Engine";
+
+    @Override
+    @Configuration
+    public Option[] configuration() {
+        final ArrayList<Option> result = new ArrayList<>();
+        for(Option o : super.configuration()) {
+            result.add(o);
+        }
+        result.add(mavenBundle().groupId("org.codehaus.groovy").artifactId(TEST_BUNDLE_ID).version("2.4.14"));
+        return result.toArray(new Option[result.size()]);
+    }
+
+    @Test
+    public void testScriptEngineFactoryPresent() throws InvalidSyntaxException {
+        
+        // The added bundle should be active
+        Bundle testBundle = null;
+        for(Bundle b : bundleContext.getBundles()) {
+            if(b.getSymbolicName().equals(TEST_BUNDLE_ID)) {
+                testBundle = b;
+            }
+        }
+        assertNotNull("Expecting bundle to be present:" + TEST_BUNDLE_ID, testBundle);
+        assertEquals("Expecting bundle to be active:" + TEST_BUNDLE_ID, Bundle.ACTIVE, testBundle.getState());
+        
+        // And the corresponding ScriptEngineFactory activated
+        ScriptEngineFactory testFactory = null;
+        List<ScriptEngineFactory> fac = scriptEngineManager.getEngineFactories();
+        for(ScriptEngineFactory f : fac) {
+            if(f.getEngineName().equals(TEST_ENGINE_NAME)) {
+                testFactory = f;
+            }
+        }
+        assertNotNull(
+                "Expecting ScriptEngineFactory to be active: " + TEST_ENGINE_NAME, 
+                testFactory);
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
bdelacretaz@apache.org.