You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2021/07/28 15:23:04 UTC

[sling-org-apache-sling-graphql-schema-aggregator] branch issue/SLING-10681 created (now 940d300)

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

radu pushed a change to branch issue/SLING-10681
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-graphql-schema-aggregator.git.


      at 940d300  SLING-10681 - Restrict the naming pattern for partials

This branch includes the following new commits:

     new 940d300  SLING-10681 - Restrict the naming pattern for partials

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-graphql-schema-aggregator] 01/01: SLING-10681 - Restrict the naming pattern for partials

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch issue/SLING-10681
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-graphql-schema-aggregator.git

commit 940d3000ef30144fd3e58fef7970771dc21e0efc
Author: Radu Cotescu <co...@adobe.com>
AuthorDate: Wed Jul 28 17:21:53 2021 +0200

    SLING-10681 - Restrict the naming pattern for partials
    
    * renamed test partials to align them with the upcoming partial names
    pattern restriction
---
 .../impl/DefaultSchemaAggregatorTest.java          | 26 +++++++++++-----------
 .../schema/aggregator/impl/PartialReaderTest.java  |  2 +-
 .../aggregator/impl/ProviderBundleTrackerTest.java | 18 +++++++--------
 .../partials/several-providers-output.txt          | 14 ++++++------
 4 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregatorTest.java b/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregatorTest.java
