anchela commented on a change in pull request #9: URL: https://github.com/apache/sling-org-apache-sling-repoinit-parser/pull/9#discussion_r602235934
########## 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: @bdelacretaz , comparing repoInit.tostring with tc.input won't work for the following reasons: - 1 operation doesn't allow to generate the original string (see FIXME with SLING-jira-reference) - instructions like create service user a,b,c get converted to 3x CreateServiceUserOperation and it is impossible to know if that was 3x create service user or the shortcut. the only way to do that is manually creating a result.txt.... but that then probably generates a lot of extra maintenance effort for you and there is a tiny risk of the result.txt also containing flaws. what might be more reliable than toString is getParameterDescription.... for some ops it is public. but not for all..... but i was a bit hesitant to make it public just for testing purpose in the light of an issue that is otherwise unrelated. but if you make it public i would use it instead of toString. wdyt? -- 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]
