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-repoinit-parser.git
The following commit(s) were added to refs/heads/master by this push:
new fc02bf2 SLING-10236 - cleanup
fc02bf2 is described below
commit fc02bf24521ebf39d86aaf649b67d71fcb1cf8ac
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Tue Mar 30 15:25:18 2021 +0200
SLING-10236 - cleanup
---
.../parser/operations/PathSegmentDefinition.java | 1 -
.../repoinit/parser/operations/AsRepoInitTest.java | 18 +--
.../sling/repoinit/parser/test/ParserTest.java | 100 +----------------
.../sling/repoinit/parser/test/ParserTestCase.java | 121 +++++++++++++++++++++
4 files changed, 131 insertions(+), 109 deletions(-)
diff --git
a/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java
b/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java
index 327156a..2c34c7a 100644
---
a/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java
+++
b/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java
@@ -20,7 +20,6 @@ package org.apache.sling.repoinit.parser.operations;
import java.util.Collections;
import java.util.List;
-import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ProviderType;
/** Defines a segment of a path to be created,
diff --git
a/src/test/java/org/apache/sling/repoinit/parser/operations/AsRepoInitTest.java
b/src/test/java/org/apache/sling/repoinit/parser/operations/AsRepoInitTest.java
index 01c2d52..fe12c50 100644
---
a/src/test/java/org/apache/sling/repoinit/parser/operations/AsRepoInitTest.java
+++
b/src/test/java/org/apache/sling/repoinit/parser/operations/AsRepoInitTest.java
@@ -17,9 +17,9 @@
package org.apache.sling.repoinit.parser.operations;
-import org.apache.sling.repoinit.parser.RepoInitParsingException;
import org.apache.sling.repoinit.parser.impl.RepoInitParserService;
import org.apache.sling.repoinit.parser.test.ParserTest;
+import org.apache.sling.repoinit.parser.test.ParserTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -28,9 +28,7 @@ import org.junit.runners.Parameterized.Parameters;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
/** Similar to {@link ParserTest} but uses {@link
Operation#asRepoInitString()})
* to rebuild the input script after parsing it, to verify that that operation
@@ -39,14 +37,14 @@ import java.util.List;
@RunWith(Parameterized.class)
public class AsRepoInitTest {
- private final ParserTest.TestCase tc;
+ private final ParserTestCase tc;
@Parameters(name="{0}")
public static Collection<Object[]> data() throws IOException {
- return ParserTest.TestCase.buildTestData();
+ return ParserTestCase.buildTestData();
}
- public AsRepoInitTest(ParserTest.TestCase tc) {
+ public AsRepoInitTest(ParserTestCase tc) {
this.tc = tc;
}
@@ -61,10 +59,6 @@ public class AsRepoInitTest {
@Test
public void checkResultAsRepoInit() throws Exception {
- try {
- ParserTest.TestCase.validate(rebuildInputScript(tc.input),
tc.expected);
- } finally {
- tc.close();
- }
+ ParserTestCase.validate(rebuildInputScript(tc.input), tc.expected, tc);
}
-}
+}
\ No newline at end of file
diff --git
a/src/test/java/org/apache/sling/repoinit/parser/test/ParserTest.java
b/src/test/java/org/apache/sling/repoinit/parser/test/ParserTest.java
index 3195c58..6b1b5a2 100644
--- a/src/test/java/org/apache/sling/repoinit/parser/test/ParserTest.java
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/ParserTest.java
@@ -17,23 +17,10 @@
package org.apache.sling.repoinit.parser.test;
-import static org.junit.Assert.assertEquals;
-
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
-import org.apache.commons.io.IOUtils;
import org.apache.sling.repoinit.parser.RepoInitParsingException;
-import org.apache.sling.repoinit.parser.impl.RepoInitParserService;
-import org.apache.sling.repoinit.parser.operations.Operation;
-import org.apache.sling.repoinit.parser.operations.OperationVisitor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -47,98 +34,19 @@ import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ParserTest {
- public static final String DEFAULT_ENCODING = "UTF-8";
-
- public static class TestCase {
- public final Reader input;
- final String inputFilename;
- public final InputStream expected;
- final String outputFilename;
-
- private static final String PREFIX = "/testcases/test-";
-
- @Override
- public String toString() {
- return inputFilename;
- }
-
- private TestCase(int index) throws IOException {
- inputFilename = PREFIX + index + ".txt";
- final InputStream is =
getClass().getResourceAsStream(inputFilename);
- if ( is != null ) {
- input = new InputStreamReader(is, "UTF-8");
- } else {
- input = null;
- }
- outputFilename = PREFIX + index + "-output.txt";
- expected = getClass().getResourceAsStream(outputFilename);
- }
-
- public static TestCase build(int index) throws IOException {
- final TestCase result = new TestCase(index);
- if(result.input == null || result.expected == null) {
- return null;
- }
- return result;
- }
-
- public void close() {
- try {
- input.close();
- } catch(IOException ignored) {
- }
- try {
- expected.close();
- } catch(IOException ignored) {
- }
- }
-
- public static void validate(Reader validateInput, InputStream
validateExpected) throws RepoInitParsingException, IOException {
- final String expected = IOUtils.toString(validateExpected,
DEFAULT_ENCODING).trim();
- final StringWriter sw = new StringWriter();
- final OperationVisitor v = new OperationToStringVisitor(new
PrintWriter(sw));
- final List<Operation> result = new
RepoInitParserService().parse(validateInput);
- for(Operation o : result) {
- o.accept(v);
- }
- sw.flush();
- String actual = sw.toString().trim();
-
- // normalize line endings to ensure tests run on windows as well
- actual = actual.replaceAll("\r\n", "\n");
-
- assertEquals(expected, actual);
- }
-
- public static Collection<Object[]> buildTestData() throws IOException {
- final List<Object []> result = new ArrayList<>();
- for(int i=0; i < 100; i++) {
- final ParserTest.TestCase tc = ParserTest.TestCase.build(i);
- if(tc != null) {
- result.add(new Object[] { tc });
- }
- }
- return result;
- }
- }
-
- private final TestCase tc;
+ private final ParserTestCase tc;
@Parameters(name="{0}")
public static Collection<Object[]> data() throws IOException {
- return TestCase.buildTestData();
+ return ParserTestCase.buildTestData();
}
- public ParserTest(TestCase tc) {
+ public ParserTest(ParserTestCase tc) {
this.tc = tc;
}
@Test
public void checkResult() throws RepoInitParsingException, IOException {
- try {
- TestCase.validate(tc.input, tc.expected);
- } finally {
- tc.close();
- }
+ ParserTestCase.validate(tc.input, tc.expected, tc);
}
}
diff --git
a/src/test/java/org/apache/sling/repoinit/parser/test/ParserTestCase.java
b/src/test/java/org/apache/sling/repoinit/parser/test/ParserTestCase.java
new file mode 100644
index 0000000..0c26a75
--- /dev/null
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/ParserTestCase.java
@@ -0,0 +1,121 @@
+/*
+ * 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.
+ */
+
+package org.apache.sling.repoinit.parser.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.apache.sling.repoinit.parser.impl.RepoInitParserService;
+import org.apache.sling.repoinit.parser.operations.Operation;
+import org.apache.sling.repoinit.parser.operations.OperationVisitor;
+
+public class ParserTestCase implements Closeable {
+ public final Reader input;
+ final String inputFilename;
+ public final InputStream expected;
+ final String outputFilename;
+
+ private static final String DEFAULT_ENCODING = "UTF-8";
+ private static final String PREFIX = "/testcases/test-";
+ private static final int MAX_TEST_INDEX = 100;
+ private static final int EXPECTED_TEST_COUNT = 30;
+
+ @Override
+ public String toString() {
+ return inputFilename;
+ }
+
+ private ParserTestCase(int index) throws IOException {
+ inputFilename = PREFIX + index + ".txt";
+ final InputStream is = getClass().getResourceAsStream(inputFilename);
+ if ( is != null ) {
+ input = new InputStreamReader(is, "UTF-8");
+ } else {
+ input = null;
+ }
+ outputFilename = PREFIX + index + "-output.txt";
+ expected = getClass().getResourceAsStream(outputFilename);
+ }
+
+ public static ParserTestCase build(int index) throws IOException {
+ final ParserTestCase result = new ParserTestCase(index);
+ if(result.input == null || result.expected == null) {
+ return null;
+ }
+ return result;
+ }
+
+ public void close() {
+ try {
+ input.close();
+ } catch(IOException ignored) {
+ }
+ try {
+ expected.close();
+ } catch(IOException ignored) {
+ }
+ }
+
+ public static void validate(Reader validateInput, InputStream
validateExpected, Closeable toClose) throws RepoInitParsingException,
IOException {
+ try {
+ final String expected = IOUtils.toString(validateExpected,
DEFAULT_ENCODING).trim();
+ final StringWriter sw = new StringWriter();
+ final OperationVisitor v = new OperationToStringVisitor(new
PrintWriter(sw));
+ final List<Operation> result = new
RepoInitParserService().parse(validateInput);
+ for(Operation o : result) {
+ o.accept(v);
+ }
+ sw.flush();
+ String actual = sw.toString().trim();
+
+ // normalize line endings to ensure tests run on windows as well
+ actual = actual.replaceAll("\r\n", "\n");
+
+ assertEquals(expected, actual);
+ } finally {
+ toClose.close();
+ }
+ }
+
+ public static Collection<Object[]> buildTestData() throws IOException {
+ final List<Object []> result = new ArrayList<>();
+ for(int i=0; i <= MAX_TEST_INDEX; i++) {
+ final ParserTestCase tc = ParserTestCase.build(i);
+ if(tc != null) {
+ result.add(new Object[] { tc });
+ }
+ }
+ if(result.size() < EXPECTED_TEST_COUNT) {
+ fail("Expected at least " + EXPECTED_TEST_COUNT + " test cases but
got only " + result.size());
+ }
+ return result;
+ }
+}
\ No newline at end of file