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/05/12 13:25:00 UTC

[sling-org-apache-sling-graphql-core] 01/04: Move test schema to a file

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-graphql-core.git

commit d5eb7ffae141d5414a69aaf55c88accaf9715e48
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue May 12 15:04:31 2020 +0200

    Move test schema to a file
---
 .../graphql/core/mocks/MockSchemaProvider.java     | 38 ++++++++----------
 src/test/resources/test-schema.txt                 | 45 ++++++++++++++++++++++
 2 files changed, 62 insertions(+), 21 deletions(-)

diff --git a/src/test/java/org/apache/sling/graphql/core/mocks/MockSchemaProvider.java b/src/test/java/org/apache/sling/graphql/core/mocks/MockSchemaProvider.java
index 009902a..d58a668 100644
--- a/src/test/java/org/apache/sling/graphql/core/mocks/MockSchemaProvider.java
+++ b/src/test/java/org/apache/sling/graphql/core/mocks/MockSchemaProvider.java
@@ -18,32 +18,28 @@
  */
 package org.apache.sling.graphql.core.mocks;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+
+import org.apache.commons.io.IOUtils;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.graphql.api.SchemaProvider;
 
 public class MockSchemaProvider implements SchemaProvider {
 
-    private static final String MOCK_SCHEMA = 
-        "type Query {\n"
-        + "    ## fetch:test/echo\n"
-        + "    currentResource : SlingResource\n"
-        + "    ## fetch:test/static\n"
-        + "    staticContent: Test"
-        + "}\n"
-        + "type SlingResource { \n"
-        + "    path: String\n"
-        + "    resourceType: String\n"
-        + "\n"
-        + "    ## fetch:test/digest/md5 path\n"
-        + "    pathMD5: String\n"
-        + "\n"
-        + "    ## fetch:test/digest/sha-256 path\n"
-        + "    pathSHA256: String\n"
-        + "\n"
-        + "    ## fetch:test/digest/md5 resourceType\n"
-        + "    resourceTypeMD5: String\n"
-        + " }\n"
-        + "type Test { test: Boolean }";
+    private static final String MOCK_SCHEMA_PATH = "/test-schema.txt";
+    private static final String MOCK_SCHEMA;
+
+    static {
+        try (InputStream is = MockSchemaProvider.class.getResourceAsStream(MOCK_SCHEMA_PATH)) {
+            final StringWriter w = new StringWriter();
+            IOUtils.copy(is, w);
+            MOCK_SCHEMA = w.toString();
+        } catch(IOException ioe) {
+            throw new RuntimeException("Error reading " + MOCK_SCHEMA_PATH, ioe);
+        }
+    }
 
     @Override
     public String getSchema(Resource r, String[] selectors) {
diff --git a/src/test/resources/test-schema.txt b/src/test/resources/test-schema.txt
new file mode 100644
index 0000000..9ecb003
--- /dev/null
+++ b/src/test/resources/test-schema.txt
@@ -0,0 +1,45 @@
+# * 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.
+
+# GraphQL Schema used for our tests
+# annotated with our fetch: definitions
+
+type Query {
+    ## fetch:test/echo
+    currentResource : SlingResource
+
+    ## fetch:test/static
+    staticContent: Test
+}
+
+type SlingResource { 
+    path: String
+    resourceType: String
+
+    ## fetch:test/digest/md5 path
+    pathMD5: String
+
+    ## fetch:test/digest/sha-256 path
+    pathSHA256: String
+
+    ## fetch:test/digest/md5 resourceType
+    resourceTypeMD5: String
+}
+
+type Test { 
+    test: Boolean 
+}
\ No newline at end of file