2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Ericsson
4 * Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.oran.smo.yangtools.parser.model.statements.yang.test;
23 import static org.junit.Assert.assertTrue;
25 import java.util.Arrays;
26 import java.util.List;
28 import org.junit.Test;
30 import org.oran.smo.yangtools.parser.findings.ModuleAndFindingTypeAndSchemaNodePathFilterPredicate;
31 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
32 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
33 import org.oran.smo.yangtools.parser.model.statements.yang.YRevision;
34 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
36 public class RevisionTest extends YangTestCommon {
39 public void testNoRevisionWithFailFastTrue() {
41 context.setFailFast(true);
43 parseRelativeImplementsYangModels(Arrays.asList("revision-test/revision-test-module-no-revision.yang"));
45 final YModule yModule = getModule("revision-test-module");
46 assertTrue(yModule != null);
48 assertTrue(yModule.getRevisions().size() == 0);
49 assertHasFindingOfType(ParserFindingType.P032_MISSING_REVISION.toString());
50 assertHasFindingOfType(ParserFindingType.P009_FAIL_FAST.toString());
53 * Fail-fast is on so should suppress this one here.
55 assertHasNotFindingOfType(ParserFindingType.P018_ILLEGAL_CHILD_STATEMENT.toString());
59 public void testNoRevisionWithFailFastFalse() {
61 context.setFailFast(false);
63 parseRelativeImplementsYangModels(Arrays.asList("revision-test/revision-test-module-no-revision.yang"));
65 final YModule yModule = getModule("revision-test-module");
66 assertTrue(yModule != null);
68 assertTrue(yModule.getRevisions().size() == 0);
69 assertHasFindingOfType(ParserFindingType.P032_MISSING_REVISION.toString());
71 assertHasNotFindingOfType(ParserFindingType.P009_FAIL_FAST.toString());
75 public void testNoRevisionWithFineGrainedFilterAndFailFastTrue() {
77 findingsManager.addFilterPredicate(ModuleAndFindingTypeAndSchemaNodePathFilterPredicate.fromString(
78 "revision-test-module;*;*"));
80 parseRelativeImplementsYangModels(Arrays.asList("revision-test/revision-test-module-no-revision.yang"));
82 final YModule yModule = getModule("revision-test-module");
83 assertTrue(yModule != null);
85 assertTrue(yModule.getRevisions().size() == 0);
88 * These should both be filtered. There should not be a fail-fast either
90 assertHasNotFindingOfType(ParserFindingType.P032_MISSING_REVISION.toString());
91 assertHasNotFindingOfType(ParserFindingType.P018_ILLEGAL_CHILD_STATEMENT.toString());
92 assertHasNotFindingOfType(ParserFindingType.P009_FAIL_FAST.toString());
96 public void testDuplicateRevisionNonLatest() {
97 parseRelativeImplementsYangModels(Arrays.asList(
98 "revision-test/revision-test-module-duplicate-revision-non-latest.yang"));
100 final YModule yModule = getModule("revision-test-module");
101 assertTrue(yModule != null);
103 assertHasFindingOfType(ParserFindingType.P049_DUPLICATE_REVISION.toString());
107 public void testDuplicateRevisionLatest() {
108 parseRelativeImplementsYangModels(Arrays.asList(
109 "revision-test/revision-test-module-duplicate-revision-latest.yang"));
111 final YModule yModule = getModule("revision-test-module");
112 assertTrue(yModule != null);
114 assertHasFindingOfType(ParserFindingType.P050_DUPLICATE_LATEST_REVISION.toString());
118 public void testInvalidRevision() {
119 parseRelativeImplementsYangModels(Arrays.asList("revision-test/revision-test-module-invalid-revision.yang"));
121 final YModule yModule = getModule("revision-test-module");
122 assertTrue(yModule != null);
124 assertHasFindingOfType(ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
126 final List<YRevision> revisions = yModule.getRevisions();
128 assertTrue(revisions.size() == 8);
130 assertNoFindingsOnStatement(revisions.get(0));
131 assertStatementHasFindingOfType(revisions.get(1), ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
132 assertStatementHasFindingOfType(revisions.get(2), ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
133 assertStatementHasFindingOfType(revisions.get(3), ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
134 assertStatementHasFindingOfType(revisions.get(4), ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
135 assertStatementHasFindingOfType(revisions.get(5), ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
136 assertStatementHasFindingOfType(revisions.get(6), ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
137 assertStatementHasFindingOfType(revisions.get(7), ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());