blob: 4c825a02e69c970377d470e809b84cf421dbcd63 [file] [log] [blame]
sonu guptaeff184b2016-11-24 12:43:49 +05301/*
2 * Copyright (c) 2016. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
3 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
4 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
5 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
6 * Vestibulum commodo. Ut rhoncus gravida arcu.
7 */
8
9package org.onosproject.yms.app.ydt;
10
11import org.junit.Test;
12import org.onosproject.yms.app.yob.DefaultYobBuilder;
13import org.onosproject.yms.app.ytb.DefaultYangTreeBuilder;
14import org.onosproject.yms.ydt.YdtContext;
15
16import java.util.HashSet;
17import java.util.LinkedList;
18import java.util.List;
19import java.util.Set;
20
21import static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.OTHER_EDIT;
22import static org.onosproject.yms.app.ydt.YdtTestUtils.identityRefYdt;
23import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppLogicalNodeContents;
24import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppModuleNodeContents;
25import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents;
26import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafListContents;
27import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents;
28import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree;
29import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
30import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REPLY;
31
32public class IdentityTest {
33
34 Set<String> valueSet = new HashSet();
35
36 private static final String[] EXPECTED = {
37 "Entry Node is identityref.",
38 "Entry Node is crypto-base.",
39 "Entry Node is crypto.",
40 "Exit Node is crypto.",
41 "Entry Node is abc-zeunion.",
42 "Exit Node is abc-zeunion.",
43 "Entry Node is level2.",
44 "Exit Node is level2.",
45 "Entry Node is level3.",
46 "Exit Node is level3.",
47 "Entry Node is level4.",
48 "Exit Node is level4.",
49 "Entry Node is abc-type.",
50 "Exit Node is abc-type.",
51 "Exit Node is crypto-base.",
52 "Exit Node is identityref.",
53 };
54
55 /**
56 * Creates and validates identity ref in ydt.
57 */
58 @Test
59 public void identityRefTest() {
60 YangRequestWorkBench ydtBuilder = identityRefYdt();
61 validateTree(ydtBuilder);
62 validateAppTree(ydtBuilder);
63 walkINTree(ydtBuilder, EXPECTED);
64
65 //TODO need to be handled later
66// validateYangObject(ydtBuilder);
67 }
68
69 /**
70 * Validates the given built ydt.
71 */
72 private void validateTree(YangRequestWorkBench ydtBuilder) {
73
74 valueSet.add("crypto-alg");
75 // Assign root node to ydtNode for validating purpose.
76 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
77 // Logical root node does not have operation type
78 validateNodeContents(ydtNode, "identityref", null);
79 ydtNode = ydtNode.getFirstChild();
80 validateNodeContents(ydtNode, "crypto-base", MERGE);
81 ydtNode = ydtNode.getFirstChild();
82
83 validateLeafContents(ydtNode, "crypto", "crypto-alg");
84 ydtNode = ydtNode.getNextSibling();
85 validateLeafContents(ydtNode, "abc-zeunion", "crypto-alg");
86 ydtNode = ydtNode.getNextSibling();
87 validateLeafContents(ydtNode, "level2", "crypto-alg2");
88 ydtNode = ydtNode.getNextSibling();
89 validateLeafContents(ydtNode, "level3", "crypto-alg3");
90 ydtNode = ydtNode.getNextSibling();
91 validateLeafContents(ydtNode, "level4", "crypto-alg3");
92 ydtNode = ydtNode.getNextSibling();
93 validateLeafListContents(ydtNode, "abc-type", valueSet);
94
95 }
96
97 /**
98 * Validates the given built ydt application tree.
99 */
100 private void validateAppTree(YangRequestWorkBench ydtBuilder) {
101
102 // Assign root node to ydtNode for validating purpose.
103 YdtAppContext ydtAppContext = ydtBuilder.getAppRootNode();
104 // Logical root node does not have operation type
105 validateAppLogicalNodeContents(ydtAppContext);
106 ydtAppContext = ydtAppContext.getFirstChild();
107 validateAppModuleNodeContents(ydtAppContext, "crypto-base",
108 OTHER_EDIT);
109 }
110
111 /**
112 * Creates Ydt from YO using YTB.
113 */
114 private void validateYangObject(YangRequestWorkBench ydtBuilder) {
115
116 YdtContext rootCtx = ydtBuilder.getRootNode();
117
118 YdtContext childCtx = rootCtx.getFirstChild();
119
120 DefaultYobBuilder builder = new DefaultYobBuilder();
121
122 Object yangObject = builder.getYangObject(
123 (YdtExtendedContext) childCtx, YdtTestUtils
124 .getSchemaRegistry());
125
126 List<Object> list = new LinkedList<>();
127 list.add(yangObject);
128 // Builds YANG tree in YTB.
129 DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder();
130 YangRequestWorkBench defaultYdtBuilder =
131 (YangRequestWorkBench) treeBuilder.getYdtBuilderForYo(
132 list, "identityref", "ydt.crypto-base",
133 EDIT_CONFIG_REPLY, YdtTestUtils
134 .getSchemaRegistry());
135
136 // Validate the created YDT
137 walkINTree(defaultYdtBuilder, EXPECTED);
138 validateTree(defaultYdtBuilder);
139 }
140}