You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2019/09/15 14:12:26 UTC
[sling-org-apache-sling-scripting-core] 01/02: polish integration
tests and prepare support for extension
This is an automated email from the ASF dual-hosted git repository.
olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-core.git
commit 0fcb3deb06a6c6c999cd23bb8505607137bface6
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sun Sep 15 15:57:58 2019 +0200
polish integration tests and prepare support for extension
---
pom.xml | 13 ++++
.../it/BindingsValuesProvidersByContextIT.java | 44 ++++++-------
.../core/it/Jsr223ScriptEngineBundleIT.java | 59 +++++++++--------
.../core/it/ScriptingCoreTestSupport.java | 76 +++++++++++++++-------
4 files changed, 115 insertions(+), 77 deletions(-)
diff --git a/pom.xml b/pom.xml
index e7d0e42..d35fe47 100644
--- a/pom.xml
+++ b/pom.xml
@@ -144,6 +144,12 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.resource.presence</artifactId>
+ <version>0.0.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.serviceusermapper</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
@@ -245,6 +251,13 @@
<version>1.9.5</version>
<scope>test</scope>
</dependency>
+ <!-- jsoup -->
+ <dependency>
+ <groupId>org.jsoup</groupId>
+ <artifactId>jsoup</artifactId>
+ <version>1.11.3</version>
+ <scope>test</scope>
+ </dependency>
<!-- testing -->
<dependency>
<groupId>junit</groupId>
diff --git a/src/test/java/org/apache/sling/scripting/core/it/BindingsValuesProvidersByContextIT.java b/src/test/java/org/apache/sling/scripting/core/it/BindingsValuesProvidersByContextIT.java
index b6cf688..31a18f8 100644
--- a/src/test/java/org/apache/sling/scripting/core/it/BindingsValuesProvidersByContextIT.java
+++ b/src/test/java/org/apache/sling/scripting/core/it/BindingsValuesProvidersByContextIT.java
@@ -18,17 +18,6 @@
*/
package org.apache.sling.scripting.core.it;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.ops4j.pax.exam.CoreOptions.bundle;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.provision;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.CoreOptions.when;
-
-import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -45,11 +34,11 @@ import javax.script.ScriptEngineFactory;
import org.apache.sling.scripting.api.BindingsValuesProvider;
import org.apache.sling.scripting.api.BindingsValuesProvidersByContext;
-import org.apache.sling.scripting.core.it.ScriptingCoreTestSupport;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.util.Filter;
@@ -57,8 +46,12 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.options;
+
@RunWith(PaxExam.class)
-public class BindingsValuesProvidersByContextIT extends ScriptingCoreTestSupport{
+public class BindingsValuesProvidersByContextIT extends ScriptingCoreTestSupport {
@Inject
@Filter(timeout = 300000)
@@ -76,18 +69,24 @@ public class BindingsValuesProvidersByContextIT extends ScriptingCoreTestSuppor
@After
public void cleanup() {
- for(ServiceRegistration reg : regs) {
+ for (ServiceRegistration reg : regs) {
reg.unregister();
}
}
+ @Configuration
+ public Option[] configuration() {
+ return options(
+ baseConfiguration()
+ );
+ }
private Dictionary<String, Object> getProperties(String context, String engineName) {
final Dictionary<String, Object> props = new Hashtable<String, Object>();
- if(context != null) {
+ if (context != null) {
props.put(BindingsValuesProvider.CONTEXT, context.split(","));
}
- if(engineName != null) {
+ if (engineName != null) {
props.put(ScriptEngine.NAME, engineName);
}
return props;
@@ -206,16 +205,16 @@ public class BindingsValuesProvidersByContextIT extends ScriptingCoreTestSuppor
private String asString(Collection<?> data, boolean sortList) {
final List<String> maybeSorted = new ArrayList<String>();
- for(Object o : data) {
+ for (Object o : data) {
maybeSorted.add(o.toString());
}
- if(sortList) {
+ if (sortList) {
Collections.sort(maybeSorted);
}
final StringBuilder sb = new StringBuilder();
- for(String str : maybeSorted) {
- if(sb.length() > 0) {
+ for (String str : maybeSorted) {
+ if (sb.length() > 0) {
sb.append(",");
}
sb.append(str);
@@ -248,7 +247,7 @@ public class BindingsValuesProvidersByContextIT extends ScriptingCoreTestSuppor
addBVP("foo", null, "js");
addBVP("bar", null, null);
addBVP("r1", "request", "js");
- addBVP("r2", "request", null);
+ addBVP("r2", "request", null);
addBVP("o1", "other", "js");
addBVP("o2", "other", null);
addBVP("o3", "other,request", null);
@@ -269,7 +268,7 @@ public class BindingsValuesProvidersByContextIT extends ScriptingCoreTestSuppor
addBVP("foo", null, "js");
addMap("bar", null, null);
addMap("r1", "request", "js");
- addMap("r2", "request", null);
+ addMap("r2", "request", null);
addMap("o1", "other", "js");
addBVP("o2", "other", null);
addMap("o3", "other,request", null);
@@ -311,4 +310,5 @@ public class BindingsValuesProvidersByContextIT extends ScriptingCoreTestSuppor
addBVPWithServiceRanking("genericOne", "request", null, -42);
assertEquals("genericOne,genericTwo,genericThree,first,second,last", asString(bvpProvider.getBindingsValuesProviders(factory("js"), "request"), false));
}
+
}
diff --git a/src/test/java/org/apache/sling/scripting/core/it/Jsr223ScriptEngineBundleIT.java b/src/test/java/org/apache/sling/scripting/core/it/Jsr223ScriptEngineBundleIT.java
index 2064f8a..2752640 100644
--- a/src/test/java/org/apache/sling/scripting/core/it/Jsr223ScriptEngineBundleIT.java
+++ b/src/test/java/org/apache/sling/scripting/core/it/Jsr223ScriptEngineBundleIT.java
@@ -18,74 +18,73 @@
*/
package org.apache.sling.scripting.core.it;
-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)
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+
+/**
+ * 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{
+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
+ private static final String TEST_BUNDLE_ID = "groovy-all";
+
+ private static final String TEST_ENGINE_NAME = "Groovy Scripting Engine";
+
@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()]);
+ return options(
+ baseConfiguration(),
+ mavenBundle().groupId("org.codehaus.groovy").artifactId(TEST_BUNDLE_ID).version("2.4.14")
+ );
}
@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)) {
+ 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)) {
+ for (ScriptEngineFactory f : fac) {
+ if (f.getEngineName().equals(TEST_ENGINE_NAME)) {
testFactory = f;
}
}
- assertNotNull(
- "Expecting ScriptEngineFactory to be active: " + TEST_ENGINE_NAME,
- testFactory);
+ assertNotNull("Expecting ScriptEngineFactory to be active: " + TEST_ENGINE_NAME, testFactory);
}
-}
\ No newline at end of file
+
+}
diff --git a/src/test/java/org/apache/sling/scripting/core/it/ScriptingCoreTestSupport.java b/src/test/java/org/apache/sling/scripting/core/it/ScriptingCoreTestSupport.java
index cef5f79..d65d977 100644
--- a/src/test/java/org/apache/sling/scripting/core/it/ScriptingCoreTestSupport.java
+++ b/src/test/java/org/apache/sling/scripting/core/it/ScriptingCoreTestSupport.java
@@ -18,52 +18,78 @@
*/
package org.apache.sling.scripting.core.it;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
import org.apache.sling.testing.paxexam.TestSupport;
-import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.options.CompositeOption;
+import org.ops4j.pax.exam.options.ModifiableCompositeOption;
-import static org.apache.sling.testing.paxexam.SlingOptions.sling;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingResourcePresence;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingScripting;
import static org.apache.sling.testing.paxexam.SlingOptions.versionResolver;
-import static org.apache.sling.testing.paxexam.SlingOptions.webconsole;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
public class ScriptingCoreTestSupport extends TestSupport {
- @Configuration
- public Option[] configuration() {
- return options(
- baseConfiguration(),
- launchpad(),
+ final int httpPort = findFreePort();
+
+ final Option scriptingCore = mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.scripting.core").version(versionResolver.getVersion("org.apache.sling", "org.apache.sling.scripting.core"));
+
+ public ModifiableCompositeOption baseConfiguration() {
+ final Option slingScripting = slingScripting().remove(scriptingCore);
+ return composite(
+ super.baseConfiguration(),
+ // Sling Scripting
+ slingScripting,
+ newConfiguration("org.apache.felix.http")
+ .put("org.osgi.service.http.port", httpPort)
+ .asOption(),
// Sling Scripting Core
testBundle("bundle.filename"),
- mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.scripting.api").versionAsInProject(),
- factoryConfiguration("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended")
- .put("user.mapping", new String[]{
- "org.apache.sling.scripting.core=sling-scripting"
- })
- .asOption(),
// debugging
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.inventory").version(versionResolver),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.webconsole.plugins.ds").version(versionResolver),
// testing
+ slingResourcePresence(),
+ mavenBundle().groupId("org.jsoup").artifactId("jsoup").versionAsInProject(),
+ mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
junitBundles()
);
}
- private Option launchpad() {
- final int httpPort = findFreePort();
- return composite(
- sling(),
- webconsole(),
- newConfiguration("org.apache.felix.http")
- .put("org.osgi.service.http.port", httpPort)
- .asOption()
- );
+ // move below helpers for deep removal to Pax Exam
+
+ private static List<Option> expand(final Option[] options) {
+ final List<Option> expanded = new ArrayList<>();
+ if (options != null) {
+ for (final Option option : options) {
+ if (option != null) {
+ if (option instanceof CompositeOption) {
+ expanded.addAll(Arrays.asList(((CompositeOption) option).getOptions()));
+ } else {
+ expanded.add(option);
+ }
+ }
+ }
+ }
+ return expanded;
+ }
+
+ static Option[] remove(final Option[] options, final Option option) {
+ final List<Option> expanded = expand(options);
+ if (option instanceof CompositeOption) {
+ expanded.removeAll(Arrays.asList(((CompositeOption) option).getOptions()));
+ } else {
+ expanded.removeAll(Collections.singleton(option));
+ }
+ return expanded.toArray(new Option[0]);
}
}