bdelacretaz commented on a change in pull request #9: URL: https://github.com/apache/sling-org-apache-sling-repoinit-parser/pull/9#discussion_r600723588
########## File path: src/test/java/org/apache/sling/repoinit/parser/test/AsRepoInitTest.java ########## @@ -0,0 +1,90 @@ +/* + * 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 org.apache.sling.repoinit.parser.RepoInitParsingException; +import org.apache.sling.repoinit.parser.impl.RepoInitParserService; +import org.apache.sling.repoinit.parser.operations.Operation; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** Test the parser using our test-* input/expected output files. + * The code of this class doesn't contain any actual tests, it + * just looks for test-*.txt files, parses them and verifies the + * results according to the test-*-output.txt files. + */ +@RunWith(Parameterized.class) +public class AsRepoInitTest { + + private final ParserTest.TestCase tc; + + @Parameters(name="{0}") + public static Collection<Object[]> data() 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; + + } + + public AsRepoInitTest(ParserTest.TestCase tc) { + this.tc = tc; + } + + @Test + public void checkResultAsRepoInit() throws Exception { + StringBuilder repoInit = new StringBuilder(); + final List<Operation> expectedResult; + try { + expectedResult = new RepoInitParserService().parse(tc.input); + for (Operation o : expectedResult) { + repoInit.append(o.asRepoInitString()); + } + } finally { + tc.close(); + } + + try { + List<Operation> ops = new RepoInitParserService().parse(new StringReader(repoInit.toString())); + assertEquals(expectedResult.size(), ops.size()); + for (int i = 0; i < expectedResult.size(); i++) { + Operation expected = expectedResult.get(i); + Operation op = ops.get(i); + assertEquals(expected.toString(), op.toString()); Review comment: I think this doesn't work for `SetAclPrincipalBased` and maybe other `Operation` classes where toString() doesn't include all the parameters. We might define that toString must include all parameters but that's hard to enforce. I think comparing `repoInit.toString()` with the contents of `tc.input` would test what we actually want to test, but the comparison probably requires normalizing both strings, at least in terms of whitespace, and maybe tweaking the test scripts if that helps getting equal values once normalized. ########## File path: src/test/java/org/apache/sling/repoinit/parser/test/AsRepoInitTest.java ########## @@ -0,0 +1,79 @@ +/* + * 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 org.apache.sling.repoinit.parser.impl.RepoInitParserService; +import org.apache.sling.repoinit.parser.operations.Operation; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** Test the parser using our test-* input/expected output files. + * The code of this class doesn't contain any actual tests, it + * just looks for test-*.txt files, parses them and verifies the + * results according to the test-*-output.txt files. + */ +@RunWith(Parameterized.class) +public class AsRepoInitTest { + + private final ParserTest.TestCase tc; + + @Parameters(name="{0}") + public static Collection<Object[]> data() 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; + + } + + public AsRepoInitTest(ParserTest.TestCase tc) { + this.tc = tc; + } + + @Test + public void checkResultAsRepoInit() throws Exception { + StringBuilder repoInit = new StringBuilder(); + final List<Operation> expectedResult; + try { + expectedResult = new RepoInitParserService().parse(tc.input); + for (Operation o : expectedResult) { + repoInit.append(o.asRepoInitString()); + } + } finally { + tc.close(); + } + + List<Operation> ops = new RepoInitParserService().parse(new StringReader(repoInit.toString())); + assertEquals(expectedResult.size(), ops.size()); + // FIXME: assert operations are equivalent Review comment: to compare the reconstructed repoinit script S with the original O, I see two options: * 1) implement `equals` in all `Operation` classes and use that to compare the result of parsing S and O * 2) normalize the test input String (removing extra spaces etc) and compare to the normalized `repoInit` string If needed for 2) we might slightly change the test inputs for things that the normalization wouldn't catch, to make testing easier -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