index cad4510..c0268eb 100644
--- a/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregatorTest.java
+++ b/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregatorTest.java
@@ -52,7 +52,7 @@ public class DefaultSchemaAggregatorTest {
     private void assertOutput(String expectedResourceName, String actual) throws IOException {
         try(InputStream is = getClass().getResourceAsStream(expectedResourceName)) {
             assertNotNull("Expecting classpath resource to be present:" + expectedResourceName, is);
-            final String expected = IOUtils.toString(is, "UTF-8");
+            final String expected = IOUtils.toString(is, "UTF-8").trim();
             assertEquals(expected, actual);
         }
     }
@@ -86,9 +86,9 @@ public class DefaultSchemaAggregatorTest {
     @Test
     public void severalProviders() throws Exception{
         final StringWriter target = new StringWriter();
-        tracker.addingBundle(U.mockProviderBundle(bundleContext, "A", 1, "1.txt", "2.z.w", "3abc", "4abc"), null);
-        tracker.addingBundle(U.mockProviderBundle(bundleContext, "B", 2, "B1a.txt", "B2.xy"), null);
-        dsa.aggregate(target, "B1a", "B2", "2.z");
+        tracker.addingBundle(U.mockProviderBundle(bundleContext, "A", 1, "a1.txt", "a2.z.w.txt", "a3abc.txt", "a4abc.txt"), null);
+        tracker.addingBundle(U.mockProviderBundle(bundleContext, "B", 2, "b1a.txt", "b2.xy.txt"), null);
+        dsa.aggregate(target, "b1a", "b2.xy", "a2.z.w");
         final String sdl = target.toString().trim();
         assertContainsIgnoreCase("schema aggregated by DefaultSchemaAggregator", sdl);
         assertOutput("/partials/several-providers-output.txt", sdl);
@@ -97,11 +97,11 @@ public class DefaultSchemaAggregatorTest {
     @Test
     public void regexpSelection() throws Exception {
         final StringWriter target = new StringWriter();
-        tracker.addingBundle(U.mockProviderBundle(bundleContext, "A", 1, "a.authoring.1.txt", "a.authoring.2.txt", "3.txt", "4.txt"), null);
-        tracker.addingBundle(U.mockProviderBundle(bundleContext, "B", 2, "B1.txt", "B.authoring.txt"), null);
-        dsa.aggregate(target, "B1", "/.*\\.authoring.*/");
+        tracker.addingBundle(U.mockProviderBundle(bundleContext, "A", 1, "a.authoring.1.txt", "a.authoring.2.txt", "a.txt", "b.txt"), null);
+        tracker.addingBundle(U.mockProviderBundle(bundleContext, "B", 2, "b1.txt", "b.authoring.txt"), null);
+        dsa.aggregate(target, "b1", "/.*\\.authoring.*/");
         assertContainsIgnoreCase("schema aggregated by DefaultSchemaAggregator", target.toString());
-        U.assertPartialsFoundInSchema(target.toString(), "a.authoring.1", "a.authoring.2", "B.authoring", "B1");
+        U.assertPartialsFoundInSchema(target.toString(), "a.authoring.1", "a.authoring.2", "b.authoring", "b1");
     }
 
     @Test
@@ -191,15 +191,15 @@ public class DefaultSchemaAggregatorTest {
     @Test
     public void providersOrdering() throws Exception {
         final StringWriter target = new StringWriter();
-        tracker.addingBundle(U.mockProviderBundle(bundleContext, "ordering", 1, "Aprov.txt", "Cprov.txt", "Z_test.txt", "A_test.txt",
-                "Zprov.txt",
-                "Z_test.txt", "Bprov.txt", "C_test.txt"), null);
-        dsa.aggregate(target, "Aprov", "Zprov", "/[A-Z]_test/", "A_test", "Cprov");
+        tracker.addingBundle(U.mockProviderBundle(bundleContext, "ordering", 1, "aprov.txt", "cprov.txt", "z_test.txt", "a_test.txt",
+                "zprov.txt",
+                "z_test.txt", "bprov.txt", "c_test.txt"), null);
+        dsa.aggregate(target, "aprov", "zprov", "/[a-z]_test/", "a_test", "cprov");
         final String sdl = target.toString();
 
         // The order of named partials is kept, regexp selected ones are ordered by name
         // And A_test has already been used so it's not used again when called explicitly after regexp
-        final String expected = "End of Schema aggregated from {Aprov,Zprov,A_test,C_test,Z_test,Cprov} by DefaultSchemaAggregator";
+        final String expected = "End of Schema aggregated from {aprov,zprov,a_test,c_test,z_test,cprov} by DefaultSchemaAggregator";
         assertTrue(String.format("Expecting schema to contain [%s]: %s", expected, sdl), sdl.contains(expected));
    }
 }
diff --git a/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/PartialReaderTest.java b/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/PartialReaderTest.java
index a7863cf..6fca4d1 100644
--- a/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/PartialReaderTest.java
+++ b/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/PartialReaderTest.java
@@ -51,7 +51,7 @@ public class PartialReaderTest {
         }
         if(contentRegexp != null) {
             try(Reader r = s.getContent()) {
-                final String actual = IOUtils.toString(s.getContent()).trim();
+                final String actual = IOUtils.toString(r).trim();
                 final Pattern regexp = Pattern.compile(contentRegexp, Pattern.DOTALL);
                 assertTrue(
                     String.format("Expecting section %s to match %s but was [%s]", name, contentRegexp, actual),
diff --git a/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/ProviderBundleTrackerTest.java b/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/ProviderBundleTrackerTest.java
index 1f78d9b..2ceee73 100644
--- a/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/ProviderBundleTrackerTest.java
+++ b/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/ProviderBundleTrackerTest.java
@@ -52,19 +52,19 @@ public class ProviderBundleTrackerTest {
 
     @Test
     public void addBundle() throws Exception {
-        final Bundle a = U.mockProviderBundle(bundleContext, "A", ++bundleId, "1.txt");
+        final Bundle a = U.mockProviderBundle(bundleContext, "A", ++bundleId, "a.txt");
         tracker.addingBundle(a, null);
         assertEquals(1, tracker.getSchemaProviders().size());
 
         final Partial s = tracker.getSchemaProviders().values().iterator().next();
         assertTrue(s.toString().contains(a.getSymbolicName()));
-        assertTrue(s.toString().contains("1.txt"));
+        assertTrue(s.toString().contains("a.txt"));
     }
 
     @Test
     public void addAndRemoveBundles() throws Exception {
-        final Bundle a = U.mockProviderBundle(bundleContext, "A", ++bundleId, "1.graphql.txt");
-        final Bundle b = U.mockProviderBundle(bundleContext, "B", ++bundleId, "2.txt", "1.txt");
+        final Bundle a = U.mockProviderBundle(bundleContext, "A", ++bundleId, "a1.graphql.txt");
+        final Bundle b = U.mockProviderBundle(bundleContext, "B", ++bundleId, "b2.txt", "b1.txt");
         tracker.addingBundle(a, null);
         tracker.addingBundle(b, null);
         assertEquals(3, tracker.getSchemaProviders().size());
@@ -79,11 +79,11 @@ public class ProviderBundleTrackerTest {
     @Test
     public void duplicatePartialName() throws Exception {
         final LogCapture capture = new LogCapture(ProviderBundleTracker.class.getName(), true);
-        final Bundle a = U.mockProviderBundle(bundleContext, "A", ++bundleId, "TT.txt");
-        final Bundle b = U.mockProviderBundle(bundleContext, "B", ++bundleId, "TT.txt", "another.x");
+        final Bundle a = U.mockProviderBundle(bundleContext, "A", ++bundleId, "tt.txt");
+        final Bundle b = U.mockProviderBundle(bundleContext, "B", ++bundleId, "tt.txt", "another.x");
         tracker.addingBundle(a, null);
         tracker.addingBundle(b, null);
-        capture.assertContains(Level.WARN, "Partial provider with name TT already present");
+        capture.assertContains(Level.WARN, "Partial provider with name tt already present");
         assertEquals(2, tracker.getSchemaProviders().size());
     }
 
@@ -95,9 +95,9 @@ public class ProviderBundleTrackerTest {
  
     @Test
     public void getSectionsContent() throws IOException {
-        final Bundle a = U.mockProviderBundle(bundleContext, "A", ++bundleId, "1.txt");
+        final Bundle a = U.mockProviderBundle(bundleContext, "A", ++bundleId, "a1.txt");
         tracker.addingBundle(a, null);
         final Partial p = tracker.getSchemaProviders().values().iterator().next();
-        assertSectionContent(p, Partial.SectionName.QUERY, "Fake query for 1.txt");
+        assertSectionContent(p, Partial.SectionName.QUERY, "Fake query for a1.txt");
     }
 }
diff --git a/src/test/resources/partials/several-providers-output.txt b/src/test/resources/partials/several-providers-output.txt
index b3fa1f7..cff4dc8 100644
--- a/src/test/resources/partials/several-providers-output.txt
+++ b/src/test/resources/partials/several-providers-output.txt
@@ -2,15 +2,15 @@
 
 type Query {
 
-# DefaultSchemaAggregator.source=B1a
-Fake query for B1a.txt
+# DefaultSchemaAggregator.source=b1a
+Fake query for b1a.txt
 
-# DefaultSchemaAggregator.source=B2
-Fake query for B2.xy
+# DefaultSchemaAggregator.source=b2.xy
+Fake query for b2.xy.txt
 
-# DefaultSchemaAggregator.source=2.z
-Fake query for 2.z.w
+# DefaultSchemaAggregator.source=a2.z.w
+Fake query for a2.z.w.txt
 
 }
 
-# End of Schema aggregated from {B1a,B2,2.z} by DefaultSchemaAggregator
\ No newline at end of file
+# End of Schema aggregated from {b1a,b2.xy,a2.z.w} by DefaultSchemaAggregator