blob: 720b8274a67baf550a3d2d093ee32035cfaedf36 [file] [log] [blame]
sonu guptaeff184b2016-11-24 12:43:49 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey2d572dd2017-04-14 10:01:24 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
sonu guptaeff184b2016-11-24 12:43:49 +053015 */
sonu guptaeff184b2016-11-24 12:43:49 +053016package org.onosproject.yms.app.ydt;
17
18import org.junit.Test;
19
20import static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.OTHER_EDIT;
21import static org.onosproject.yms.app.ydt.YdtTestConstants.AUGNS;
22import static org.onosproject.yms.app.ydt.YdtTestConstants.AUGSE;
23import static org.onosproject.yms.app.ydt.YdtTestUtils.augmentSequenceYdt;
24import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppLogicalNodeContents;
25import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppModuleNodeContents;
26import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppNodeContents;
27import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents;
28import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents;
29import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree;
30import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
31
32public class AugmentSequenceTest {
33
34 private static final String[] EXPECTED = {
35 "Entry Node is augment.",
36 "Entry Node is augmentSequence.",
37 "Entry Node is l1.",
38 "Entry Node is leaf1.",
39 "Exit Node is leaf1.",
40
41 "Entry Node is c1.",
42 "Entry Node is leaf2.",
43 "Exit Node is leaf2.",
44 "Exit Node is c1.",
45
46 "Entry Node is c2.",
47 "Entry Node is leaf2.",
48 "Exit Node is leaf2.",
49 "Exit Node is c2.",
50
51 "Exit Node is l1.",
52 "Exit Node is augmentSequence.",
53 "Exit Node is augment.",
54 };
55
56 /**
57 * Creates and validates sequence of augment in ydt.
58 */
59 @Test
60 public void augmentTest() {
61 YangRequestWorkBench ydtBuilder = augmentSequenceYdt();
62 validateTree(ydtBuilder);
63 validateAppTree(ydtBuilder);
64 walkINTree(ydtBuilder, EXPECTED);
65 }
66
67 /**
68 * Validates the given built ydt.
69 */
70 private void validateTree(YangRequestWorkBench ydtBuilder) {
71
72 // Assign root node to ydtNode for validating purpose.
73 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
74 // Logical root node does not have operation type
75 validateNodeContents(ydtNode, "augment", null);
76 ydtNode = ydtNode.getFirstChild();
77 validateNodeContents(ydtNode, "augmentSequence", MERGE);
78 ydtNode = ydtNode.getFirstChild();
79 validateNodeContents(ydtNode, "l1", MERGE);
80 ydtNode = ydtNode.getFirstChild();
81
82 validateLeafContents(ydtNode, "leaf1", "1");
83 ydtNode = ydtNode.getNextSibling();
84
85 //Augmenting leaf2
86 validateNodeContents(ydtNode, "c1", MERGE);
87 ydtNode = ydtNode.getFirstChild();
88 validateLeafContents(ydtNode, "leaf2", "2");
89 ydtNode = ydtNode.getParent();
90 ydtNode = ydtNode.getNextSibling();
91
92 //Augmenting leaf3
93 validateNodeContents(ydtNode, "c2", MERGE);
94 ydtNode = ydtNode.getFirstChild();
95 validateLeafContents(ydtNode, "leaf2", "3");
96 }
97
98 /**
99 * Validates the given built ydt application tree.
100 */
101 private void validateAppTree(YangRequestWorkBench ydtBuilder) {
102
103 // Assign root node to ydtNode for validating purpose.
104 YdtAppContext ydtAppContext = ydtBuilder.getAppRootNode();
105 // Logical root node does not have operation type
106 validateAppLogicalNodeContents(ydtAppContext);
107 ydtAppContext = ydtAppContext.getFirstChild();
108 validateAppModuleNodeContents(ydtAppContext, "augmentSequence",
109 OTHER_EDIT);
110 ydtAppContext = ydtAppContext.getFirstChild();
111
112 //Inside list checking the first augmented leaf
113 validateAppNodeContents(ydtAppContext, AUGSE, AUGNS, OTHER_EDIT);
114 }
115}