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 2021/07/12 16:05:58 UTC
[sling-whiteboard] branch master updated: SLING-10551 - remove
output noise
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
The following commit(s) were added to refs/heads/master by this push:
new 2d11256 SLING-10551 - remove output noise
2d11256 is described below
commit 2d112567377713d9217386eff3572e8ed398b457
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Jul 12 17:27:07 2021 +0200
SLING-10551 - remove output noise
---
.../aggregator/impl/DefaultSchemaAggregator.java | 17 ++++++++------
.../impl/DefaultSchemaAggregatorTest.java | 7 +++---
.../aggregator/it/SchemaAggregatorServletIT.java | 1 -
.../test/resources/several-providers-output.txt | 27 +---------------------
4 files changed, 15 insertions(+), 37 deletions(-)
diff --git a/sling-org-apache-sling-graphql-schema/src/main/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregator.java b/sling-org-apache-sling-graphql-schema/src/main/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregator.java
index 5f5ef7c..1b47804 100644
--- a/sling-org-apache-sling-graphql-schema/src/main/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregator.java
+++ b/sling-org-apache-sling-graphql-schema/src/main/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregator.java
@@ -67,18 +67,21 @@ public class DefaultSchemaAggregator implements SchemaAggregator {
}
private void copySection(Set<Partial> selected, String sectionName, boolean inBlock, Writer target) throws IOException {
- if(inBlock) {
- target.write(String.format("%ntype %s {%n", sectionName));
- }
+ String prefixToWrite = inBlock ? String.format("%ntype %s {%n", sectionName) : null;
+ boolean anyOutput = false;
for(Partial p : selected) {
- writeSourceInfo(target, p);
final Optional<Partial.Section> section = p.getSection(sectionName);
if(section.isPresent()) {
+ anyOutput = true;
+ if(prefixToWrite != null) {
+ target.write(prefixToWrite);
+ prefixToWrite = null;
+ }
+ writeSourceInfo(target, p);
IOUtils.copy(section.get().getContent(), target);
- target.write(String.format("%n"));
}
}
- if(inBlock) {
+ if(anyOutput && inBlock) {
target.write(String.format("%n}%n"));
}
}
@@ -118,7 +121,7 @@ public class DefaultSchemaAggregator implements SchemaAggregator {
}
partialNames.append(p.getName());
});
- target.write(String.format("%n# End of Schema aggregated from [%s] by %s", partialNames, getClass().getSimpleName()));
+ target.write(String.format("%n# End of Schema aggregated from {%s} by %s", partialNames, getClass().getSimpleName()));
}
Set<Partial> selectProviders(Map<String, Partial> providers, Set<String> missing, String ... providerNamesOrRegexp) {
diff --git a/sling-org-apache-sling-graphql-schema/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregatorTest.java b/sling-org-apache-sling-graphql-schema/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregatorTest.java
index 498b8c3..cf7e79c 100644
--- a/sling-org-apache-sling-graphql-schema/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregatorTest.java
+++ b/sling-org-apache-sling-graphql-schema/src/test/java/org/apache/sling/graphql/schema/aggregator/impl/DefaultSchemaAggregatorTest.java
@@ -76,12 +76,13 @@ public class DefaultSchemaAggregatorTest {
tracker.addingBundle(U.mockProviderBundle("A", 1, "1.txt", "2.z.w", "3abc", "4abc"), null);
tracker.addingBundle(U.mockProviderBundle("B", 2, "B1a.txt", "B2.xy"), null);
dsa.aggregate(target, "B1a", "B2", "2.z");
- assertContainsIgnoreCase("schema aggregated by DefaultSchemaAggregator", target.toString());
+ final String sdl = target.toString().trim();
+ assertContainsIgnoreCase("schema aggregated by DefaultSchemaAggregator", sdl);
try(InputStream is = getClass().getResourceAsStream("/several-providers-output.txt")) {
assertNotNull("Expecting test resource to be present", is);
final String expected = IOUtils.toString(is, "UTF-8");
- assertEquals(expected, target.toString().trim());
+ assertEquals(expected, sdl);
}
}
@@ -161,7 +162,7 @@ public class DefaultSchemaAggregatorTest {
// 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));
}
}
\ No newline at end of file
diff --git a/sling-org-apache-sling-graphql-schema/src/test/java/org/apache/sling/graphql/schema/aggregator/it/SchemaAggregatorServletIT.java b/sling-org-apache-sling-graphql-schema/src/test/java/org/apache/sling/graphql/schema/aggregator/it/SchemaAggregatorServletIT.java
index 1d50c2b..fe4cb6b 100644
--- a/sling-org-apache-sling-graphql-schema/src/test/java/org/apache/sling/graphql/schema/aggregator/it/SchemaAggregatorServletIT.java
+++ b/sling-org-apache-sling-graphql-schema/src/test/java/org/apache/sling/graphql/schema/aggregator/it/SchemaAggregatorServletIT.java
@@ -24,7 +24,6 @@ import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
-import static org.junit.Assert.fail;
import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
import org.apache.sling.graphql.schema.aggregator.U;
diff --git a/sling-org-apache-sling-graphql-schema/src/test/resources/several-providers-output.txt b/sling-org-apache-sling-graphql-schema/src/test/resources/several-providers-output.txt
index 0ecd6a8..2b2c828 100644
--- a/sling-org-apache-sling-graphql-schema/src/test/resources/several-providers-output.txt
+++ b/sling-org-apache-sling-graphql-schema/src/test/resources/several-providers-output.txt
@@ -1,41 +1,16 @@
# Schema aggregated by DefaultSchemaAggregator
-# DefaultSchemaAggregator.source=B1a
-
-# DefaultSchemaAggregator.source=B2
-
-# DefaultSchemaAggregator.source=2.z
-
type QUERY {
# DefaultSchemaAggregator.source=B1a
Fake query for B1a.txt
-
# DefaultSchemaAggregator.source=B2
Fake query for B2.xy
-
# DefaultSchemaAggregator.source=2.z
Fake query for 2.z.w
-
-}
-
-type MUTATION {
-
-# DefaultSchemaAggregator.source=B1a
-
-# DefaultSchemaAggregator.source=B2
-
-# DefaultSchemaAggregator.source=2.z
-
}
-# DefaultSchemaAggregator.source=B1a
-
-# DefaultSchemaAggregator.source=B2
-
-# DefaultSchemaAggregator.source=2.z
-
-# End of Schema aggregated from [B1a,B2,2.z] by DefaultSchemaAggregator
\ No newline at end of file
+# End of Schema aggregated from {B1a,B2,2.z} by DefaultSchemaAggregator
\ No newline at end of file