blob: 68200f1a44459c5f489ac74a8b9832264c1a796e [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 */
16
17package org.onosproject.yms.app.ydt;
18
19import org.junit.Test;
20import org.onosproject.yms.app.yob.DefaultYobBuilder;
21import org.onosproject.yms.app.ytb.DefaultYangTreeBuilder;
22import org.onosproject.yms.ydt.YdtContext;
23
24import java.util.HashSet;
25import java.util.LinkedList;
26import java.util.List;
27import java.util.Set;
28
29import static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.OTHER_EDIT;
30import static org.onosproject.yms.app.ydt.YdtTestUtils.identityRefYdt;
31import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppLogicalNodeContents;
32import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppModuleNodeContents;
33import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents;
34import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafListContents;
35import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents;
36import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree;
37import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
38import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REPLY;
39
40public class IdentityTest {
41
42 Set<String> valueSet = new HashSet();
43
44 private static final String[] EXPECTED = {
45 "Entry Node is identityref.",
46 "Entry Node is crypto-base.",
47 "Entry Node is crypto.",
48 "Exit Node is crypto.",
49 "Entry Node is abc-zeunion.",
50 "Exit Node is abc-zeunion.",
51 "Entry Node is level2.",
52 "Exit Node is level2.",
53 "Entry Node is level3.",
54 "Exit Node is level3.",
55 "Entry Node is level4.",
56 "Exit Node is level4.",
57 "Entry Node is abc-type.",
58 "Exit Node is abc-type.",
59 "Exit Node is crypto-base.",
60 "Exit Node is identityref.",
61 };
62
63 /**
64 * Creates and validates identity ref in ydt.
65 */
66 @Test
67 public void identityRefTest() {
68 YangRequestWorkBench ydtBuilder = identityRefYdt();
69 validateTree(ydtBuilder);
70 validateAppTree(ydtBuilder);
71 walkINTree(ydtBuilder, EXPECTED);
72
73 //TODO need to be handled later
74// validateYangObject(ydtBuilder);
75 }
76
77 /**
78 * Validates the given built ydt.
79 */
80 private void validateTree(YangRequestWorkBench ydtBuilder) {
81
82 valueSet.add("crypto-alg");
83 // Assign root node to ydtNode for validating purpose.
84 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
85 // Logical root node does not have operation type
86 validateNodeContents(ydtNode, "identityref", null);
87 ydtNode = ydtNode.getFirstChild();
88 validateNodeContents(ydtNode, "crypto-base", MERGE);
89 ydtNode = ydtNode.getFirstChild();
90
91 validateLeafContents(ydtNode, "crypto", "crypto-alg");
92 ydtNode = ydtNode.getNextSibling();
93 validateLeafContents(ydtNode, "abc-zeunion", "crypto-alg");
94 ydtNode = ydtNode.getNextSibling();
95 validateLeafContents(ydtNode, "level2", "crypto-alg2");
96 ydtNode = ydtNode.getNextSibling();
97 validateLeafContents(ydtNode, "level3", "crypto-alg3");
98 ydtNode = ydtNode.getNextSibling();
99 validateLeafContents(ydtNode, "level4", "crypto-alg3");
100 ydtNode = ydtNode.getNextSibling();
101 validateLeafListContents(ydtNode, "abc-type", valueSet);
102
103 }
104
105 /**
106 * Validates the given built ydt application tree.
107 */
108 private void validateAppTree(YangRequestWorkBench ydtBuilder) {
109
110 // Assign root node to ydtNode for validating purpose.
111 YdtAppContext ydtAppContext = ydtBuilder.getAppRootNode();
112 // Logical root node does not have operation type
113 validateAppLogicalNodeContents(ydtAppContext);
114 ydtAppContext = ydtAppContext.getFirstChild();
115 validateAppModuleNodeContents(ydtAppContext, "crypto-base",
116 OTHER_EDIT);
117 }
118
119 /**
120 * Creates Ydt from YO using YTB.
121 */
122 private void validateYangObject(YangRequestWorkBench ydtBuilder) {
123
124 YdtContext rootCtx = ydtBuilder.getRootNode();
125
126 YdtContext childCtx = rootCtx.getFirstChild();
127
128 DefaultYobBuilder builder = new DefaultYobBuilder();
129
130 Object yangObject = builder.getYangObject(
131 (YdtExtendedContext) childCtx, YdtTestUtils
132 .getSchemaRegistry());
133
134 List<Object> list = new LinkedList<>();
135 list.add(yangObject);
136 // Builds YANG tree in YTB.
137 DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder();
138 YangRequestWorkBench defaultYdtBuilder =
139 (YangRequestWorkBench) treeBuilder.getYdtBuilderForYo(
140 list, "identityref", "ydt.crypto-base",
141 EDIT_CONFIG_REPLY, YdtTestUtils
142 .getSchemaRegistry());
143
144 // Validate the created YDT
145 walkINTree(defaultYdtBuilder, EXPECTED);
146 validateTree(defaultYdtBuilder);
147 }
148}