4c0e5879f9516bc841a727b0b3c7825ee8a40be9
[smo/teiv.git] /
1 /*
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21 package org.oran.smo.yangtools.parser.model.statements.ietf.test;
22
23 import static org.junit.Assert.assertNull;
24 import static org.junit.Assert.assertTrue;
25
26 import java.util.Arrays;
27
28 import org.junit.Test;
29
30 import org.oran.smo.yangtools.parser.model.statements.ietf.CIETF;
31 import org.oran.smo.yangtools.parser.model.statements.ietf.YIetfAnnotation;
32 import org.oran.smo.yangtools.parser.model.statements.ietf.YIetfDefaultDenyAll;
33 import org.oran.smo.yangtools.parser.model.statements.ietf.YIetfDefaultDenyWrite;
34 import org.oran.smo.yangtools.parser.model.statements.threegpp.C3GPP;
35 import org.oran.smo.yangtools.parser.model.statements.threegpp.Y3gppInVariant;
36 import org.oran.smo.yangtools.parser.model.statements.threegpp.Y3gppInitialValue;
37 import org.oran.smo.yangtools.parser.model.statements.threegpp.Y3gppNotNotifyable;
38 import org.oran.smo.yangtools.parser.model.statements.yang.YContainer;
39 import org.oran.smo.yangtools.parser.model.statements.yang.YLeaf;
40 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
41 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
42
43 public class OtherExtensionsTest extends YangTestCommon {
44
45     private static final String IETF_YANG_METADATA = "ietf-yang-metadata";
46     private static final String THREE_GPP_COMMON_YANG_EXTENSIONS = "_3gpp-common-yang-extensions";
47     private static final String IETF_NETCONF_ACM = "ietf-netconf-acm";
48
49     @Test
50     public void test_3gpp_extensions() {
51
52         parseAbsoluteImplementsYangModels(Arrays.asList(
53                 "src/test/resources/model-statements-other/other-extension-test.yang", THREEGPP_YANG_EXT_PATH,
54                 YANG_METADATA_PATH, NETCONF_ACM_PATH, "src/test/resources/_orig-modules/ietf-inet-types-2019-11-04.yang",
55                 "src/test/resources/_orig-modules/ietf-yang-types-2019-11-04.yang"));
56
57         assertNoFindings();
58
59         final YModule module = getModule("other-extension-test");
60         assertTrue(module != null);
61
62         final YIetfAnnotation annotation = getExtensionChild(module, IETF_YANG_METADATA, "annotation");
63         assertTrue(annotation != null);
64         assertTrue(annotation.getAnnotationName().equals("last-modified"));
65         assertTrue(getChild(annotation, "type") != null);
66         assertTrue(annotation.getStatementModuleAndName().equals(CIETF.IETF_YANG_METADATA__ANNOTATION));
67
68         final YContainer cont1 = getContainer(module, "cont1");
69
70         final YIetfDefaultDenyWrite defaultDenyWrite = getExtensionChild(cont1, IETF_NETCONF_ACM, "default-deny-write");
71         assertTrue(defaultDenyWrite != null);
72         assertTrue(defaultDenyWrite.getStatementModuleAndName().equals(CIETF.IETF_NETCONF_ACM__DEFAULT_DENY_WRITE));
73
74         final YLeaf leaf1 = getLeaf(cont1, "leaf1");
75
76         final Y3gppInVariant inVariant = getExtensionChild(leaf1, THREE_GPP_COMMON_YANG_EXTENSIONS, C3GPP.IN_VARIANT);
77         assertTrue(inVariant != null);
78         assertTrue(inVariant.getStatementModuleAndName().equals(C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__IN_VARIANT));
79
80         final Y3gppInitialValue threegppInitialValue = getExtensionChild(leaf1, THREE_GPP_COMMON_YANG_EXTENSIONS,
81                 C3GPP.INITIAL_VALUE);
82         assertTrue(threegppInitialValue != null);
83         assertTrue(threegppInitialValue.getInitialValue().equals("Hello"));
84         assertTrue(threegppInitialValue.getStatementModuleAndName().equals(
85                 C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__INITIAL_VALUE));
86
87         final Y3gppNotNotifyable threegppNotNotifyable = getExtensionChild(leaf1, THREE_GPP_COMMON_YANG_EXTENSIONS,
88                 C3GPP.NOT_NOTIFYABLE);
89         assertTrue(threegppNotNotifyable != null);
90         assertNull(threegppNotNotifyable.getValue());
91         assertTrue(threegppNotNotifyable.getStatementModuleAndName().equals(
92                 C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__NOT_NOTIFYABLE));
93
94         final YIetfDefaultDenyAll defaultDenyAll = getExtensionChild(leaf1, IETF_NETCONF_ACM, "default-deny-all");
95         assertTrue(defaultDenyAll != null);
96         assertTrue(defaultDenyAll.getStatementModuleAndName().equals(CIETF.IETF_NETCONF_ACM__DEFAULT_DENY_ALL));
97     }
98
99     @Test
100     public void test_CI_C3() {
101         assertTrue(CIETF.HANDLED_STATEMENTS.size() == 3);
102         assertTrue(CIETF.HANDLED_STATEMENTS.containsKey("ietf-yang-schema-mount"));
103         assertTrue(CIETF.HANDLED_STATEMENTS.containsKey("ietf-yang-metadata"));
104         assertTrue(CIETF.HANDLED_STATEMENTS.containsKey("ietf-netconf-acm"));
105
106         assertTrue(C3GPP.HANDLED_STATEMENTS.size() == 1);
107         assertTrue(C3GPP.HANDLED_STATEMENTS.containsKey("_3gpp-common-yang-extensions"));
108     }
109 }