blob: 1d15d047092cfe0b2ec87640fb667d301291981a [file] [log] [blame]
sonu gupta1bb37b82016-11-11 16:51:18 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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.
15 */
16
17package org.onosproject.yms.app.ydt;
18
19import org.junit.Test;
20import org.onosproject.yms.app.ydt.exceptions.YdtException;
21
22import static org.onosproject.yms.app.ydt.YdtTestConstants.A;
23import static org.onosproject.yms.app.ydt.YdtTestConstants.B;
24import static org.onosproject.yms.app.ydt.YdtTestConstants.C;
25import static org.onosproject.yms.app.ydt.YdtTestConstants.E;
26import static org.onosproject.yms.app.ydt.YdtTestConstants.F;
27import static org.onosproject.yms.app.ydt.YdtTestConstants.G;
28import static org.onosproject.yms.app.ydt.YdtTestConstants.H;
29import static org.onosproject.yms.app.ydt.YdtTestConstants.MAXIWR;
30import static org.onosproject.yms.app.ydt.YdtTestConstants.MIDIWR;
31import static org.onosproject.yms.app.ydt.YdtTestConstants.MINIWR;
32import static org.onosproject.yms.app.ydt.YdtTestConstants.MRV;
33import static org.onosproject.yms.app.ydt.YdtTestConstants.NIWMF;
34import static org.onosproject.yms.app.ydt.YdtTestConstants.NWF;
35import static org.onosproject.yms.app.ydt.YdtTestConstants.PIWMF;
36import static org.onosproject.yms.app.ydt.YdtTestConstants.PWF;
37import static org.onosproject.yms.app.ydt.YdtTestConstants.TYPE;
38import static org.onosproject.yms.app.ydt.YdtTestUtils.decimal64Ydt;
39import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents;
40import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents;
41import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
42
43public class YdtDecimal64Test {
44
45 /*
46
47 Positive scenario
48
49 input at boundry for decimal64 with fraction 2
50 i. min value
51 ii. max value
52
53 input at boundry for decimal64 with minimum fraction
54 i. min value
55 ii. mid value
56 iii. max value
57
58 input at boundry for decimal64 with maximum fraction
59 i. min value
60 ii. mid value
61 iii. max value
62
63 input with in range
64 if range is 10 to 100 for integer
65 i.1. input 11
66 i.2. min value 10
67 i.3. max value 100
68
69 input with multi interval range
70 if range is 10..40 | 50..100 for decimal64
71 i.1. input 11
72 i.2. input 10
73 i.3. input 40
74 i.4. input 50
75 i.5. input 55
76 i.6. input 100
77
78 if range is "min .. 3.14 | 10 | 20..max" for decimal64
79 i.1. input min
80 i.2. input 2.505
81 i.3. input 3.14
82 i.4. input 10
83 i.5. input 20
84 i.6. input 92233720368547757
85 i.7. input 92233720368547758.07
86
87 */
88
89 /**
90 * Creates and validates decimal64 ydt covering different positive scenario.
91 */
92 @Test
93 public void positiveTest() throws YdtException {
94 YangRequestWorkBench ydtBuilder = decimal64Ydt();
95 validateTree(ydtBuilder);
96 }
97
98 /**
99 * Validates the given built ydt.
100 */
101 private void validateTree(YangRequestWorkBench ydtBuilder) {
102
103 // assign root node to ydtNode for validating purpose.
104 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
105 // Logical root node does not have operation type
106 validateNodeContents(ydtNode, TYPE, null);
107
108 ydtNode = ydtNode.getFirstChild();
109 validateNodeContents(ydtNode, "decimal64", MERGE);
110 ydtNode = ydtNode.getFirstChild();
111 validateLeafContents(ydtNode, "negInt", C);
112 ydtNode = ydtNode.getNextSibling();
113 validateLeafContents(ydtNode, "posInt", A);
114 ydtNode = ydtNode.getNextSibling();
115 validateLeafContents(ydtNode, NIWMF, F);
116 ydtNode = ydtNode.getNextSibling();
117 validateLeafContents(ydtNode, PIWMF, G);
118 ydtNode = ydtNode.getNextSibling();
119 validateLeafContents(ydtNode, NWF, H);
120 ydtNode = ydtNode.getNextSibling();
121 validateLeafContents(ydtNode, PWF, E);
122 ydtNode = ydtNode.getNextSibling();
123 validateLeafContents(ydtNode, MIDIWR, "11");
124 ydtNode = ydtNode.getNextSibling();
125 validateLeafContents(ydtNode, MINIWR, "10");
126 ydtNode = ydtNode.getNextSibling();
127 validateLeafContents(ydtNode, MAXIWR, "100");
128 ydtNode = ydtNode.getNextSibling();
129 validateNodeContents(ydtNode, MRV, MERGE);
130 ydtNode = ydtNode.getFirstChild();
131 validateLeafContents(ydtNode, "decimal", "11");
132 ydtNode = ydtNode.getParent();
133 ydtNode = ydtNode.getNextSibling();
134 validateNodeContents(ydtNode, MRV, MERGE);
135 ydtNode = ydtNode.getFirstChild();
136 validateLeafContents(ydtNode, "decimal", "10");
137 ydtNode = ydtNode.getParent();
138 ydtNode = ydtNode.getNextSibling();
139 validateNodeContents(ydtNode, MRV, MERGE);
140 ydtNode = ydtNode.getFirstChild();
141 validateLeafContents(ydtNode, "decimal", "40");
142 ydtNode = ydtNode.getParent();
143 ydtNode = ydtNode.getNextSibling();
144 validateNodeContents(ydtNode, MRV, MERGE);
145 ydtNode = ydtNode.getFirstChild();
146 validateLeafContents(ydtNode, "decimal", "50");
147 ydtNode = ydtNode.getParent();
148 ydtNode = ydtNode.getNextSibling();
149 validateNodeContents(ydtNode, MRV, MERGE);
150 ydtNode = ydtNode.getFirstChild();
151 validateLeafContents(ydtNode, "decimal", "55");
152 ydtNode = ydtNode.getParent();
153 ydtNode = ydtNode.getNextSibling();
154 validateNodeContents(ydtNode, MRV, MERGE);
155 ydtNode = ydtNode.getFirstChild();
156 validateLeafContents(ydtNode, "decimal", "100");
157 ydtNode = ydtNode.getParent();
158 ydtNode = ydtNode.getNextSibling();
159 validateNodeContents(ydtNode, MRV, MERGE);
160 ydtNode = ydtNode.getFirstChild();
161 validateLeafContents(ydtNode, "revDecimal", C);
162 ydtNode = ydtNode.getParent();
163 ydtNode = ydtNode.getNextSibling();
164 validateNodeContents(ydtNode, MRV, MERGE);
165 ydtNode = ydtNode.getFirstChild();
166 validateLeafContents(ydtNode, "revDecimal", "2.505");
167 ydtNode = ydtNode.getParent();
168 ydtNode = ydtNode.getNextSibling();
169 validateNodeContents(ydtNode, MRV, MERGE);
170 ydtNode = ydtNode.getFirstChild();
171 validateLeafContents(ydtNode, "revDecimal", "3.14");
172 ydtNode = ydtNode.getParent();
173 ydtNode = ydtNode.getNextSibling();
174 validateNodeContents(ydtNode, MRV, MERGE);
175 ydtNode = ydtNode.getFirstChild();
176 validateLeafContents(ydtNode, "revDecimal", "10");
177 ydtNode = ydtNode.getParent();
178 ydtNode = ydtNode.getNextSibling();
179 validateNodeContents(ydtNode, MRV, MERGE);
180 ydtNode = ydtNode.getFirstChild();
181 validateLeafContents(ydtNode, "revDecimal", "20");
182 ydtNode = ydtNode.getParent();
183 ydtNode = ydtNode.getNextSibling();
184 validateNodeContents(ydtNode, MRV, MERGE);
185 ydtNode = ydtNode.getFirstChild();
186 validateLeafContents(ydtNode, "revDecimal", B);
187 ydtNode = ydtNode.getParent();
188 ydtNode = ydtNode.getNextSibling();
189 validateNodeContents(ydtNode, MRV, MERGE);
190 ydtNode = ydtNode.getFirstChild();
191 validateLeafContents(ydtNode, "revDecimal", A);
192 }
193}