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.data.test;
23 import static org.junit.Assert.assertTrue;
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.List;
30 import org.junit.Test;
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;
40 public class InstanceDataTreeBuilderTest extends YangTestCommon {
43 public void test_single_data_file() {
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"));
52 checkDataParsedCorrectly();
55 private void checkDataParsedCorrectly() {
56 final YModule module = getModule("module1");
57 assertTrue(module != null);
59 final RootInstance rootInstance = yangDeviceModel.getCombinedInstanceDataRoot();
60 assertTrue(rootInstance != null);
62 final ContainerInstance cont1Instance = getContainerInstance(rootInstance, "test:module", "cont1");
63 assertTrue(cont1Instance != null);
65 final Map<String, String> map1 = new HashMap<>();
66 map1.put("leaf111", "key-value-1");
68 final ListInstance list11InstanceKeyValue1 = getListInstanceData(cont1Instance, "test:module", "list11", map1);
69 assertTrue(list11InstanceKeyValue1 != null);
71 final LeafInstance leaf111Instance = getLeafInstance(list11InstanceKeyValue1, "test:module", "leaf111");
72 assertTrue(leaf111Instance != null);
73 assertTrue(leaf111Instance.getValue().equals("key-value-1"));
75 final LeafInstance leaf112Instance = getLeafInstance(list11InstanceKeyValue1, "test:module", "leaf112");
76 assertTrue(leaf112Instance != null);
77 assertTrue(leaf112Instance.getValue().equals("some string"));
79 final List<LeafListInstance> leaf113Instance = getLeafListInstances(list11InstanceKeyValue1, "test:module",
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"));
87 LeafInstance leaf12Instance = getLeafInstance(cont1Instance, "test:module", "leaf12");
88 assertTrue(leaf12Instance != null);
89 assertTrue(leaf12Instance.getValue().equals("42"));