88759083677e20049e95755a77d772407f3c93c8
[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.data.test;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30 import org.junit.Test;
31
32 import org.oran.smo.yangtools.parser.data.instance.ContainerInstance;
33 import org.oran.smo.yangtools.parser.data.instance.LeafInstance;
34 import org.oran.smo.yangtools.parser.data.instance.LeafListInstance;
35 import org.oran.smo.yangtools.parser.data.instance.ListInstance;
36 import org.oran.smo.yangtools.parser.data.instance.RootInstance;
37 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
38 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
39
40 public class InstanceDataTreeBuilderTest extends YangTestCommon {
41
42     @Test
43     public void test_single_data_file() {
44
45         parseAbsoluteImplementsYangModels(Arrays.asList(
46                 "src/test/resources/data/instance-data-tree-builder-test/module1.yang"));
47         parseAbsoluteYangData(Arrays.asList(
48                 "src/test/resources/data/instance-data-tree-builder-test/data-in-single-file.xml"));
49
50         assertNoFindings();
51
52         checkDataParsedCorrectly();
53     }
54
55     private void checkDataParsedCorrectly() {
56         final YModule module = getModule("module1");
57         assertTrue(module != null);
58
59         final RootInstance rootInstance = yangDeviceModel.getCombinedInstanceDataRoot();
60         assertTrue(rootInstance != null);
61
62         final ContainerInstance cont1Instance = getContainerInstance(rootInstance, "test:module", "cont1");
63         assertTrue(cont1Instance != null);
64
65         final Map<String, String> map1 = new HashMap<>();
66         map1.put("leaf111", "key-value-1");
67
68         final ListInstance list11InstanceKeyValue1 = getListInstanceData(cont1Instance, "test:module", "list11", map1);
69         assertTrue(list11InstanceKeyValue1 != null);
70
71         final LeafInstance leaf111Instance = getLeafInstance(list11InstanceKeyValue1, "test:module", "leaf111");
72         assertTrue(leaf111Instance != null);
73         assertTrue(leaf111Instance.getValue().equals("key-value-1"));
74
75         final LeafInstance leaf112Instance = getLeafInstance(list11InstanceKeyValue1, "test:module", "leaf112");
76         assertTrue(leaf112Instance != null);
77         assertTrue(leaf112Instance.getValue().equals("some string"));
78
79         final List<LeafListInstance> leaf113Instance = getLeafListInstances(list11InstanceKeyValue1, "test:module",
80                 "leaflist113");
81         assertTrue(leaf113Instance != null);
82         assertTrue(leaf113Instance.size() == 3);
83         assertTrue(leaf113Instance.get(0).getValue().equals("20"));
84         assertTrue(leaf113Instance.get(1).getValue().equals("30"));
85         assertTrue(leaf113Instance.get(2).getValue().equals("40"));
86
87         LeafInstance leaf12Instance = getLeafInstance(cont1Instance, "test:module", "leaf12");
88         assertTrue(leaf12Instance != null);
89         assertTrue(leaf12Instance.getValue().equals("42"));
90     }
91 }