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 2020/03/27 15:23:42 UTC
[sling-whiteboard] 01/03: Add graphql-java
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-whiteboard.git
commit 639cc8359213e70dae710764369d2ca27cce9033
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Mar 27 14:39:29 2020 +0100
Add graphql-java
---
graphql-scripting/pom.xml | 10 +++---
.../graphql/it/GraphQLScriptingTestSupport.java | 39 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/graphql-scripting/pom.xml b/graphql-scripting/pom.xml
index 9d0727f..7852c61 100644
--- a/graphql-scripting/pom.xml
+++ b/graphql-scripting/pom.xml
@@ -85,13 +85,11 @@
</build>
<dependencies>
- <!-- javax -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>test</scope>
</dependency>
- <!-- OSGi -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
@@ -112,14 +110,18 @@
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<scope>provided</scope>
</dependency>
- <!-- Apache Felix -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>6.0.3</version>
<scope>test</scope>
</dependency>
- <!-- Apache Sling -->
+ <dependency>
+ <groupId>com.graphql-java</groupId>
+ <artifactId>graphql-java</artifactId>
+ <version>11.0</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
diff --git a/graphql-scripting/src/test/java/org/apache/sling/scripting/graphql/it/GraphQLScriptingTestSupport.java b/graphql-scripting/src/test/java/org/apache/sling/scripting/graphql/it/GraphQLScriptingTestSupport.java
index 414546a..9ae877b 100644
--- a/graphql-scripting/src/test/java/org/apache/sling/scripting/graphql/it/GraphQLScriptingTestSupport.java
+++ b/graphql-scripting/src/test/java/org/apache/sling/scripting/graphql/it/GraphQLScriptingTestSupport.java
@@ -26,6 +26,7 @@ import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.servlethelpers.MockSlingHttpServletRequest;
import org.apache.sling.servlethelpers.MockSlingHttpServletResponse;
import org.apache.sling.testing.paxexam.TestSupport;
+import org.junit.Before;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.ProbeBuilder;
import org.ops4j.pax.exam.TestProbeBuilder;
@@ -37,6 +38,7 @@ import org.apache.sling.engine.SlingRequestProcessor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
import static org.apache.sling.testing.paxexam.SlingOptions.slingResourcePresence;
import static org.apache.sling.testing.paxexam.SlingOptions.slingScripting;
@@ -47,8 +49,13 @@ import static org.ops4j.pax.exam.CoreOptions.when;
import static org.ops4j.pax.exam.CoreOptions.vmOption;
import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
+import java.util.ArrayList;
+import java.util.List;
+
public abstract class GraphQLScriptingTestSupport extends TestSupport {
+ private final static int STARTUP_WAIT_SECONDS = 30;
+
@Inject
@Filter(value = "(names=graphql)")
protected ScriptEngineFactory scriptEngineFactory;
@@ -68,6 +75,7 @@ public abstract class GraphQLScriptingTestSupport extends TestSupport {
),
super.baseConfiguration(),
slingQuickstart(),
+ graphQLJava(),
testBundle("bundle.filename"),
newConfiguration("org.apache.sling.jcr.base.internal.LoginAdminWhitelist")
.put("whitelist.bundles.regexp", "^PAXEXAM.*$")
@@ -93,6 +101,37 @@ public abstract class GraphQLScriptingTestSupport extends TestSupport {
);
}
+ protected Option graphQLJava() {
+ return composite(
+ mavenBundle().groupId("com.graphql-java").artifactId("graphql-java").versionAsInProject(),
+ mavenBundle().groupId("org.antlr").artifactId("antlr4-runtime").versionAsInProject(),
+ mavenBundle().groupId("com.graphql-java").artifactId("java-dataloader").versionAsInProject(),
+ mavenBundle().groupId("org.reactivestreams").artifactId("reactive-streams").versionAsInProject()
+ );
+ }
+
+ /**
+ * Injecting the appropriate services to wait for would be more elegant but this is very reliable..
+ */
+ @Before
+ public void waitForSling() throws Exception {
+ final int expectedStatus = 200;
+ final List<Integer> statuses = new ArrayList<>();
+ final String path = "/.json";
+ final long endTime = System.currentTimeMillis() + STARTUP_WAIT_SECONDS * 1000;
+
+ while (System.currentTimeMillis() < endTime) {
+ final int status = executeRequest("GET", path, -1).getStatus();
+ statuses.add(status);
+ if (status == expectedStatus) {
+ return;
+ }
+ Thread.sleep(250);
+ }
+
+ fail("Did not get a " + expectedStatus + " status at " + path + " got " + statuses);
+ }
+
protected MockSlingHttpServletResponse executeRequest(final String method, final String path, final int expectedStatus) throws Exception {
final ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
assertNotNull("Expecting ResourceResolver", resourceResolver);